Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / voice_engine / voe_rtp_rtcp_impl.cc
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/interface/critical_section_wrapper.h"
12 #include "webrtc/system_wrappers/interface/file_wrapper.h"
13 #include "webrtc/system_wrappers/interface/trace.h"
14 #include "webrtc/video_engine/include/vie_network.h"
15 #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"
18
19 #include "webrtc/voice_engine/channel.h"
20 #include "webrtc/voice_engine/transmit_mixer.h"
21
22 namespace webrtc {
23
24 VoERTP_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     }
33     VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
34     s->AddRef();
35     return s;
36 #endif
37 }
38
39 #ifdef WEBRTC_VOICE_ENGINE_RTP_RTCP_API
40
41 VoERTP_RTCPImpl::VoERTP_RTCPImpl(voe::SharedData* shared) : _shared(shared)
42 {
43     WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
44                  "VoERTP_RTCPImpl::VoERTP_RTCPImpl() - ctor");
45 }
46
47 VoERTP_RTCPImpl::~VoERTP_RTCPImpl()
48 {
49     WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
50                  "VoERTP_RTCPImpl::~VoERTP_RTCPImpl() - dtor");
51 }
52
53 int VoERTP_RTCPImpl::RegisterRTPObserver(int channel, VoERTPObserver& observer)
54 {
55     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
56                  "RegisterRTPObserver(channel=%d observer=0x%x)",
57                  channel, &observer);
58     if (!_shared->statistics().Initialized())
59     {
60         _shared->SetLastError(VE_NOT_INITED, kTraceError);
61         return -1;
62     }
63     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
64     voe::Channel* channelPtr = ch.channel();
65     if (channelPtr == NULL)
66     {
67         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
68             "RegisterRTPObserver() failed to locate channel");
69         return -1;
70     }
71     return channelPtr->RegisterRTPObserver(observer);
72 }
73
74 int VoERTP_RTCPImpl::DeRegisterRTPObserver(int channel)
75 {
76     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
77                  "DeRegisterRTPObserver(channel=%d)", channel);
78     if (!_shared->statistics().Initialized())
79     {
80         _shared->SetLastError(VE_NOT_INITED, kTraceError);
81         return -1;
82     }
83     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
84     voe::Channel* channelPtr = ch.channel();
85     if (channelPtr == NULL)
86     {
87         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
88             "DeRegisterRTPObserver() failed to locate channel");
89         return -1;
90     }
91     return channelPtr->DeRegisterRTPObserver();
92 }
93
94 int VoERTP_RTCPImpl::RegisterRTCPObserver(int channel, VoERTCPObserver& observer)
95 {
96     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
97                  "RegisterRTCPObserver(channel=%d observer=0x%x)",
98                  channel, &observer);
99     if (!_shared->statistics().Initialized())
100     {
101         _shared->SetLastError(VE_NOT_INITED, kTraceError);
102         return -1;
103     }
104     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
105     voe::Channel* channelPtr = ch.channel();
106     if (channelPtr == NULL)
107     {
108         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
109             "RegisterRTPObserver() failed to locate channel");
110         return -1;
111     }
112     return channelPtr->RegisterRTCPObserver(observer);
113 }
114
115 int VoERTP_RTCPImpl::DeRegisterRTCPObserver(int channel)
116 {
117     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
118                  "DeRegisterRTCPObserver(channel=%d)", channel);
119     if (!_shared->statistics().Initialized())
120     {
121         _shared->SetLastError(VE_NOT_INITED, kTraceError);
122         return -1;
123     }
124     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
125     voe::Channel* channelPtr = ch.channel();
126     if (channelPtr == NULL)
127     {
128         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
129             "DeRegisterRTCPObserver() failed to locate channel");
130         return -1;
131     }
132     return channelPtr->DeRegisterRTCPObserver();
133 }
134
135 int VoERTP_RTCPImpl::SetLocalSSRC(int channel, unsigned int ssrc)
136 {
137     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
138                  "SetLocalSSRC(channel=%d, %lu)", channel, ssrc);
139     if (!_shared->statistics().Initialized())
140     {
141         _shared->SetLastError(VE_NOT_INITED, kTraceError);
142         return -1;
143     }
144     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
145     voe::Channel* channelPtr = ch.channel();
146     if (channelPtr == NULL)
147     {
148         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
149             "SetLocalSSRC() failed to locate channel");
150         return -1;
151     }
152     return channelPtr->SetLocalSSRC(ssrc);
153 }
154
155 int VoERTP_RTCPImpl::GetLocalSSRC(int channel, unsigned int& ssrc)
156 {
157     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
158                  "GetLocalSSRC(channel=%d, ssrc=?)", channel);
159     if (!_shared->statistics().Initialized())
160     {
161         _shared->SetLastError(VE_NOT_INITED, kTraceError);
162         return -1;
163     }
164     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
165     voe::Channel* channelPtr = ch.channel();
166     if (channelPtr == NULL)
167     {
168         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
169             "GetLocalSSRC() failed to locate channel");
170         return -1;
171     }
172     return channelPtr->GetLocalSSRC(ssrc);
173 }
174
175 int VoERTP_RTCPImpl::GetRemoteSSRC(int channel, unsigned int& ssrc)
176 {
177     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
178                  "GetRemoteSSRC(channel=%d, ssrc=?)", channel);
179     if (!_shared->statistics().Initialized())
180     {
181         _shared->SetLastError(VE_NOT_INITED, kTraceError);
182         return -1;
183     }
184     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
185     voe::Channel* channelPtr = ch.channel();
186     if (channelPtr == NULL)
187     {
188         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
189             "GetRemoteSSRC() failed to locate channel");
190         return -1;
191     }
192     return channelPtr->GetRemoteSSRC(ssrc);
193 }
194
195 int VoERTP_RTCPImpl::GetRemoteCSRCs(int channel, unsigned int arrCSRC[15])
196 {
197     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
198                  "GetRemoteCSRCs(channel=%d, arrCSRC=?)", channel);
199     if (!_shared->statistics().Initialized())
200     {
201         _shared->SetLastError(VE_NOT_INITED, kTraceError);
202         return -1;
203     }
204     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
205     voe::Channel* channelPtr = ch.channel();
206     if (channelPtr == NULL)
207     {
208         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
209             "GetRemoteCSRCs() failed to locate channel");
210         return -1;
211     }
212     return channelPtr->GetRemoteCSRCs(arrCSRC);
213 }
214
215 int VoERTP_RTCPImpl::SetSendAudioLevelIndicationStatus(int channel,
216                                                        bool enable,
217                                                        unsigned char id)
218 {
219     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
220                  "SetSendAudioLevelIndicationStatus(channel=%d, enable=%d,"
221                  " ID=%u)", channel, enable, id);
222     if (!_shared->statistics().Initialized())
223     {
224         _shared->SetLastError(VE_NOT_INITED, kTraceError);
225         return -1;
226     }
227     if (enable && (id < kVoiceEngineMinRtpExtensionId ||
228                    id > kVoiceEngineMaxRtpExtensionId))
229     {
230         // [RFC5285] The 4-bit id is the local identifier of this element in
231         // the range 1-14 inclusive.
232         _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
233             "SetSendAudioLevelIndicationStatus() invalid ID parameter");
234         return -1;
235     }
236
237     // Set state and id for the specified channel.
238     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
239     voe::Channel* channelPtr = ch.channel();
240     if (channelPtr == NULL)
241     {
242         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
243             "SetSendAudioLevelIndicationStatus() failed to locate channel");
244         return -1;
245     }
246     return channelPtr->SetSendAudioLevelIndicationStatus(enable, id);
247 }
248
249 int VoERTP_RTCPImpl::SetReceiveAudioLevelIndicationStatus(int channel,
250                                                           bool enable,
251                                                           unsigned char id) {
252   WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
253       "SetReceiveAudioLevelIndicationStatus(channel=%d, enable=%d, id=%u)",
254       channel, enable, id);
255   if (!_shared->statistics().Initialized()) {
256     _shared->SetLastError(VE_NOT_INITED, kTraceError);
257     return -1;
258   }
259   if (enable &&
260       (id < kVoiceEngineMinRtpExtensionId ||
261        id > kVoiceEngineMaxRtpExtensionId)) {
262     // [RFC5285] The 4-bit id is the local identifier of this element in
263     // the range 1-14 inclusive.
264     _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
265         "SetReceiveAbsoluteSenderTimeStatus() invalid id parameter");
266     return -1;
267   }
268   // Set state and id for the specified channel.
269   voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
270   voe::Channel* channel_ptr = ch.channel();
271   if (channel_ptr == NULL) {
272     _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
273         "SetReceiveAudioLevelIndicationStatus() failed to locate channel");
274     return -1;
275   }
276   return channel_ptr->SetReceiveAudioLevelIndicationStatus(enable, id);
277 }
278
279 int VoERTP_RTCPImpl::SetSendAbsoluteSenderTimeStatus(int channel,
280                                                      bool enable,
281                                                      unsigned char id) {
282   WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
283                "SetSendAbsoluteSenderTimeStatus(channel=%d, enable=%d, id=%u)",
284                channel, enable, id);
285   if (!_shared->statistics().Initialized()) {
286     _shared->SetLastError(VE_NOT_INITED, kTraceError);
287     return -1;
288   }
289   if (enable && (id < kVoiceEngineMinRtpExtensionId ||
290                  id > kVoiceEngineMaxRtpExtensionId)) {
291     // [RFC5285] The 4-bit id is the local identifier of this element in
292     // the range 1-14 inclusive.
293     _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
294         "SetSendAbsoluteSenderTimeStatus() invalid id parameter");
295     return -1;
296   }
297   // Set state and id for the specified channel.
298   voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
299   voe::Channel* channelPtr = ch.channel();
300   if (channelPtr == NULL) {
301     _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
302         "SetSendAbsoluteSenderTimeStatus() failed to locate channel");
303     return -1;
304   }
305   return channelPtr->SetSendAbsoluteSenderTimeStatus(enable, id);
306 }
307
308 int VoERTP_RTCPImpl::SetReceiveAbsoluteSenderTimeStatus(int channel,
309                                                         bool enable,
310                                                         unsigned char id) {
311   WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
312       "SetReceiveAbsoluteSenderTimeStatus(channel=%d, enable=%d, id=%u)",
313       channel, enable, id);
314   if (!_shared->statistics().Initialized()) {
315     _shared->SetLastError(VE_NOT_INITED, kTraceError);
316     return -1;
317   }
318   if (enable && (id < kVoiceEngineMinRtpExtensionId ||
319                  id > kVoiceEngineMaxRtpExtensionId)) {
320     // [RFC5285] The 4-bit id is the local identifier of this element in
321     // the range 1-14 inclusive.
322     _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
323         "SetReceiveAbsoluteSenderTimeStatus() invalid id parameter");
324     return -1;
325   }
326   // Set state and id for the specified channel.
327   voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
328   voe::Channel* channelPtr = ch.channel();
329   if (channelPtr == NULL) {
330     _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
331         "SetReceiveAbsoluteSenderTimeStatus() failed to locate channel");
332     return -1;
333   }
334   return channelPtr->SetReceiveAbsoluteSenderTimeStatus(enable, id);
335 }
336
337 int VoERTP_RTCPImpl::SetRTCPStatus(int channel, bool enable)
338 {
339     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
340                  "SetRTCPStatus(channel=%d, enable=%d)", channel, enable);
341     if (!_shared->statistics().Initialized())
342     {
343         _shared->SetLastError(VE_NOT_INITED, kTraceError);
344         return -1;
345     }
346     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
347     voe::Channel* channelPtr = ch.channel();
348     if (channelPtr == NULL)
349     {
350         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
351             "SetRTCPStatus() failed to locate channel");
352         return -1;
353     }
354     return channelPtr->SetRTCPStatus(enable);
355 }
356
357 int VoERTP_RTCPImpl::GetRTCPStatus(int channel, bool& enabled)
358 {
359     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
360                  "GetRTCPStatus(channel=%d)", channel);
361     if (!_shared->statistics().Initialized())
362     {
363         _shared->SetLastError(VE_NOT_INITED, kTraceError);
364         return -1;
365     }
366     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
367     voe::Channel* channelPtr = ch.channel();
368     if (channelPtr == NULL)
369     {
370         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
371             "GetRTCPStatus() failed to locate channel");
372         return -1;
373     }
374     return channelPtr->GetRTCPStatus(enabled);
375 }
376
377 int VoERTP_RTCPImpl::SetRTCP_CNAME(int channel, const char cName[256])
378 {
379     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
380                  "SetRTCP_CNAME(channel=%d, cName=%s)", channel, cName);
381     if (!_shared->statistics().Initialized())
382     {
383         _shared->SetLastError(VE_NOT_INITED, kTraceError);
384         return -1;
385     }
386     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
387     voe::Channel* channelPtr = ch.channel();
388     if (channelPtr == NULL)
389     {
390         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
391             "SetRTCP_CNAME() failed to locate channel");
392         return -1;
393     }
394     return channelPtr->SetRTCP_CNAME(cName);
395 }
396
397 int VoERTP_RTCPImpl::GetRTCP_CNAME(int channel, char cName[256])
398 {
399     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
400                  "GetRTCP_CNAME(channel=%d, cName=?)", channel);
401     if (!_shared->statistics().Initialized())
402     {
403         _shared->SetLastError(VE_NOT_INITED, kTraceError);
404         return -1;
405     }
406     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
407     voe::Channel* channelPtr = ch.channel();
408     if (channelPtr == NULL)
409     {
410         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
411             "GetRTCP_CNAME() failed to locate channel");
412         return -1;
413     }
414     return channelPtr->GetRTCP_CNAME(cName);
415 }
416
417 int VoERTP_RTCPImpl::GetRemoteRTCP_CNAME(int channel, char cName[256])
418 {
419     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
420                  "GetRemoteRTCP_CNAME(channel=%d, cName=?)", channel);
421     if (!_shared->statistics().Initialized())
422     {
423         _shared->SetLastError(VE_NOT_INITED, kTraceError);
424         return -1;
425     }
426     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
427     voe::Channel* channelPtr = ch.channel();
428     if (channelPtr == NULL)
429     {
430         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
431             "GetRemoteRTCP_CNAME() failed to locate channel");
432         return -1;
433     }
434     return channelPtr->GetRemoteRTCP_CNAME(cName);
435 }
436
437 int VoERTP_RTCPImpl::GetRemoteRTCPData(
438     int channel,
439     unsigned int& NTPHigh, // from sender info in SR
440     unsigned int& NTPLow, // from sender info in SR
441     unsigned int& timestamp, // from sender info in SR
442     unsigned int& playoutTimestamp, // derived locally
443     unsigned int* jitter, // from report block 1 in SR/RR
444     unsigned short* fractionLost) // from report block 1 in SR/RR
445 {
446     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
447                  "GetRemoteRTCPData(channel=%d,...)", channel);
448     if (!_shared->statistics().Initialized())
449     {
450         _shared->SetLastError(VE_NOT_INITED, kTraceError);
451         return -1;
452     }
453     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
454     voe::Channel* channelPtr = ch.channel();
455     if (channelPtr == NULL)
456     {
457         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
458             "GetRemoteRTCP_CNAME() failed to locate channel");
459         return -1;
460     }
461     return channelPtr->GetRemoteRTCPData(NTPHigh,
462                                          NTPLow,
463                                          timestamp,
464                                          playoutTimestamp,
465                                          jitter,
466                                          fractionLost);
467 }
468
469 int VoERTP_RTCPImpl::SendApplicationDefinedRTCPPacket(
470     int channel,
471     unsigned char subType,
472     unsigned int name,
473     const char* data,
474     unsigned short dataLengthInBytes)
475 {
476     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
477                  "SendApplicationDefinedRTCPPacket(channel=%d, subType=%u,"
478                  "name=%u, data=?, dataLengthInBytes=%u)",
479                  channel, subType, name, dataLengthInBytes);
480     if (!_shared->statistics().Initialized())
481     {
482         _shared->SetLastError(VE_NOT_INITED, kTraceError);
483         return -1;
484     }
485     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
486     voe::Channel* channelPtr = ch.channel();
487     if (channelPtr == NULL)
488     {
489         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
490             "SendApplicationDefinedRTCPPacket() failed to locate channel");
491         return -1;
492     }
493     return channelPtr->SendApplicationDefinedRTCPPacket(subType,
494                                                         name,
495                                                         data,
496                                                         dataLengthInBytes);
497 }
498
499 int VoERTP_RTCPImpl::GetRTPStatistics(int channel,
500                                       unsigned int& averageJitterMs,
501                                       unsigned int& maxJitterMs,
502                                       unsigned int& discardedPackets)
503 {
504     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
505                  "GetRTPStatistics(channel=%d,....)", channel);
506     if (!_shared->statistics().Initialized())
507     {
508         _shared->SetLastError(VE_NOT_INITED, kTraceError);
509         return -1;
510     }
511     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
512     voe::Channel* channelPtr = ch.channel();
513     if (channelPtr == NULL)
514     {
515         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
516             "GetRTPStatistics() failed to locate channel");
517         return -1;
518     }
519     return channelPtr->GetRTPStatistics(averageJitterMs,
520                                         maxJitterMs,
521                                         discardedPackets);
522 }
523
524 int VoERTP_RTCPImpl::GetRTCPStatistics(int channel, CallStatistics& stats)
525 {
526     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
527                  "GetRTCPStatistics(channel=%d)", channel);
528     if (!_shared->statistics().Initialized())
529     {
530         _shared->SetLastError(VE_NOT_INITED, kTraceError);
531         return -1;
532     }
533     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
534     voe::Channel* channelPtr = ch.channel();
535     if (channelPtr == NULL)
536     {
537         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
538             "GetRTPStatistics() failed to locate channel");
539         return -1;
540     }
541     return channelPtr->GetRTPStatistics(stats);
542 }
543
544 int VoERTP_RTCPImpl::GetRemoteRTCPSenderInfo(int channel,
545                                              SenderInfo* sender_info) {
546   WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
547                "GetRemoteRTCPSenderInfo(channel=%d)", channel);
548   if (!_shared->statistics().Initialized()) {
549     _shared->SetLastError(VE_NOT_INITED, kTraceError);
550     return -1;
551   }
552   voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
553   voe::Channel* channel_ptr = ch.channel();
554   if (channel_ptr == NULL) {
555     _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
556         "GetRemoteRTCPSenderInfo() failed to locate channel");
557     return -1;
558   }
559   return channel_ptr->GetRemoteRTCPSenderInfo(sender_info);
560 }
561
562 int VoERTP_RTCPImpl::GetRemoteRTCPReportBlocks(
563     int channel, std::vector<ReportBlock>* report_blocks) {
564   WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
565                "GetRemoteRTCPReportBlocks(channel=%d)", channel);
566   if (!_shared->statistics().Initialized()) {
567     _shared->SetLastError(VE_NOT_INITED, kTraceError);
568     return -1;
569   }
570   voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
571   voe::Channel* channel_ptr = ch.channel();
572   if (channel_ptr == NULL) {
573     _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
574         "GetRemoteRTCPReportBlocks() failed to locate channel");
575     return -1;
576   }
577   return channel_ptr->GetRemoteRTCPReportBlocks(report_blocks);
578 }
579
580 int VoERTP_RTCPImpl::SetFECStatus(int channel, bool enable, int redPayloadtype)
581 {
582     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
583                  "SetFECStatus(channel=%d, enable=%d, redPayloadtype=%d)",
584                  channel, enable, redPayloadtype);
585 #ifdef WEBRTC_CODEC_RED
586     if (!_shared->statistics().Initialized())
587     {
588         _shared->SetLastError(VE_NOT_INITED, kTraceError);
589         return -1;
590     }
591     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
592     voe::Channel* channelPtr = ch.channel();
593     if (channelPtr == NULL)
594     {
595         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
596             "SetFECStatus() failed to locate channel");
597         return -1;
598     }
599     return channelPtr->SetFECStatus(enable, redPayloadtype);
600 #else
601     _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
602         "SetFECStatus() RED is not supported");
603     return -1;
604 #endif
605 }
606
607 int VoERTP_RTCPImpl::GetFECStatus(int channel,
608                                   bool& enabled,
609                                   int& redPayloadtype)
610 {
611     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
612                  "GetFECStatus(channel=%d, enabled=?, redPayloadtype=?)",
613                  channel);
614 #ifdef WEBRTC_CODEC_RED
615     if (!_shared->statistics().Initialized())
616     {
617         _shared->SetLastError(VE_NOT_INITED, kTraceError);
618         return -1;
619     }
620     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
621     voe::Channel* channelPtr = ch.channel();
622     if (channelPtr == NULL)
623     {
624         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
625             "GetFECStatus() failed to locate channel");
626         return -1;
627     }
628     return channelPtr->GetFECStatus(enabled, redPayloadtype);
629 #else
630     _shared->SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError,
631         "GetFECStatus() RED is not supported");
632     return -1;
633 #endif
634 }
635
636
637 int VoERTP_RTCPImpl::SetNACKStatus(int channel,
638                                    bool enable,
639                                    int maxNoPackets)
640 {
641     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
642                  "SetNACKStatus(channel=%d, enable=%d, maxNoPackets=%d)",
643                  channel, enable, maxNoPackets);
644
645     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
646     voe::Channel* channelPtr = ch.channel();
647     if (channelPtr == NULL)
648     {
649         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
650             "SetNACKStatus() failed to locate channel");
651         return -1;
652     }
653     channelPtr->SetNACKStatus(enable, maxNoPackets);
654     return 0;
655 }
656
657
658 int VoERTP_RTCPImpl::StartRTPDump(int channel,
659                                   const char fileNameUTF8[1024],
660                                   RTPDirections direction)
661 {
662     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
663                  "StartRTPDump(channel=%d, fileNameUTF8=%s, direction=%d)",
664                  channel, fileNameUTF8, direction);
665     assert(1024 == FileWrapper::kMaxFileNameSize);
666     if (!_shared->statistics().Initialized())
667     {
668         _shared->SetLastError(VE_NOT_INITED, kTraceError);
669         return -1;
670     }
671     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
672     voe::Channel* channelPtr = ch.channel();
673     if (channelPtr == NULL)
674     {
675         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
676             "StartRTPDump() failed to locate channel");
677         return -1;
678     }
679     return channelPtr->StartRTPDump(fileNameUTF8, direction);
680 }
681
682 int VoERTP_RTCPImpl::StopRTPDump(int channel, RTPDirections direction)
683 {
684     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
685                  "StopRTPDump(channel=%d, direction=%d)", channel, direction);
686     if (!_shared->statistics().Initialized())
687     {
688         _shared->SetLastError(VE_NOT_INITED, kTraceError);
689         return -1;
690     }
691     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
692     voe::Channel* channelPtr = ch.channel();
693     if (channelPtr == NULL)
694     {
695         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
696             "StopRTPDump() failed to locate channel");
697         return -1;
698     }
699     return channelPtr->StopRTPDump(direction);
700 }
701
702 int VoERTP_RTCPImpl::RTPDumpIsActive(int channel, RTPDirections direction)
703 {
704     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
705                  "RTPDumpIsActive(channel=%d, direction=%d)",
706                  channel, direction);
707     if (!_shared->statistics().Initialized())
708     {
709         _shared->SetLastError(VE_NOT_INITED, kTraceError);
710         return -1;
711     }
712     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
713     voe::Channel* channelPtr = ch.channel();
714     if (channelPtr == NULL)
715     {
716         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
717             "StopRTPDump() failed to locate channel");
718         return -1;
719     }
720     return channelPtr->RTPDumpIsActive(direction);
721 }
722
723 int VoERTP_RTCPImpl::GetLastRemoteTimeStamp(int channel,
724                                             uint32_t* timestamp) {
725     WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
726                  "GetLastRemoteTimeStamp(channel=%d, timestamp=?)", channel);
727     if (!_shared->statistics().Initialized())
728     {
729         _shared->SetLastError(VE_NOT_INITED, kTraceError);
730         return -1;
731     }
732     voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
733     voe::Channel* channelPtr = ch.channel();
734     if (channelPtr == NULL)
735     {
736         _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
737             "GetLastRemoteTimeStamp() failed to locate channel");
738         return -1;
739     }
740     *timestamp = channelPtr->LastRemoteTimeStamp();
741     return 0;
742 }
743
744 int VoERTP_RTCPImpl::SetVideoEngineBWETarget(int channel,
745                                              ViENetwork* vie_network,
746                                              int video_channel) {
747   WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
748       "SetVideoEngineBWETarget(channel=%d, vie_network=?, video_channel=%d)",
749       channel, vie_network, video_channel);
750
751   voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
752   voe::Channel* channelPtr = ch.channel();
753   if (channelPtr == NULL) {
754     _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
755                           "SetVideoEngineBWETarget() failed to locate channel");
756     if (vie_network) {
757       vie_network->Release();
758     }
759     return -1;
760   }
761   channelPtr->SetVideoEngineBWETarget(vie_network, video_channel);
762   return 0;
763 }
764
765 #endif  // #ifdef WEBRTC_VOICE_ENGINE_RTP_RTCP_API
766
767 }  // namespace webrtc