blob: f04e0e75cc3fd140a45d21f0cb5c41a493c5f8cc [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.orgd6ec3862012-10-25 11:30:29 +0000186 uint8_t idx = 0;
187 if (vie_channel->GetLocalSSRC(idx, &SSRC) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000188 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000189 return -1;
190 }
191 return 0;
192}
193
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000194int ViERTP_RTCPImpl::GetRemoteSSRC(const int video_channel,
195 unsigned int& SSRC) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000196 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
197 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000198 "%s(channel: %d)", __FUNCTION__, video_channel, SSRC);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000199 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000200 ViEChannel* vie_channel = cs.Channel(video_channel);
201 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000202 WEBRTC_TRACE(kTraceError, kTraceVideo,
203 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000204 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000205 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000206 return -1;
207 }
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000208 if (vie_channel->GetRemoteSSRC(&SSRC) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000209 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000210 return -1;
211 }
212 return 0;
213}
214
215int ViERTP_RTCPImpl::GetRemoteCSRCs(const int video_channel,
216 unsigned int CSRCs[kRtpCsrcSize]) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000217 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
218 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000219 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000220 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000221 ViEChannel* vie_channel = cs.Channel(video_channel);
222 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000223 WEBRTC_TRACE(kTraceError, kTraceVideo,
224 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000225 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000226 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000227 return -1;
228 }
229 if (vie_channel->GetRemoteCSRC(CSRCs) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000230 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000231 return -1;
232 }
233 return 0;
234}
235
236int ViERTP_RTCPImpl::SetStartSequenceNumber(const int video_channel,
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000237 uint16_t sequence_number) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000238 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
239 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000240 "%s(channel: %d, sequence_number: %u)", __FUNCTION__,
241 video_channel, sequence_number);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000242 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000243 ViEChannel* vie_channel = cs.Channel(video_channel);
244 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000245 WEBRTC_TRACE(kTraceError, kTraceVideo,
246 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000247 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000248 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000249 return -1;
250 }
251 if (vie_channel->Sending()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000252 WEBRTC_TRACE(kTraceError, kTraceVideo,
253 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000254 "%s: Channel %d already sending.", __FUNCTION__,
255 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000256 shared_data_->SetLastError(kViERtpRtcpAlreadySending);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000257 return -1;
258 }
259 if (vie_channel->SetStartSequenceNumber(sequence_number) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000260 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000261 return -1;
262 }
263 return 0;
264}
265
266int ViERTP_RTCPImpl::SetRTCPStatus(const int video_channel,
267 const ViERTCPMode rtcp_mode) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000268 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
269 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000270 "%s(channel: %d, mode: %d)", __FUNCTION__, video_channel,
271 rtcp_mode);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000272 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000273 ViEChannel* vie_channel = cs.Channel(video_channel);
274 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000275 WEBRTC_TRACE(kTraceError, kTraceVideo,
276 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000277 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000278 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
stefan@webrtc.orgd0bdab02011-10-14 14:24:54 +0000279 return -1;
280 }
281
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000282 RTCPMethod module_mode = ViERTCPModeToRTCPMethod(rtcp_mode);
283 if (vie_channel->SetRTCPMode(module_mode) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000284 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000285 return -1;
286 }
287 return 0;
288}
289
290int ViERTP_RTCPImpl::GetRTCPStatus(const int video_channel,
291 ViERTCPMode& rtcp_mode) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000292 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
293 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000294 "%s(channel: %d)", __FUNCTION__, video_channel, rtcp_mode);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000295 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000296 ViEChannel* vie_channel = cs.Channel(video_channel);
297 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000298 WEBRTC_TRACE(kTraceError, kTraceVideo,
299 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000300 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000301 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000302 return -1;
303 }
304 RTCPMethod module_mode = kRtcpOff;
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000305 if (vie_channel->GetRTCPMode(&module_mode) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000306 WEBRTC_TRACE(kTraceError, kTraceVideo,
307 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000308 "%s: could not get current RTCP mode", __FUNCTION__);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000309 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000310 return -1;
311 }
312 rtcp_mode = RTCPMethodToViERTCPMode(module_mode);
313 return 0;
314}
315
316int ViERTP_RTCPImpl::SetRTCPCName(const int video_channel,
317 const char rtcp_cname[KMaxRTCPCNameLength]) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000318 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
319 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000320 "%s(channel: %d, name: %s)", __FUNCTION__, video_channel,
321 rtcp_cname);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000322 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000323 ViEChannel* vie_channel = cs.Channel(video_channel);
324 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000325 WEBRTC_TRACE(kTraceError, kTraceVideo,
326 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000327 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000328 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000329 return -1;
330 }
331 if (vie_channel->Sending()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000332 WEBRTC_TRACE(kTraceError, kTraceVideo,
333 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000334 "%s: Channel %d already sending.", __FUNCTION__,
335 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000336 shared_data_->SetLastError(kViERtpRtcpAlreadySending);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000337 return -1;
338 }
339 if (vie_channel->SetRTCPCName(rtcp_cname) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000340 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000341 return -1;
342 }
343 return 0;
344}
345
346int ViERTP_RTCPImpl::GetRTCPCName(const int video_channel,
347 char rtcp_cname[KMaxRTCPCNameLength]) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000348 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
349 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000350 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000351 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000352 ViEChannel* vie_channel = cs.Channel(video_channel);
353 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000354 WEBRTC_TRACE(kTraceError, kTraceVideo,
355 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000356 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000357 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000358 return -1;
359 }
360 if (vie_channel->GetRTCPCName(rtcp_cname) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000361 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000362 return -1;
363 }
364 return 0;
365}
366
367int ViERTP_RTCPImpl::GetRemoteRTCPCName(
368 const int video_channel,
369 char rtcp_cname[KMaxRTCPCNameLength]) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000370 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
371 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000372 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000373 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000374 ViEChannel* vie_channel = cs.Channel(video_channel);
375 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000376 WEBRTC_TRACE(kTraceError, kTraceVideo,
377 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000378 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000379 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000380 return -1;
381 }
382 if (vie_channel->GetRemoteRTCPCName(rtcp_cname) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000383 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000384 return -1;
385 }
386 return 0;
387}
388
389int ViERTP_RTCPImpl::SendApplicationDefinedRTCPPacket(
390 const int video_channel,
391 const unsigned char sub_type,
392 unsigned int name,
393 const char* data,
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000394 uint16_t data_length_in_bytes) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000395 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
396 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000397 "%s(channel: %d, sub_type: %c, name: %d, data: x, length: %u)",
398 __FUNCTION__, video_channel, sub_type, name,
399 data_length_in_bytes);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000400 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000401 ViEChannel* vie_channel = cs.Channel(video_channel);
402 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000403 WEBRTC_TRACE(kTraceError, kTraceVideo,
404 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000405 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000406 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000407 return -1;
408 }
409 if (!vie_channel->Sending()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000410 WEBRTC_TRACE(kTraceError, kTraceVideo,
411 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000412 "%s: Channel %d not sending", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000413 shared_data_->SetLastError(kViERtpRtcpNotSending);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000414 return -1;
415 }
416 RTCPMethod method;
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000417 if (vie_channel->GetRTCPMode(&method) != 0 || method == kRtcpOff) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000418 WEBRTC_TRACE(kTraceError, kTraceVideo,
419 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000420 "%s: RTCP disabled on channel %d.", __FUNCTION__,
421 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000422 shared_data_->SetLastError(kViERtpRtcpRtcpDisabled);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000423 return -1;
424 }
425 if (vie_channel->SendApplicationDefinedRTCPPacket(
426 sub_type, name, reinterpret_cast<const WebRtc_UWord8*>(data),
427 data_length_in_bytes) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000428 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000429 return -1;
430 }
431 return 0;
432}
433
434int ViERTP_RTCPImpl::SetNACKStatus(const int video_channel, const bool enable) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000435 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
436 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000437 "%s(channel: %d, enable: %d)", __FUNCTION__, video_channel,
438 enable);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000439 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000440 ViEChannel* vie_channel = cs.Channel(video_channel);
441 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000442 WEBRTC_TRACE(kTraceError, kTraceVideo,
443 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000444 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000445 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000446 return -1;
447 }
448 if (vie_channel->SetNACKStatus(enable) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000449 WEBRTC_TRACE(kTraceError, kTraceVideo,
450 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000451 "%s: failed for channel %d", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000452 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000453 return -1;
454 }
455
456 // Update the encoder
457 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
458 if (!vie_encoder) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000459 WEBRTC_TRACE(kTraceError, kTraceVideo,
460 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000461 "%s: Could not get encoder for channel %d", __FUNCTION__,
462 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000463 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000464 return -1;
465 }
466 vie_encoder->UpdateProtectionMethod();
467 return 0;
468}
469
470int ViERTP_RTCPImpl::SetFECStatus(const int video_channel, const bool enable,
471 const unsigned char payload_typeRED,
472 const unsigned char payload_typeFEC) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000473 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
474 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000475 "%s(channel: %d, enable: %d, payload_typeRED: %u, "
476 "payloadTypeFEC: %u)",
477 __FUNCTION__, video_channel, enable, payload_typeRED,
478 payload_typeFEC);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000479 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000480 ViEChannel* vie_channel = cs.Channel(video_channel);
481 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000482 WEBRTC_TRACE(kTraceError, kTraceVideo,
483 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000484 "%s: Channel %d doesn't exist", __FUNCTION__,
485 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000486 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000487 return -1;
488 }
489 if (vie_channel->SetFECStatus(enable, payload_typeRED,
490 payload_typeFEC) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000491 WEBRTC_TRACE(kTraceError, kTraceVideo,
492 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000493 "%s: failed for channel %d", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000494 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000495 return -1;
496 }
497 // Update the encoder.
498 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
499 if (!vie_encoder) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000500 WEBRTC_TRACE(kTraceError, kTraceVideo,
501 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000502 "%s: Could not get encoder for channel %d", __FUNCTION__,
503 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000504 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000505 return -1;
506 }
507 vie_encoder->UpdateProtectionMethod();
508 return 0;
509}
510
511int ViERTP_RTCPImpl::SetHybridNACKFECStatus(
512 const int video_channel,
513 const bool enable,
514 const unsigned char payload_typeRED,
515 const unsigned char payload_typeFEC) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000516 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
517 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000518 "%s(channel: %d, enable: %d, payload_typeRED: %u, "
519 "payloadTypeFEC: %u)",
520 __FUNCTION__, video_channel, enable, payload_typeRED,
521 payload_typeFEC);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000522 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000523 ViEChannel* vie_channel = cs.Channel(video_channel);
524 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000525 WEBRTC_TRACE(kTraceError, kTraceVideo,
526 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000527 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000528 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000529 return -1;
530 }
531
532 // Update the channel status with hybrid NACK FEC mode.
533 if (vie_channel->SetHybridNACKFECStatus(enable, payload_typeRED,
534 payload_typeFEC) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000535 WEBRTC_TRACE(kTraceError, kTraceVideo,
536 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000537 "%s: failed for channel %d", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000538 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000539 return -1;
540 }
541
542 // Update the encoder.
543 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
544 if (!vie_encoder) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000545 WEBRTC_TRACE(kTraceError, kTraceVideo,
546 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000547 "%s: Could not get encoder for channel %d", __FUNCTION__,
548 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000549 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000550 return -1;
551 }
552 vie_encoder->UpdateProtectionMethod();
553 return 0;
554}
555
mikhal@webrtc.orgdbe97d22013-02-01 19:33:21 +0000556int ViERTP_RTCPImpl::EnableSenderStreamingMode(int video_channel,
557 int target_delay_ms) {
558 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
559 ViEId(shared_data_->instance_id(), video_channel),
560 "%s(channel: %d, target_delay: %d)",
561 __FUNCTION__, video_channel, target_delay_ms);
562 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
563 ViEChannel* vie_channel = cs.Channel(video_channel);
564 if (!vie_channel) {
565 WEBRTC_TRACE(kTraceError, kTraceVideo,
566 ViEId(shared_data_->instance_id(), video_channel),
567 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
568 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
569 return -1;
570 }
571
572 // Update the channel's streaming mode settings.
573 if (vie_channel->EnableSenderStreamingMode(target_delay_ms) != 0) {
574 WEBRTC_TRACE(kTraceError, kTraceVideo,
575 ViEId(shared_data_->instance_id(), video_channel),
576 "%s: failed for channel %d", __FUNCTION__, video_channel);
577 shared_data_->SetLastError(kViERtpRtcpUnknownError);
578 return -1;
579 }
580 return 0;
581}
582
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000583int ViERTP_RTCPImpl::SetKeyFrameRequestMethod(
584 const int video_channel,
585 const ViEKeyFrameRequestMethod method) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000586 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
587 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000588 "%s(channel: %d, method: %d)", __FUNCTION__, video_channel,
589 method);
590
591 // Get the channel.
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000592 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000593 ViEChannel* vie_channel = cs.Channel(video_channel);
594 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000595 WEBRTC_TRACE(kTraceError, kTraceVideo,
596 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000597 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000598 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000599 return -1;
600 }
601 KeyFrameRequestMethod module_method = APIRequestToModuleRequest(method);
602 if (vie_channel->SetKeyFrameRequestMethod(module_method) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000603 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000604 return -1;
605 }
606 return 0;
607}
608
609int ViERTP_RTCPImpl::SetTMMBRStatus(const int video_channel,
610 const bool enable) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000611 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
612 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000613 "%s(channel: %d, enable: %d)", __FUNCTION__, video_channel,
614 enable);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000615 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000616 ViEChannel* vie_channel = cs.Channel(video_channel);
617 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000618 WEBRTC_TRACE(kTraceError, kTraceVideo,
619 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000620 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000621 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000622 return -1;
623 }
624 if (vie_channel->EnableTMMBR(enable) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000625 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000626 return -1;
627 }
628 return 0;
629}
630
mflodman@webrtc.org6cf529d2012-01-24 06:16:16 +0000631int ViERTP_RTCPImpl::SetRembStatus(int video_channel, bool sender,
mflodman@webrtc.org84dc3d12011-12-22 10:26:13 +0000632 bool receiver) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000633 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
634 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org84dc3d12011-12-22 10:26:13 +0000635 "ViERTP_RTCPImpl::SetRembStatus(%d, %d, %d)", video_channel,
636 sender, receiver);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000637 if (!shared_data_->channel_manager()->SetRembStatus(video_channel, sender,
638 receiver)) {
mflodman@webrtc.org6cf529d2012-01-24 06:16:16 +0000639 return -1;
640 }
641 return 0;
mflodman@webrtc.org84dc3d12011-12-22 10:26:13 +0000642}
643
stefan@webrtc.org976a7e62012-09-21 13:20:21 +0000644int ViERTP_RTCPImpl::SetBandwidthEstimationMode(BandwidthEstimationMode mode) {
645 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_->instance_id(),
646 "ViERTP_RTCPImpl::SetBandwidthEstimationMode(%d)", mode);
647 if (!shared_data_->channel_manager()->SetBandwidthEstimationMode(mode)) {
648 return -1;
649 }
650 return 0;
651}
652
mflodman@webrtc.org90071dd2012-08-13 17:13:27 +0000653int ViERTP_RTCPImpl::SetSendTimestampOffsetStatus(int video_channel,
654 bool enable,
655 int id) {
656 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
657 ViEId(shared_data_->instance_id(), video_channel),
658 "ViERTP_RTCPImpl::SetSendTimestampOffsetStatus(%d, %d, %d)",
659 video_channel, enable, id);
660
661 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
662 ViEChannel* vie_channel = cs.Channel(video_channel);
663 if (!vie_channel) {
664 WEBRTC_TRACE(kTraceError, kTraceVideo,
665 ViEId(shared_data_->instance_id(), video_channel),
666 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
667 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
668 return -1;
669 }
670 if (vie_channel->SetSendTimestampOffsetStatus(enable, id) != 0) {
671 shared_data_->SetLastError(kViERtpRtcpUnknownError);
672 return -1;
673 }
674 return 0;
675}
676
677int ViERTP_RTCPImpl::SetReceiveTimestampOffsetStatus(int video_channel,
678 bool enable,
679 int id) {
680 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
681 ViEId(shared_data_->instance_id(), video_channel),
682 "ViERTP_RTCPImpl::SetReceiveTimestampOffsetStatus(%d, %d, %d)",
683 video_channel, enable, id);
684 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
685 ViEChannel* vie_channel = cs.Channel(video_channel);
686 if (!vie_channel) {
687 WEBRTC_TRACE(kTraceError, kTraceVideo,
688 ViEId(shared_data_->instance_id(), video_channel),
689 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
690 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
691 return -1;
692 }
693 if (vie_channel->SetReceiveTimestampOffsetStatus(enable, id) != 0) {
694 shared_data_->SetLastError(kViERtpRtcpUnknownError);
695 return -1;
696 }
697 return 0;
698}
699
mflodman@webrtc.org5a7507f2012-09-12 13:47:06 +0000700int ViERTP_RTCPImpl::SetTransmissionSmoothingStatus(int video_channel,
701 bool enable) {
702 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
703 ViEId(shared_data_->instance_id(), video_channel),
704 "%s(channel: %d, enble: %d)", __FUNCTION__, video_channel,
705 enable);
706 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
707 ViEChannel* vie_channel = cs.Channel(video_channel);
708 if (!vie_channel) {
709 WEBRTC_TRACE(kTraceError, kTraceVideo,
710 ViEId(shared_data_->instance_id(), video_channel),
711 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
712 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
713 return -1;
714 }
715 vie_channel->SetTransmissionSmoothingStatus(enable);
716 return 0;
717}
718
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000719int ViERTP_RTCPImpl::GetReceivedRTCPStatistics(const int video_channel,
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000720 uint16_t& fraction_lost,
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000721 unsigned int& cumulative_lost,
722 unsigned int& extended_max,
723 unsigned int& jitter,
724 int& rtt_ms) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000725 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
726 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000727 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000728 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000729 ViEChannel* vie_channel = cs.Channel(video_channel);
730 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000731 WEBRTC_TRACE(kTraceError, kTraceVideo,
732 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000733 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000734 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000735 return -1;
736 }
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000737 if (vie_channel->GetReceivedRtcpStatistics(&fraction_lost,
738 &cumulative_lost,
739 &extended_max,
740 &jitter,
741 &rtt_ms) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000742 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000743 return -1;
744 }
745 return 0;
746}
747
748int ViERTP_RTCPImpl::GetSentRTCPStatistics(const int video_channel,
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000749 uint16_t& fraction_lost,
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000750 unsigned int& cumulative_lost,
751 unsigned int& extended_max,
752 unsigned int& jitter,
753 int& rtt_ms) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000754 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
755 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000756 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000757 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000758 ViEChannel* vie_channel = cs.Channel(video_channel);
759 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000760 WEBRTC_TRACE(kTraceError, kTraceVideo,
761 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000762 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000763 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000764 return -1;
765 }
766
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000767 if (vie_channel->GetSendRtcpStatistics(&fraction_lost, &cumulative_lost,
768 &extended_max, &jitter,
769 &rtt_ms) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000770 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000771 return -1;
772 }
773 return 0;
774}
775
776int ViERTP_RTCPImpl::GetRTPStatistics(const int video_channel,
777 unsigned int& bytes_sent,
778 unsigned int& packets_sent,
779 unsigned int& bytes_received,
780 unsigned int& packets_received) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000781 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
782 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000783 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000784 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000785 ViEChannel* vie_channel = cs.Channel(video_channel);
786 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000787 WEBRTC_TRACE(kTraceError, kTraceVideo,
788 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000789 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000790 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000791 return -1;
792 }
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000793 if (vie_channel->GetRtpStatistics(&bytes_sent,
794 &packets_sent,
795 &bytes_received,
796 &packets_received) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000797 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000798 return -1;
799 }
800 return 0;
801}
802
803int ViERTP_RTCPImpl::GetBandwidthUsage(const int video_channel,
804 unsigned int& total_bitrate_sent,
805 unsigned int& video_bitrate_sent,
806 unsigned int& fec_bitrate_sent,
807 unsigned int& nackBitrateSent) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000808 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
809 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000810 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000811 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000812 ViEChannel* vie_channel = cs.Channel(video_channel);
813 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000814 WEBRTC_TRACE(kTraceError, kTraceVideo,
815 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000816 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000817 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000818 return -1;
819 }
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000820 vie_channel->GetBandwidthUsage(&total_bitrate_sent,
821 &video_bitrate_sent,
822 &fec_bitrate_sent,
823 &nackBitrateSent);
stefan@webrtc.orgd0bdab02011-10-14 14:24:54 +0000824 return 0;
825}
826
stefan@webrtc.org439be292012-02-16 14:45:37 +0000827int ViERTP_RTCPImpl::GetEstimatedSendBandwidth(
stefan@webrtc.org07b45a52012-02-02 08:37:48 +0000828 const int video_channel,
829 unsigned int* estimated_bandwidth) const {
830 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
831 ViEId(shared_data_->instance_id(), video_channel),
832 "%s(channel: %d)", __FUNCTION__, video_channel);
833 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
834 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
835 if (!vie_encoder) {
836 WEBRTC_TRACE(kTraceError, kTraceVideo,
837 ViEId(shared_data_->instance_id(), video_channel),
838 "%s: Could not get encoder for channel %d", __FUNCTION__,
839 video_channel);
840 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
841 return -1;
842 }
stefan@webrtc.org439be292012-02-16 14:45:37 +0000843 return vie_encoder->EstimatedSendBandwidth(
844 static_cast<WebRtc_UWord32*>(estimated_bandwidth));
845}
846
847int ViERTP_RTCPImpl::GetEstimatedReceiveBandwidth(
848 const int video_channel,
849 unsigned int* estimated_bandwidth) const {
850 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
851 ViEId(shared_data_->instance_id(), video_channel),
852 "%s(channel: %d)", __FUNCTION__, video_channel);
853 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
854 ViEChannel* vie_channel = cs.Channel(video_channel);
855 if (!vie_channel) {
856 WEBRTC_TRACE(kTraceError, kTraceVideo,
857 ViEId(shared_data_->instance_id(), video_channel),
858 "%s: Could not get channel %d", __FUNCTION__,
859 video_channel);
860 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
861 return -1;
862 }
mflodman@webrtc.org4fd55272013-02-06 17:46:39 +0000863 vie_channel->GetEstimatedReceiveBandwidth(
stefan@webrtc.org07b45a52012-02-02 08:37:48 +0000864 static_cast<WebRtc_UWord32*>(estimated_bandwidth));
mflodman@webrtc.org4fd55272013-02-06 17:46:39 +0000865 return 0;
stefan@webrtc.org07b45a52012-02-02 08:37:48 +0000866}
867
astor@webrtc.orgc0496e62012-08-10 10:14:43 +0000868int ViERTP_RTCPImpl::SetOverUseDetectorOptions(
869 const OverUseDetectorOptions& options) const {
870 if (!shared_data_->Initialized()) {
871 shared_data_->SetLastError(kViENotInitialized);
872 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
873 "%s - ViE instance %d not initialized", __FUNCTION__,
874 shared_data_->instance_id());
875 return -1;
876 }
877 // Lock the channel manager to avoid creating a channel with
878 // "undefined" bwe settings (atomic copy).
879 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
880 shared_data_->SetOverUseDetectorOptions(options);
881 return 0;
882}
883
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000884int ViERTP_RTCPImpl::StartRTPDump(const int video_channel,
885 const char file_nameUTF8[1024],
886 RTPDirections direction) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000887 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
888 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000889 "%s(channel: %d, file_name: %s, direction: %d)", __FUNCTION__,
890 video_channel, file_nameUTF8, direction);
891 assert(FileWrapper::kMaxFileNameSize == 1024);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000892 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000893 ViEChannel* vie_channel = cs.Channel(video_channel);
894 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000895 WEBRTC_TRACE(kTraceError, kTraceVideo,
896 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000897 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000898 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000899 return -1;
900 }
901 if (vie_channel->StartRTPDump(file_nameUTF8, direction) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000902 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000903 return -1;
904 }
905 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000906}
907
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000908int ViERTP_RTCPImpl::StopRTPDump(const int video_channel,
909 RTPDirections direction) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000910 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
911 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000912 "%s(channel: %d, direction: %d)", __FUNCTION__, video_channel,
913 direction);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000914 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000915 ViEChannel* vie_channel = cs.Channel(video_channel);
916 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000917 WEBRTC_TRACE(kTraceError, kTraceVideo,
918 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000919 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000920 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000921 return -1;
922 }
923 if (vie_channel->StopRTPDump(direction) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000924 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000925 return -1;
926 }
927 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000928}
929
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000930int ViERTP_RTCPImpl::RegisterRTPObserver(const int video_channel,
931 ViERTPObserver& observer) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000932 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
933 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000934 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000935 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000936 ViEChannel* vie_channel = cs.Channel(video_channel);
937 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000938 WEBRTC_TRACE(kTraceError, kTraceVideo,
939 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000940 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000941 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000942 return -1;
943 }
944 if (vie_channel->RegisterRtpObserver(&observer) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000945 shared_data_->SetLastError(kViERtpRtcpObserverAlreadyRegistered);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000946 return -1;
947 }
948 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000949}
950
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000951int ViERTP_RTCPImpl::DeregisterRTPObserver(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000952 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
953 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000954 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000955 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000956 ViEChannel* vie_channel = cs.Channel(video_channel);
957 if (!vie_channel) {
958 WEBRTC_TRACE(kTraceError, kTraceVideo,
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000959 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000960 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000961 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000962 return -1;
963 }
964 if (vie_channel->RegisterRtpObserver(NULL) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000965 shared_data_->SetLastError(kViERtpRtcpObserverNotRegistered);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000966 return -1;
967 }
968 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000969}
970
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000971int ViERTP_RTCPImpl::RegisterRTCPObserver(const int video_channel,
972 ViERTCPObserver& observer) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000973 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
974 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000975 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000976 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000977 ViEChannel* vie_channel = cs.Channel(video_channel);
978 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000979 WEBRTC_TRACE(kTraceError, kTraceVideo,
980 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000981 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000982 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000983 return -1;
984 }
985 if (vie_channel->RegisterRtcpObserver(&observer) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000986 shared_data_->SetLastError(kViERtpRtcpObserverAlreadyRegistered);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000987 return -1;
988 }
989 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000990}
991
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000992int ViERTP_RTCPImpl::DeregisterRTCPObserver(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000993 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
994 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000995 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000996 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000997 ViEChannel* vie_channel = cs.Channel(video_channel);
998 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000999 WEBRTC_TRACE(kTraceError, kTraceVideo,
1000 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001001 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001002 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001003 return -1;
1004 }
1005 if (vie_channel->RegisterRtcpObserver(NULL) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001006 shared_data_->SetLastError(kViERtpRtcpObserverNotRegistered);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001007 return -1;
1008 }
1009 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001010}
1011
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001012} // namespace webrtc