blob: 5554734f1ad71112bcbd88307d0bc308d829b9fb [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
stefan@webrtc.org07b45a52012-02-02 08:37:48 +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
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000011#include "video_engine/vie_rtp_rtcp_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +000013#include "engine_configurations.h" // NOLINT
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000014#include "system_wrappers/interface/file_wrapper.h"
15#include "system_wrappers/interface/trace.h"
mflodman@webrtc.orga4863db2011-12-22 08:51:52 +000016#include "video_engine/include/vie_errors.h"
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000017#include "video_engine/vie_channel.h"
18#include "video_engine/vie_channel_manager.h"
19#include "video_engine/vie_defines.h"
20#include "video_engine/vie_encoder.h"
21#include "video_engine/vie_impl.h"
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000022#include "video_engine/vie_shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000024namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000025
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000026// Helper methods for converting between module format and ViE API format.
niklase@google.com470e71d2011-07-07 08:21:25 +000027
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000028static RTCPMethod ViERTCPModeToRTCPMethod(ViERTCPMode api_mode) {
29 switch (api_mode) {
30 case kRtcpNone:
31 return kRtcpOff;
niklase@google.com470e71d2011-07-07 08:21:25 +000032
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000033 case kRtcpCompound_RFC4585:
34 return kRtcpCompound;
35
36 case kRtcpNonCompound_RFC5506:
37 return kRtcpNonCompound;
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000038 }
mflodman@webrtc.org657b2a42012-02-06 11:06:01 +000039 assert(false);
40 return kRtcpOff;
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000041}
42
43static ViERTCPMode RTCPMethodToViERTCPMode(RTCPMethod module_method) {
44 switch (module_method) {
45 case kRtcpOff:
46 return kRtcpNone;
47
48 case kRtcpCompound:
49 return kRtcpCompound_RFC4585;
50
51 case kRtcpNonCompound:
52 return kRtcpNonCompound_RFC5506;
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000053 }
mflodman@webrtc.org657b2a42012-02-06 11:06:01 +000054 assert(false);
55 return kRtcpNone;
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000056}
57
58static KeyFrameRequestMethod APIRequestToModuleRequest(
59 ViEKeyFrameRequestMethod api_method) {
60 switch (api_method) {
61 case kViEKeyFrameRequestNone:
62 return kKeyFrameReqFirRtp;
63
64 case kViEKeyFrameRequestPliRtcp:
65 return kKeyFrameReqPliRtcp;
66
67 case kViEKeyFrameRequestFirRtp:
68 return kKeyFrameReqFirRtp;
69
70 case kViEKeyFrameRequestFirRtcp:
71 return kKeyFrameReqFirRtcp;
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000072 }
mflodman@webrtc.org657b2a42012-02-06 11:06:01 +000073 assert(false);
74 return kKeyFrameReqFirRtp;
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000075}
76
77ViERTP_RTCP* ViERTP_RTCP::GetInterface(VideoEngine* video_engine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000078#ifdef WEBRTC_VIDEO_ENGINE_RTP_RTCP_API
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000079 if (!video_engine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000080 return NULL;
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000081 }
82 VideoEngineImpl* vie_impl = reinterpret_cast<VideoEngineImpl*>(video_engine);
83 ViERTP_RTCPImpl* vie_rtpimpl = vie_impl;
84 // Increase ref count.
85 (*vie_rtpimpl)++;
86 return vie_rtpimpl;
87#else
88 return NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +000089#endif
90}
91
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000092int ViERTP_RTCPImpl::Release() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000093 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000094 "ViERTP_RTCP::Release()");
95 // Decrease ref count.
96 (*this)--;
niklase@google.com470e71d2011-07-07 08:21:25 +000097
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000098 WebRtc_Word32 ref_count = GetCount();
99 if (ref_count < 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000100 WEBRTC_TRACE(kTraceWarning, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000101 "ViERTP_RTCP release too many times");
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000102 shared_data_->SetLastError(kViEAPIDoesNotExist);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000103 return -1;
104 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000105 WEBRTC_TRACE(kTraceInfo, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000106 "ViERTP_RTCP reference count: %d", ref_count);
107 return ref_count;
niklase@google.com470e71d2011-07-07 08:21:25 +0000108}
109
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000110ViERTP_RTCPImpl::ViERTP_RTCPImpl(ViESharedData* shared_data)
111 : shared_data_(shared_data) {
112 WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000113 "ViERTP_RTCPImpl::ViERTP_RTCPImpl() Ctor");
niklase@google.com470e71d2011-07-07 08:21:25 +0000114}
115
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000116ViERTP_RTCPImpl::~ViERTP_RTCPImpl() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000117 WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000118 "ViERTP_RTCPImpl::~ViERTP_RTCPImpl() Dtor");
niklase@google.com470e71d2011-07-07 08:21:25 +0000119}
120
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000121int ViERTP_RTCPImpl::SetLocalSSRC(const int video_channel,
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000122 const unsigned int SSRC,
123 const StreamType usage,
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000124 const unsigned char simulcast_idx) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000125 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
126 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000127 "%s(channel: %d, SSRC: %d)", __FUNCTION__, video_channel, SSRC);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000128 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000129 ViEChannel* vie_channel = cs.Channel(video_channel);
130 if (!vie_channel) {
stefan@webrtc.orgd0bdab02011-10-14 14:24:54 +0000131 // The channel doesn't exists
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000132 WEBRTC_TRACE(kTraceError, kTraceVideo,
133 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000134 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000135 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000136 return -1;
137 }
138 if (vie_channel->SetSSRC(SSRC, usage, simulcast_idx) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000139 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000140 return -1;
141 }
142 return 0;
143}
144
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000145int ViERTP_RTCPImpl::SetRemoteSSRCType(const int videoChannel,
146 const StreamType usage,
147 const unsigned int SSRC) const {
148 WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideo,
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000149 ViEId(shared_data_->instance_id(), videoChannel),
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000150 "%s(channel: %d, usage:%d SSRC: 0x%x)",
151 __FUNCTION__, usage, videoChannel, SSRC);
152
153 // Get the channel
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000154 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000155 ViEChannel* ptrViEChannel = cs.Channel(videoChannel);
156 if (ptrViEChannel == NULL) {
157 // The channel doesn't exists
158 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo,
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000159 ViEId(shared_data_->instance_id(), videoChannel),
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000160 "%s: Channel %d doesn't exist",
161 __FUNCTION__, videoChannel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000162 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000163 return -1;
164 }
165 if (ptrViEChannel->SetRemoteSSRCType(usage, SSRC) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000166 shared_data_->SetLastError(kViERtpRtcpUnknownError);
pwestin@webrtc.org8281e7d2012-01-10 14:09:18 +0000167 return -1;
168 }
169 return 0;
170}
171
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000172int ViERTP_RTCPImpl::GetLocalSSRC(const int video_channel,
173 unsigned int& SSRC) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000174 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
175 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000176 "%s(channel: %d, SSRC: %d)", __FUNCTION__, video_channel, SSRC);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000177 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000178 ViEChannel* vie_channel = cs.Channel(video_channel);
179 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000180 WEBRTC_TRACE(kTraceError, kTraceVideo,
181 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000182 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000183 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000184 return -1;
185 }
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000186 if (vie_channel->GetLocalSSRC(&SSRC) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000187 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000188 return -1;
189 }
190 return 0;
191}
192
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000193int ViERTP_RTCPImpl::GetRemoteSSRC(const int video_channel,
194 unsigned int& SSRC) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000195 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
196 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000197 "%s(channel: %d)", __FUNCTION__, video_channel, SSRC);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000198 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000199 ViEChannel* vie_channel = cs.Channel(video_channel);
200 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000201 WEBRTC_TRACE(kTraceError, kTraceVideo,
202 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000203 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000204 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000205 return -1;
206 }
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000207 if (vie_channel->GetRemoteSSRC(&SSRC) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000208 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000209 return -1;
210 }
211 return 0;
212}
213
214int ViERTP_RTCPImpl::GetRemoteCSRCs(const int video_channel,
215 unsigned int CSRCs[kRtpCsrcSize]) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000216 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
217 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000218 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000219 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000220 ViEChannel* vie_channel = cs.Channel(video_channel);
221 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000222 WEBRTC_TRACE(kTraceError, kTraceVideo,
223 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000224 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000225 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000226 return -1;
227 }
228 if (vie_channel->GetRemoteCSRC(CSRCs) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000229 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000230 return -1;
231 }
232 return 0;
233}
234
235int ViERTP_RTCPImpl::SetStartSequenceNumber(const int video_channel,
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000236 uint16_t sequence_number) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000237 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
238 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000239 "%s(channel: %d, sequence_number: %u)", __FUNCTION__,
240 video_channel, sequence_number);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000241 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000242 ViEChannel* vie_channel = cs.Channel(video_channel);
243 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000244 WEBRTC_TRACE(kTraceError, kTraceVideo,
245 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000246 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000247 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000248 return -1;
249 }
250 if (vie_channel->Sending()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000251 WEBRTC_TRACE(kTraceError, kTraceVideo,
252 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000253 "%s: Channel %d already sending.", __FUNCTION__,
254 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000255 shared_data_->SetLastError(kViERtpRtcpAlreadySending);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000256 return -1;
257 }
258 if (vie_channel->SetStartSequenceNumber(sequence_number) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000259 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000260 return -1;
261 }
262 return 0;
263}
264
265int ViERTP_RTCPImpl::SetRTCPStatus(const int video_channel,
266 const ViERTCPMode rtcp_mode) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000267 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
268 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000269 "%s(channel: %d, mode: %d)", __FUNCTION__, video_channel,
270 rtcp_mode);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000271 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000272 ViEChannel* vie_channel = cs.Channel(video_channel);
273 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000274 WEBRTC_TRACE(kTraceError, kTraceVideo,
275 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000276 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000277 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
stefan@webrtc.orgd0bdab02011-10-14 14:24:54 +0000278 return -1;
279 }
280
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000281 RTCPMethod module_mode = ViERTCPModeToRTCPMethod(rtcp_mode);
282 if (vie_channel->SetRTCPMode(module_mode) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000283 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000284 return -1;
285 }
286 return 0;
287}
288
289int ViERTP_RTCPImpl::GetRTCPStatus(const int video_channel,
290 ViERTCPMode& rtcp_mode) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000291 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
292 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000293 "%s(channel: %d)", __FUNCTION__, video_channel, rtcp_mode);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000294 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000295 ViEChannel* vie_channel = cs.Channel(video_channel);
296 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000297 WEBRTC_TRACE(kTraceError, kTraceVideo,
298 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000299 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000300 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000301 return -1;
302 }
303 RTCPMethod module_mode = kRtcpOff;
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000304 if (vie_channel->GetRTCPMode(&module_mode) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000305 WEBRTC_TRACE(kTraceError, kTraceVideo,
306 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000307 "%s: could not get current RTCP mode", __FUNCTION__);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000308 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000309 return -1;
310 }
311 rtcp_mode = RTCPMethodToViERTCPMode(module_mode);
312 return 0;
313}
314
315int ViERTP_RTCPImpl::SetRTCPCName(const int video_channel,
316 const char rtcp_cname[KMaxRTCPCNameLength]) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000317 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
318 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000319 "%s(channel: %d, name: %s)", __FUNCTION__, video_channel,
320 rtcp_cname);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000321 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000322 ViEChannel* vie_channel = cs.Channel(video_channel);
323 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000324 WEBRTC_TRACE(kTraceError, kTraceVideo,
325 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000326 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000327 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000328 return -1;
329 }
330 if (vie_channel->Sending()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000331 WEBRTC_TRACE(kTraceError, kTraceVideo,
332 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000333 "%s: Channel %d already sending.", __FUNCTION__,
334 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000335 shared_data_->SetLastError(kViERtpRtcpAlreadySending);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000336 return -1;
337 }
338 if (vie_channel->SetRTCPCName(rtcp_cname) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000339 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000340 return -1;
341 }
342 return 0;
343}
344
345int ViERTP_RTCPImpl::GetRTCPCName(const int video_channel,
346 char rtcp_cname[KMaxRTCPCNameLength]) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000347 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
348 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000349 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000350 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000351 ViEChannel* vie_channel = cs.Channel(video_channel);
352 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000353 WEBRTC_TRACE(kTraceError, kTraceVideo,
354 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000355 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000356 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000357 return -1;
358 }
359 if (vie_channel->GetRTCPCName(rtcp_cname) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000360 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000361 return -1;
362 }
363 return 0;
364}
365
366int ViERTP_RTCPImpl::GetRemoteRTCPCName(
367 const int video_channel,
368 char rtcp_cname[KMaxRTCPCNameLength]) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000369 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
370 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000371 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000372 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000373 ViEChannel* vie_channel = cs.Channel(video_channel);
374 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000375 WEBRTC_TRACE(kTraceError, kTraceVideo,
376 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000377 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000378 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000379 return -1;
380 }
381 if (vie_channel->GetRemoteRTCPCName(rtcp_cname) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000382 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000383 return -1;
384 }
385 return 0;
386}
387
388int ViERTP_RTCPImpl::SendApplicationDefinedRTCPPacket(
389 const int video_channel,
390 const unsigned char sub_type,
391 unsigned int name,
392 const char* data,
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000393 uint16_t data_length_in_bytes) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000394 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
395 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000396 "%s(channel: %d, sub_type: %c, name: %d, data: x, length: %u)",
397 __FUNCTION__, video_channel, sub_type, name,
398 data_length_in_bytes);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000399 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000400 ViEChannel* vie_channel = cs.Channel(video_channel);
401 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000402 WEBRTC_TRACE(kTraceError, kTraceVideo,
403 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000404 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000405 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000406 return -1;
407 }
408 if (!vie_channel->Sending()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000409 WEBRTC_TRACE(kTraceError, kTraceVideo,
410 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000411 "%s: Channel %d not sending", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000412 shared_data_->SetLastError(kViERtpRtcpNotSending);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000413 return -1;
414 }
415 RTCPMethod method;
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000416 if (vie_channel->GetRTCPMode(&method) != 0 || method == kRtcpOff) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000417 WEBRTC_TRACE(kTraceError, kTraceVideo,
418 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000419 "%s: RTCP disabled on channel %d.", __FUNCTION__,
420 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000421 shared_data_->SetLastError(kViERtpRtcpRtcpDisabled);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000422 return -1;
423 }
424 if (vie_channel->SendApplicationDefinedRTCPPacket(
425 sub_type, name, reinterpret_cast<const WebRtc_UWord8*>(data),
426 data_length_in_bytes) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000427 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000428 return -1;
429 }
430 return 0;
431}
432
433int ViERTP_RTCPImpl::SetNACKStatus(const int video_channel, const bool enable) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000434 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
435 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000436 "%s(channel: %d, enable: %d)", __FUNCTION__, video_channel,
437 enable);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000438 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000439 ViEChannel* vie_channel = cs.Channel(video_channel);
440 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000441 WEBRTC_TRACE(kTraceError, kTraceVideo,
442 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000443 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000444 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000445 return -1;
446 }
447 if (vie_channel->SetNACKStatus(enable) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000448 WEBRTC_TRACE(kTraceError, kTraceVideo,
449 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000450 "%s: failed for channel %d", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000451 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000452 return -1;
453 }
454
455 // Update the encoder
456 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
457 if (!vie_encoder) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000458 WEBRTC_TRACE(kTraceError, kTraceVideo,
459 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000460 "%s: Could not get encoder for channel %d", __FUNCTION__,
461 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000462 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000463 return -1;
464 }
465 vie_encoder->UpdateProtectionMethod();
466 return 0;
467}
468
469int ViERTP_RTCPImpl::SetFECStatus(const int video_channel, const bool enable,
470 const unsigned char payload_typeRED,
471 const unsigned char payload_typeFEC) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000472 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
473 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000474 "%s(channel: %d, enable: %d, payload_typeRED: %u, "
475 "payloadTypeFEC: %u)",
476 __FUNCTION__, video_channel, enable, payload_typeRED,
477 payload_typeFEC);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000478 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000479 ViEChannel* vie_channel = cs.Channel(video_channel);
480 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000481 WEBRTC_TRACE(kTraceError, kTraceVideo,
482 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000483 "%s: Channel %d doesn't exist", __FUNCTION__,
484 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000485 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000486 return -1;
487 }
488 if (vie_channel->SetFECStatus(enable, payload_typeRED,
489 payload_typeFEC) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000490 WEBRTC_TRACE(kTraceError, kTraceVideo,
491 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000492 "%s: failed for channel %d", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000493 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000494 return -1;
495 }
496 // Update the encoder.
497 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
498 if (!vie_encoder) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000499 WEBRTC_TRACE(kTraceError, kTraceVideo,
500 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000501 "%s: Could not get encoder for channel %d", __FUNCTION__,
502 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000503 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000504 return -1;
505 }
506 vie_encoder->UpdateProtectionMethod();
507 return 0;
508}
509
510int ViERTP_RTCPImpl::SetHybridNACKFECStatus(
511 const int video_channel,
512 const bool enable,
513 const unsigned char payload_typeRED,
514 const unsigned char payload_typeFEC) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000515 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
516 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000517 "%s(channel: %d, enable: %d, payload_typeRED: %u, "
518 "payloadTypeFEC: %u)",
519 __FUNCTION__, video_channel, enable, payload_typeRED,
520 payload_typeFEC);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000521 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000522 ViEChannel* vie_channel = cs.Channel(video_channel);
523 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000524 WEBRTC_TRACE(kTraceError, kTraceVideo,
525 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000526 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000527 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000528 return -1;
529 }
530
531 // Update the channel status with hybrid NACK FEC mode.
532 if (vie_channel->SetHybridNACKFECStatus(enable, payload_typeRED,
533 payload_typeFEC) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000534 WEBRTC_TRACE(kTraceError, kTraceVideo,
535 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000536 "%s: failed for channel %d", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000537 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000538 return -1;
539 }
540
541 // Update the encoder.
542 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
543 if (!vie_encoder) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000544 WEBRTC_TRACE(kTraceError, kTraceVideo,
545 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000546 "%s: Could not get encoder for channel %d", __FUNCTION__,
547 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000548 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000549 return -1;
550 }
551 vie_encoder->UpdateProtectionMethod();
552 return 0;
553}
554
555int ViERTP_RTCPImpl::SetKeyFrameRequestMethod(
556 const int video_channel,
557 const ViEKeyFrameRequestMethod method) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000558 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
559 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000560 "%s(channel: %d, method: %d)", __FUNCTION__, video_channel,
561 method);
562
563 // Get the channel.
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000564 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000565 ViEChannel* vie_channel = cs.Channel(video_channel);
566 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000567 WEBRTC_TRACE(kTraceError, kTraceVideo,
568 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000569 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000570 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000571 return -1;
572 }
573 KeyFrameRequestMethod module_method = APIRequestToModuleRequest(method);
574 if (vie_channel->SetKeyFrameRequestMethod(module_method) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000575 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000576 return -1;
577 }
578 return 0;
579}
580
581int ViERTP_RTCPImpl::SetTMMBRStatus(const int video_channel,
582 const bool enable) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000583 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
584 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000585 "%s(channel: %d, enable: %d)", __FUNCTION__, video_channel,
586 enable);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000587 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000588 ViEChannel* vie_channel = cs.Channel(video_channel);
589 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000590 WEBRTC_TRACE(kTraceError, kTraceVideo,
591 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000592 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000593 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000594 return -1;
595 }
596 if (vie_channel->EnableTMMBR(enable) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000597 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000598 return -1;
599 }
600 return 0;
601}
602
mflodman@webrtc.org6cf529d2012-01-24 06:16:16 +0000603int ViERTP_RTCPImpl::SetRembStatus(int video_channel, bool sender,
mflodman@webrtc.org84dc3d12011-12-22 10:26:13 +0000604 bool receiver) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000605 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
606 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org84dc3d12011-12-22 10:26:13 +0000607 "ViERTP_RTCPImpl::SetRembStatus(%d, %d, %d)", video_channel,
608 sender, receiver);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000609 if (!shared_data_->channel_manager()->SetRembStatus(video_channel, sender,
610 receiver)) {
mflodman@webrtc.org6cf529d2012-01-24 06:16:16 +0000611 return -1;
612 }
613 return 0;
mflodman@webrtc.org84dc3d12011-12-22 10:26:13 +0000614}
615
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000616int ViERTP_RTCPImpl::GetReceivedRTCPStatistics(const int video_channel,
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000617 uint16_t& fraction_lost,
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000618 unsigned int& cumulative_lost,
619 unsigned int& extended_max,
620 unsigned int& jitter,
621 int& rtt_ms) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000622 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
623 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000624 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000625 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000626 ViEChannel* vie_channel = cs.Channel(video_channel);
627 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000628 WEBRTC_TRACE(kTraceError, kTraceVideo,
629 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000630 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000631 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000632 return -1;
633 }
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000634 if (vie_channel->GetReceivedRtcpStatistics(&fraction_lost,
635 &cumulative_lost,
636 &extended_max,
637 &jitter,
638 &rtt_ms) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000639 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000640 return -1;
641 }
642 return 0;
643}
644
645int ViERTP_RTCPImpl::GetSentRTCPStatistics(const int video_channel,
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000646 uint16_t& fraction_lost,
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000647 unsigned int& cumulative_lost,
648 unsigned int& extended_max,
649 unsigned int& jitter,
650 int& rtt_ms) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000651 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
652 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000653 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000654 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000655 ViEChannel* vie_channel = cs.Channel(video_channel);
656 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000657 WEBRTC_TRACE(kTraceError, kTraceVideo,
658 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000659 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000660 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000661 return -1;
662 }
663
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000664 if (vie_channel->GetSendRtcpStatistics(&fraction_lost, &cumulative_lost,
665 &extended_max, &jitter,
666 &rtt_ms) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000667 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000668 return -1;
669 }
670 return 0;
671}
672
673int ViERTP_RTCPImpl::GetRTPStatistics(const int video_channel,
674 unsigned int& bytes_sent,
675 unsigned int& packets_sent,
676 unsigned int& bytes_received,
677 unsigned int& packets_received) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000678 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
679 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000680 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000681 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000682 ViEChannel* vie_channel = cs.Channel(video_channel);
683 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000684 WEBRTC_TRACE(kTraceError, kTraceVideo,
685 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000686 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000687 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000688 return -1;
689 }
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000690 if (vie_channel->GetRtpStatistics(&bytes_sent,
691 &packets_sent,
692 &bytes_received,
693 &packets_received) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000694 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000695 return -1;
696 }
697 return 0;
698}
699
700int ViERTP_RTCPImpl::GetBandwidthUsage(const int video_channel,
701 unsigned int& total_bitrate_sent,
702 unsigned int& video_bitrate_sent,
703 unsigned int& fec_bitrate_sent,
704 unsigned int& nackBitrateSent) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000705 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
706 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000707 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000708 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000709 ViEChannel* vie_channel = cs.Channel(video_channel);
710 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000711 WEBRTC_TRACE(kTraceError, kTraceVideo,
712 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000713 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000714 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000715 return -1;
716 }
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000717 vie_channel->GetBandwidthUsage(&total_bitrate_sent,
718 &video_bitrate_sent,
719 &fec_bitrate_sent,
720 &nackBitrateSent);
stefan@webrtc.orgd0bdab02011-10-14 14:24:54 +0000721 return 0;
722}
723
stefan@webrtc.org439be292012-02-16 14:45:37 +0000724int ViERTP_RTCPImpl::GetEstimatedSendBandwidth(
stefan@webrtc.org07b45a52012-02-02 08:37:48 +0000725 const int video_channel,
726 unsigned int* estimated_bandwidth) const {
727 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
728 ViEId(shared_data_->instance_id(), video_channel),
729 "%s(channel: %d)", __FUNCTION__, video_channel);
730 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
731 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
732 if (!vie_encoder) {
733 WEBRTC_TRACE(kTraceError, kTraceVideo,
734 ViEId(shared_data_->instance_id(), video_channel),
735 "%s: Could not get encoder for channel %d", __FUNCTION__,
736 video_channel);
737 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
738 return -1;
739 }
stefan@webrtc.org439be292012-02-16 14:45:37 +0000740 return vie_encoder->EstimatedSendBandwidth(
741 static_cast<WebRtc_UWord32*>(estimated_bandwidth));
742}
743
744int ViERTP_RTCPImpl::GetEstimatedReceiveBandwidth(
745 const int video_channel,
746 unsigned int* estimated_bandwidth) const {
747 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
748 ViEId(shared_data_->instance_id(), video_channel),
749 "%s(channel: %d)", __FUNCTION__, video_channel);
750 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
751 ViEChannel* vie_channel = cs.Channel(video_channel);
752 if (!vie_channel) {
753 WEBRTC_TRACE(kTraceError, kTraceVideo,
754 ViEId(shared_data_->instance_id(), video_channel),
755 "%s: Could not get channel %d", __FUNCTION__,
756 video_channel);
757 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
758 return -1;
759 }
760 return vie_channel->GetEstimatedReceiveBandwidth(
stefan@webrtc.org07b45a52012-02-02 08:37:48 +0000761 static_cast<WebRtc_UWord32*>(estimated_bandwidth));
762}
763
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000764int ViERTP_RTCPImpl::StartRTPDump(const int video_channel,
765 const char file_nameUTF8[1024],
766 RTPDirections direction) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000767 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
768 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000769 "%s(channel: %d, file_name: %s, direction: %d)", __FUNCTION__,
770 video_channel, file_nameUTF8, direction);
771 assert(FileWrapper::kMaxFileNameSize == 1024);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000772 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000773 ViEChannel* vie_channel = cs.Channel(video_channel);
774 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000775 WEBRTC_TRACE(kTraceError, kTraceVideo,
776 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000777 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000778 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000779 return -1;
780 }
781 if (vie_channel->StartRTPDump(file_nameUTF8, direction) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000782 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000783 return -1;
784 }
785 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000786}
787
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000788int ViERTP_RTCPImpl::StopRTPDump(const int video_channel,
789 RTPDirections direction) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000790 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
791 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000792 "%s(channel: %d, direction: %d)", __FUNCTION__, video_channel,
793 direction);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000794 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000795 ViEChannel* vie_channel = cs.Channel(video_channel);
796 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000797 WEBRTC_TRACE(kTraceError, kTraceVideo,
798 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000799 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000800 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000801 return -1;
802 }
803 if (vie_channel->StopRTPDump(direction) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000804 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000805 return -1;
806 }
807 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000808}
809
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000810int ViERTP_RTCPImpl::RegisterRTPObserver(const int video_channel,
811 ViERTPObserver& observer) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000812 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
813 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000814 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000815 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000816 ViEChannel* vie_channel = cs.Channel(video_channel);
817 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000818 WEBRTC_TRACE(kTraceError, kTraceVideo,
819 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000820 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000821 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000822 return -1;
823 }
824 if (vie_channel->RegisterRtpObserver(&observer) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000825 shared_data_->SetLastError(kViERtpRtcpObserverAlreadyRegistered);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000826 return -1;
827 }
828 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000829}
830
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000831int ViERTP_RTCPImpl::DeregisterRTPObserver(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000832 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
833 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000834 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000835 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000836 ViEChannel* vie_channel = cs.Channel(video_channel);
837 if (!vie_channel) {
838 WEBRTC_TRACE(kTraceError, kTraceVideo,
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000839 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000840 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000841 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000842 return -1;
843 }
844 if (vie_channel->RegisterRtpObserver(NULL) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000845 shared_data_->SetLastError(kViERtpRtcpObserverNotRegistered);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000846 return -1;
847 }
848 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000849}
850
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000851int ViERTP_RTCPImpl::RegisterRTCPObserver(const int video_channel,
852 ViERTCPObserver& observer) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000853 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
854 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000855 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000856 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000857 ViEChannel* vie_channel = cs.Channel(video_channel);
858 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000859 WEBRTC_TRACE(kTraceError, kTraceVideo,
860 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000861 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000862 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000863 return -1;
864 }
865 if (vie_channel->RegisterRtcpObserver(&observer) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000866 shared_data_->SetLastError(kViERtpRtcpObserverAlreadyRegistered);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000867 return -1;
868 }
869 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000870}
871
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000872int ViERTP_RTCPImpl::DeregisterRTCPObserver(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000873 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
874 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000875 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000876 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000877 ViEChannel* vie_channel = cs.Channel(video_channel);
878 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000879 WEBRTC_TRACE(kTraceError, kTraceVideo,
880 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000881 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000882 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000883 return -1;
884 }
885 if (vie_channel->RegisterRtcpObserver(NULL) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000886 shared_data_->SetLastError(kViERtpRtcpObserverNotRegistered);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000887 return -1;
888 }
889 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000890}
891
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000892} // namespace webrtc