Line data Source code
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 :
11 : #include "webrtc/system_wrappers/include/file_wrapper.h"
12 : #include "webrtc/system_wrappers/include/trace.h"
13 : #include "webrtc/voice_engine/include/voe_errors.h"
14 : #include "webrtc/voice_engine/voe_rtp_rtcp_impl.h"
15 : #include "webrtc/voice_engine/voice_engine_impl.h"
16 :
17 : #include "webrtc/voice_engine/channel.h"
18 : #include "webrtc/voice_engine/transmit_mixer.h"
19 :
20 : namespace webrtc {
21 :
22 0 : VoERTP_RTCP* VoERTP_RTCP::GetInterface(VoiceEngine* voiceEngine) {
23 0 : if (NULL == voiceEngine) {
24 0 : return NULL;
25 : }
26 0 : VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
27 0 : s->AddRef();
28 0 : return s;
29 : }
30 :
31 0 : VoERTP_RTCPImpl::VoERTP_RTCPImpl(voe::SharedData* shared) : _shared(shared) {
32 : WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
33 : "VoERTP_RTCPImpl::VoERTP_RTCPImpl() - ctor");
34 0 : }
35 :
36 0 : VoERTP_RTCPImpl::~VoERTP_RTCPImpl() {
37 : WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
38 : "VoERTP_RTCPImpl::~VoERTP_RTCPImpl() - dtor");
39 0 : }
40 :
41 0 : int VoERTP_RTCPImpl::SetLocalSSRC(int channel, unsigned int ssrc) {
42 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
43 : "SetLocalSSRC(channel=%d, %lu)", channel, ssrc);
44 0 : if (!_shared->statistics().Initialized()) {
45 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
46 0 : return -1;
47 : }
48 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
49 0 : voe::Channel* channelPtr = ch.channel();
50 0 : if (channelPtr == NULL) {
51 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
52 0 : "SetLocalSSRC() failed to locate channel");
53 0 : return -1;
54 : }
55 0 : return channelPtr->SetLocalSSRC(ssrc);
56 : }
57 :
58 0 : int VoERTP_RTCPImpl::GetLocalSSRC(int channel, unsigned int& ssrc) {
59 0 : if (!_shared->statistics().Initialized()) {
60 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
61 0 : return -1;
62 : }
63 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
64 0 : voe::Channel* channelPtr = ch.channel();
65 0 : if (channelPtr == NULL) {
66 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
67 0 : "GetLocalSSRC() failed to locate channel");
68 0 : return -1;
69 : }
70 0 : return channelPtr->GetLocalSSRC(ssrc);
71 : }
72 :
73 0 : int VoERTP_RTCPImpl::GetRemoteSSRC(int channel, unsigned int& ssrc) {
74 0 : if (!_shared->statistics().Initialized()) {
75 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
76 0 : return -1;
77 : }
78 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
79 0 : voe::Channel* channelPtr = ch.channel();
80 0 : if (channelPtr == NULL) {
81 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
82 0 : "GetRemoteSSRC() failed to locate channel");
83 0 : return -1;
84 : }
85 0 : return channelPtr->GetRemoteSSRC(ssrc);
86 : }
87 :
88 0 : int VoERTP_RTCPImpl::SetSendAudioLevelIndicationStatus(int channel,
89 : bool enable,
90 : unsigned char id) {
91 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
92 : "SetSendAudioLevelIndicationStatus(channel=%d, enable=%d,"
93 : " ID=%u)",
94 : channel, enable, id);
95 0 : if (!_shared->statistics().Initialized()) {
96 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
97 0 : return -1;
98 : }
99 0 : if (enable && (id < kVoiceEngineMinRtpExtensionId ||
100 0 : id > kVoiceEngineMaxRtpExtensionId)) {
101 : // [RFC5285] The 4-bit id is the local identifier of this element in
102 : // the range 1-14 inclusive.
103 0 : _shared->SetLastError(
104 : VE_INVALID_ARGUMENT, kTraceError,
105 0 : "SetSendAudioLevelIndicationStatus() invalid ID parameter");
106 0 : return -1;
107 : }
108 :
109 : // Set state and id for the specified channel.
110 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
111 0 : voe::Channel* channelPtr = ch.channel();
112 0 : if (channelPtr == NULL) {
113 0 : _shared->SetLastError(
114 : VE_CHANNEL_NOT_VALID, kTraceError,
115 0 : "SetSendAudioLevelIndicationStatus() failed to locate channel");
116 0 : return -1;
117 : }
118 0 : return channelPtr->SetSendAudioLevelIndicationStatus(enable, id);
119 : }
120 :
121 0 : int VoERTP_RTCPImpl::SetReceiveAudioLevelIndicationStatus(int channel,
122 : bool enable,
123 : unsigned char id) {
124 : WEBRTC_TRACE(
125 : kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
126 : "SetReceiveAudioLevelIndicationStatus(channel=%d, enable=%d, id=%u)",
127 : channel, enable, id);
128 0 : if (!_shared->statistics().Initialized()) {
129 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
130 0 : return -1;
131 : }
132 0 : if (enable && (id < kVoiceEngineMinRtpExtensionId ||
133 0 : id > kVoiceEngineMaxRtpExtensionId)) {
134 : // [RFC5285] The 4-bit id is the local identifier of this element in
135 : // the range 1-14 inclusive.
136 0 : _shared->SetLastError(
137 : VE_INVALID_ARGUMENT, kTraceError,
138 0 : "SetReceiveAudioLevelIndicationStatus() invalid id parameter");
139 0 : return -1;
140 : }
141 : // Set state and id for the specified channel.
142 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
143 0 : voe::Channel* channel_ptr = ch.channel();
144 0 : if (channel_ptr == NULL) {
145 0 : _shared->SetLastError(
146 : VE_CHANNEL_NOT_VALID, kTraceError,
147 0 : "SetReceiveAudioLevelIndicationStatus() failed to locate channel");
148 0 : return -1;
149 : }
150 0 : return channel_ptr->SetReceiveAudioLevelIndicationStatus(enable, id);
151 : }
152 :
153 0 : int VoERTP_RTCPImpl::SetRTCPStatus(int channel, bool enable) {
154 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
155 : "SetRTCPStatus(channel=%d, enable=%d)", channel, enable);
156 0 : if (!_shared->statistics().Initialized()) {
157 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
158 0 : return -1;
159 : }
160 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
161 0 : voe::Channel* channelPtr = ch.channel();
162 0 : if (channelPtr == NULL) {
163 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
164 0 : "SetRTCPStatus() failed to locate channel");
165 0 : return -1;
166 : }
167 0 : channelPtr->SetRTCPStatus(enable);
168 0 : return 0;
169 : }
170 :
171 0 : int VoERTP_RTCPImpl::GetRTCPStatus(int channel, bool& enabled) {
172 0 : if (!_shared->statistics().Initialized()) {
173 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
174 0 : return -1;
175 : }
176 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
177 0 : voe::Channel* channelPtr = ch.channel();
178 0 : if (channelPtr == NULL) {
179 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
180 0 : "GetRTCPStatus() failed to locate channel");
181 0 : return -1;
182 : }
183 0 : return channelPtr->GetRTCPStatus(enabled);
184 : }
185 :
186 0 : int VoERTP_RTCPImpl::SetRTCP_CNAME(int channel, const char cName[256]) {
187 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
188 : "SetRTCP_CNAME(channel=%d, cName=%s)", channel, cName);
189 0 : if (!_shared->statistics().Initialized()) {
190 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
191 0 : return -1;
192 : }
193 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
194 0 : voe::Channel* channelPtr = ch.channel();
195 0 : if (channelPtr == NULL) {
196 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
197 0 : "SetRTCP_CNAME() failed to locate channel");
198 0 : return -1;
199 : }
200 0 : return channelPtr->SetRTCP_CNAME(cName);
201 : }
202 :
203 0 : int VoERTP_RTCPImpl::GetRemoteRTCP_CNAME(int channel, char cName[256]) {
204 0 : if (!_shared->statistics().Initialized()) {
205 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
206 0 : return -1;
207 : }
208 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
209 0 : voe::Channel* channelPtr = ch.channel();
210 0 : if (channelPtr == NULL) {
211 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
212 0 : "GetRemoteRTCP_CNAME() failed to locate channel");
213 0 : return -1;
214 : }
215 0 : return channelPtr->GetRemoteRTCP_CNAME(cName);
216 : }
217 :
218 0 : int VoERTP_RTCPImpl::GetRTPStatistics(int channel,
219 : unsigned int& averageJitterMs,
220 : unsigned int& maxJitterMs,
221 : unsigned int& discardedPackets,
222 : unsigned int& cumulativeLost)
223 : {
224 0 : if (!_shared->statistics().Initialized()) {
225 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
226 0 : return -1;
227 : }
228 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
229 0 : voe::Channel* channelPtr = ch.channel();
230 0 : if (channelPtr == NULL) {
231 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
232 0 : "GetRTPStatistics() failed to locate channel");
233 0 : return -1;
234 : }
235 : return channelPtr->GetRTPStatistics(averageJitterMs,
236 : maxJitterMs,
237 : discardedPackets,
238 0 : cumulativeLost);
239 : }
240 :
241 0 : int VoERTP_RTCPImpl::GetRTCPStatistics(int channel, CallStatistics& stats) {
242 0 : if (!_shared->statistics().Initialized()) {
243 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
244 0 : return -1;
245 : }
246 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
247 0 : voe::Channel* channelPtr = ch.channel();
248 0 : if (channelPtr == NULL) {
249 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
250 0 : "GetRTPStatistics() failed to locate channel");
251 0 : return -1;
252 : }
253 0 : return channelPtr->GetRTPStatistics(stats);
254 : }
255 :
256 0 : int VoERTP_RTCPImpl::GetRTCPPacketTypeCounters(int channel,
257 : RtcpPacketTypeCounter& stats) {
258 0 : if (!_shared->statistics().Initialized()) {
259 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
260 0 : return -1;
261 : }
262 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
263 0 : voe::Channel* channelPtr = ch.channel();
264 0 : if (channelPtr == NULL) {
265 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
266 0 : "GetRTCPPacketTypeCounters() failed to locate channel");
267 0 : return -1;
268 : }
269 0 : return channelPtr->GetRTCPPacketTypeCounters(stats);
270 : }
271 :
272 0 : int VoERTP_RTCPImpl::GetRemoteRTCPReportBlocks(
273 : int channel, std::vector<ReportBlock>* report_blocks) {
274 0 : if (!_shared->statistics().Initialized()) {
275 0 : _shared->SetLastError(VE_NOT_INITED, kTraceError);
276 0 : return -1;
277 : }
278 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
279 0 : voe::Channel* channel_ptr = ch.channel();
280 0 : if (channel_ptr == NULL) {
281 0 : _shared->SetLastError(
282 : VE_CHANNEL_NOT_VALID, kTraceError,
283 0 : "GetRemoteRTCPReportBlocks() failed to locate channel");
284 0 : return -1;
285 : }
286 0 : return channel_ptr->GetRemoteRTCPReportBlocks(report_blocks);
287 : }
288 :
289 0 : int VoERTP_RTCPImpl::SetNACKStatus(int channel, bool enable, int maxNoPackets) {
290 : WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
291 : "SetNACKStatus(channel=%d, enable=%d, maxNoPackets=%d)", channel,
292 : enable, maxNoPackets);
293 :
294 0 : voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
295 0 : voe::Channel* channelPtr = ch.channel();
296 0 : if (channelPtr == NULL) {
297 0 : _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
298 0 : "SetNACKStatus() failed to locate channel");
299 0 : return -1;
300 : }
301 0 : channelPtr->SetNACKStatus(enable, maxNoPackets);
302 0 : return 0;
303 : }
304 :
305 : } // namespace webrtc
|