blob: 134c9541d4918f32a816a965794c5c4c104aeda5 [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
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000011#include "webrtc/video_engine/vie_rtp_rtcp_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000013#include "webrtc/engine_configurations.h"
14#include "webrtc/system_wrappers/interface/file_wrapper.h"
15#include "webrtc/system_wrappers/interface/trace.h"
16#include "webrtc/video_engine/include/vie_errors.h"
17#include "webrtc/video_engine/vie_channel.h"
18#include "webrtc/video_engine/vie_channel_manager.h"
19#include "webrtc/video_engine/vie_defines.h"
20#include "webrtc/video_engine/vie_encoder.h"
21#include "webrtc/video_engine/vie_impl.h"
22#include "webrtc/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 }
andrew@webrtc.orgd72262d2013-05-09 02:12:07 +000082 VideoEngineImpl* vie_impl = static_cast<VideoEngineImpl*>(video_engine);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000083 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
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000098 int32_t ref_count = GetCount();
mflodman@webrtc.org8da24172011-12-19 14:18:41 +000099 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
mflodman@webrtc.org9f5ebb52013-04-12 14:55:46 +0000236int ViERTP_RTCPImpl::SetRtxSendPayloadType(const int video_channel,
237 const uint8_t payload_type) {
238 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
239 ViEId(shared_data_->instance_id(), video_channel),
240 "%s(channel: %d)", __FUNCTION__, video_channel);
241 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
242 ViEChannel* vie_channel = cs.Channel(video_channel);
243 if (!vie_channel) {
244 WEBRTC_TRACE(kTraceError, kTraceVideo,
245 ViEId(shared_data_->instance_id(), video_channel),
246 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
247 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
248 return -1;
249 }
250 if (!vie_channel->SetRtxSendPayloadType(payload_type)) {
251 return -1;
252 }
253 return 0;
254}
255
256int ViERTP_RTCPImpl::SetRtxReceivePayloadType(const int video_channel,
257 const uint8_t payload_type) {
258 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
259 ViEId(shared_data_->instance_id(), video_channel),
260 "%s(channel: %d)", __FUNCTION__, video_channel);
261 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
262 ViEChannel* vie_channel = cs.Channel(video_channel);
263 if (!vie_channel) {
264 WEBRTC_TRACE(kTraceError, kTraceVideo,
265 ViEId(shared_data_->instance_id(), video_channel),
266 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
267 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
268 return -1;
269 }
270 vie_channel->SetRtxReceivePayloadType(payload_type);
271 return 0;
272}
273
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000274int ViERTP_RTCPImpl::SetStartSequenceNumber(const int video_channel,
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000275 uint16_t sequence_number) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000276 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
277 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000278 "%s(channel: %d, sequence_number: %u)", __FUNCTION__,
279 video_channel, sequence_number);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000280 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000281 ViEChannel* vie_channel = cs.Channel(video_channel);
282 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000283 WEBRTC_TRACE(kTraceError, kTraceVideo,
284 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000285 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000286 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000287 return -1;
288 }
289 if (vie_channel->Sending()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000290 WEBRTC_TRACE(kTraceError, kTraceVideo,
291 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000292 "%s: Channel %d already sending.", __FUNCTION__,
293 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000294 shared_data_->SetLastError(kViERtpRtcpAlreadySending);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000295 return -1;
296 }
297 if (vie_channel->SetStartSequenceNumber(sequence_number) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000298 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000299 return -1;
300 }
301 return 0;
302}
303
304int ViERTP_RTCPImpl::SetRTCPStatus(const int video_channel,
305 const ViERTCPMode rtcp_mode) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000306 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
307 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000308 "%s(channel: %d, mode: %d)", __FUNCTION__, video_channel,
309 rtcp_mode);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000310 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000311 ViEChannel* vie_channel = cs.Channel(video_channel);
312 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000313 WEBRTC_TRACE(kTraceError, kTraceVideo,
314 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000315 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000316 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
stefan@webrtc.orgd0bdab02011-10-14 14:24:54 +0000317 return -1;
318 }
319
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000320 RTCPMethod module_mode = ViERTCPModeToRTCPMethod(rtcp_mode);
321 if (vie_channel->SetRTCPMode(module_mode) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000322 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000323 return -1;
324 }
325 return 0;
326}
327
328int ViERTP_RTCPImpl::GetRTCPStatus(const int video_channel,
329 ViERTCPMode& rtcp_mode) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000330 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
331 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000332 "%s(channel: %d)", __FUNCTION__, video_channel, rtcp_mode);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000333 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000334 ViEChannel* vie_channel = cs.Channel(video_channel);
335 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000336 WEBRTC_TRACE(kTraceError, kTraceVideo,
337 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000338 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000339 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000340 return -1;
341 }
342 RTCPMethod module_mode = kRtcpOff;
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000343 if (vie_channel->GetRTCPMode(&module_mode) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000344 WEBRTC_TRACE(kTraceError, kTraceVideo,
345 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000346 "%s: could not get current RTCP mode", __FUNCTION__);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000347 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000348 return -1;
349 }
350 rtcp_mode = RTCPMethodToViERTCPMode(module_mode);
351 return 0;
352}
353
354int ViERTP_RTCPImpl::SetRTCPCName(const int video_channel,
355 const char rtcp_cname[KMaxRTCPCNameLength]) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000356 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
357 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000358 "%s(channel: %d, name: %s)", __FUNCTION__, video_channel,
359 rtcp_cname);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000360 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000361 ViEChannel* vie_channel = cs.Channel(video_channel);
362 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000363 WEBRTC_TRACE(kTraceError, kTraceVideo,
364 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000365 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000366 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000367 return -1;
368 }
369 if (vie_channel->Sending()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000370 WEBRTC_TRACE(kTraceError, kTraceVideo,
371 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000372 "%s: Channel %d already sending.", __FUNCTION__,
373 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000374 shared_data_->SetLastError(kViERtpRtcpAlreadySending);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000375 return -1;
376 }
377 if (vie_channel->SetRTCPCName(rtcp_cname) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000378 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000379 return -1;
380 }
381 return 0;
382}
383
384int ViERTP_RTCPImpl::GetRTCPCName(const int video_channel,
385 char rtcp_cname[KMaxRTCPCNameLength]) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000386 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
387 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000388 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000389 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000390 ViEChannel* vie_channel = cs.Channel(video_channel);
391 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000392 WEBRTC_TRACE(kTraceError, kTraceVideo,
393 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000394 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000395 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000396 return -1;
397 }
398 if (vie_channel->GetRTCPCName(rtcp_cname) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000399 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000400 return -1;
401 }
402 return 0;
403}
404
405int ViERTP_RTCPImpl::GetRemoteRTCPCName(
406 const int video_channel,
407 char rtcp_cname[KMaxRTCPCNameLength]) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000408 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
409 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000410 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000411 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000412 ViEChannel* vie_channel = cs.Channel(video_channel);
413 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000414 WEBRTC_TRACE(kTraceError, kTraceVideo,
415 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000416 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000417 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000418 return -1;
419 }
420 if (vie_channel->GetRemoteRTCPCName(rtcp_cname) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000421 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000422 return -1;
423 }
424 return 0;
425}
426
427int ViERTP_RTCPImpl::SendApplicationDefinedRTCPPacket(
428 const int video_channel,
429 const unsigned char sub_type,
430 unsigned int name,
431 const char* data,
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000432 uint16_t data_length_in_bytes) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000433 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
434 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000435 "%s(channel: %d, sub_type: %c, name: %d, data: x, length: %u)",
436 __FUNCTION__, video_channel, sub_type, name,
437 data_length_in_bytes);
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->Sending()) {
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: Channel %d not sending", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000451 shared_data_->SetLastError(kViERtpRtcpNotSending);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000452 return -1;
453 }
454 RTCPMethod method;
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000455 if (vie_channel->GetRTCPMode(&method) != 0 || method == kRtcpOff) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000456 WEBRTC_TRACE(kTraceError, kTraceVideo,
457 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000458 "%s: RTCP disabled on channel %d.", __FUNCTION__,
459 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000460 shared_data_->SetLastError(kViERtpRtcpRtcpDisabled);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000461 return -1;
462 }
463 if (vie_channel->SendApplicationDefinedRTCPPacket(
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000464 sub_type, name, reinterpret_cast<const uint8_t*>(data),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000465 data_length_in_bytes) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000466 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000467 return -1;
468 }
469 return 0;
470}
471
472int ViERTP_RTCPImpl::SetNACKStatus(const int video_channel, const bool enable) {
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)", __FUNCTION__, video_channel,
476 enable);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000477 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000478 ViEChannel* vie_channel = cs.Channel(video_channel);
479 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000480 WEBRTC_TRACE(kTraceError, kTraceVideo,
481 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000482 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000483 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000484 return -1;
485 }
486 if (vie_channel->SetNACKStatus(enable) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000487 WEBRTC_TRACE(kTraceError, kTraceVideo,
488 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000489 "%s: failed for channel %d", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000490 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000491 return -1;
492 }
493
494 // Update the encoder
495 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
496 if (!vie_encoder) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000497 WEBRTC_TRACE(kTraceError, kTraceVideo,
498 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000499 "%s: Could not get encoder for channel %d", __FUNCTION__,
500 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000501 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000502 return -1;
503 }
504 vie_encoder->UpdateProtectionMethod();
505 return 0;
506}
507
508int ViERTP_RTCPImpl::SetFECStatus(const int video_channel, const bool enable,
509 const unsigned char payload_typeRED,
510 const unsigned char payload_typeFEC) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000511 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
512 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000513 "%s(channel: %d, enable: %d, payload_typeRED: %u, "
514 "payloadTypeFEC: %u)",
515 __FUNCTION__, video_channel, enable, payload_typeRED,
516 payload_typeFEC);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000517 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000518 ViEChannel* vie_channel = cs.Channel(video_channel);
519 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000520 WEBRTC_TRACE(kTraceError, kTraceVideo,
521 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000522 "%s: Channel %d doesn't exist", __FUNCTION__,
523 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000524 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000525 return -1;
526 }
527 if (vie_channel->SetFECStatus(enable, payload_typeRED,
528 payload_typeFEC) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000529 WEBRTC_TRACE(kTraceError, kTraceVideo,
530 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000531 "%s: failed for channel %d", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000532 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000533 return -1;
534 }
535 // Update the encoder.
536 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
537 if (!vie_encoder) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000538 WEBRTC_TRACE(kTraceError, kTraceVideo,
539 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000540 "%s: Could not get encoder for channel %d", __FUNCTION__,
541 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000542 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000543 return -1;
544 }
545 vie_encoder->UpdateProtectionMethod();
546 return 0;
547}
548
549int ViERTP_RTCPImpl::SetHybridNACKFECStatus(
550 const int video_channel,
551 const bool enable,
552 const unsigned char payload_typeRED,
553 const unsigned char payload_typeFEC) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000554 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
555 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000556 "%s(channel: %d, enable: %d, payload_typeRED: %u, "
557 "payloadTypeFEC: %u)",
558 __FUNCTION__, video_channel, enable, payload_typeRED,
559 payload_typeFEC);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000560 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000561 ViEChannel* vie_channel = cs.Channel(video_channel);
562 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000563 WEBRTC_TRACE(kTraceError, kTraceVideo,
564 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000565 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000566 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000567 return -1;
568 }
569
570 // Update the channel status with hybrid NACK FEC mode.
571 if (vie_channel->SetHybridNACKFECStatus(enable, payload_typeRED,
572 payload_typeFEC) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000573 WEBRTC_TRACE(kTraceError, kTraceVideo,
574 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000575 "%s: failed for channel %d", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000576 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000577 return -1;
578 }
579
580 // Update the encoder.
581 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
582 if (!vie_encoder) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000583 WEBRTC_TRACE(kTraceError, kTraceVideo,
584 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000585 "%s: Could not get encoder for channel %d", __FUNCTION__,
586 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000587 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000588 return -1;
589 }
590 vie_encoder->UpdateProtectionMethod();
591 return 0;
592}
593
mikhal@webrtc.orgef9f76a2013-02-15 23:22:18 +0000594int ViERTP_RTCPImpl::SetSenderBufferingMode(int video_channel,
mikhal@webrtc.orgdbe97d22013-02-01 19:33:21 +0000595 int target_delay_ms) {
596 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
597 ViEId(shared_data_->instance_id(), video_channel),
mikhal@webrtc.orgef9f76a2013-02-15 23:22:18 +0000598 "%s(channel: %d, sender target_delay: %d)",
mikhal@webrtc.orgdbe97d22013-02-01 19:33:21 +0000599 __FUNCTION__, video_channel, target_delay_ms);
600 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
601 ViEChannel* vie_channel = cs.Channel(video_channel);
602 if (!vie_channel) {
603 WEBRTC_TRACE(kTraceError, kTraceVideo,
604 ViEId(shared_data_->instance_id(), video_channel),
605 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
606 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
607 return -1;
608 }
mikhal@webrtc.org3d305c62013-02-10 18:42:55 +0000609 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
610 if (!vie_encoder) {
611 WEBRTC_TRACE(kTraceError, kTraceVideo,
612 ViEId(shared_data_->instance_id(), video_channel),
613 "%s: Could not get encoder for channel %d", __FUNCTION__,
614 video_channel);
615 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
616 return -1;
617 }
mikhal@webrtc.orgdbe97d22013-02-01 19:33:21 +0000618
mikhal@webrtc.orgef9f76a2013-02-15 23:22:18 +0000619 // Update the channel with buffering mode settings.
620 if (vie_channel->SetSenderBufferingMode(target_delay_ms) != 0) {
mikhal@webrtc.orgdbe97d22013-02-01 19:33:21 +0000621 WEBRTC_TRACE(kTraceError, kTraceVideo,
622 ViEId(shared_data_->instance_id(), video_channel),
623 "%s: failed for channel %d", __FUNCTION__, video_channel);
624 shared_data_->SetLastError(kViERtpRtcpUnknownError);
625 return -1;
626 }
mikhal@webrtc.org3d305c62013-02-10 18:42:55 +0000627
mikhal@webrtc.orgef9f76a2013-02-15 23:22:18 +0000628 // Update the encoder's buffering mode settings.
629 vie_encoder->SetSenderBufferingMode(target_delay_ms);
630 return 0;
631}
632
633int ViERTP_RTCPImpl::SetReceiverBufferingMode(int video_channel,
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000634 int target_delay_ms) {
mikhal@webrtc.orgef9f76a2013-02-15 23:22:18 +0000635 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
636 ViEId(shared_data_->instance_id(), video_channel),
637 "%s(channel: %d, receiver target_delay: %d)",
638 __FUNCTION__, video_channel, target_delay_ms);
639 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
640 ViEChannel* vie_channel = cs.Channel(video_channel);
641 if (!vie_channel) {
642 WEBRTC_TRACE(kTraceError, kTraceVideo,
643 ViEId(shared_data_->instance_id(), video_channel),
644 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
645 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
646 return -1;
647 }
stefan@webrtc.org8ca8a712013-04-23 16:48:32 +0000648
mikhal@webrtc.orgef9f76a2013-02-15 23:22:18 +0000649 // Update the channel with buffering mode settings.
650 if (vie_channel->SetReceiverBufferingMode(target_delay_ms) != 0) {
651 WEBRTC_TRACE(kTraceError, kTraceVideo,
652 ViEId(shared_data_->instance_id(), video_channel),
653 "%s: failed for channel %d", __FUNCTION__, video_channel);
654 shared_data_->SetLastError(kViERtpRtcpUnknownError);
655 return -1;
656 }
mikhal@webrtc.orgdbe97d22013-02-01 19:33:21 +0000657 return 0;
658}
659
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000660int ViERTP_RTCPImpl::SetKeyFrameRequestMethod(
661 const int video_channel,
662 const ViEKeyFrameRequestMethod method) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000663 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
664 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000665 "%s(channel: %d, method: %d)", __FUNCTION__, video_channel,
666 method);
667
668 // Get the channel.
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000669 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000670 ViEChannel* vie_channel = cs.Channel(video_channel);
671 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000672 WEBRTC_TRACE(kTraceError, kTraceVideo,
673 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000674 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000675 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000676 return -1;
677 }
678 KeyFrameRequestMethod module_method = APIRequestToModuleRequest(method);
679 if (vie_channel->SetKeyFrameRequestMethod(module_method) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000680 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000681 return -1;
682 }
683 return 0;
684}
685
686int ViERTP_RTCPImpl::SetTMMBRStatus(const int video_channel,
687 const bool enable) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000688 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
689 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000690 "%s(channel: %d, enable: %d)", __FUNCTION__, video_channel,
691 enable);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000692 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000693 ViEChannel* vie_channel = cs.Channel(video_channel);
694 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000695 WEBRTC_TRACE(kTraceError, kTraceVideo,
696 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000697 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000698 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000699 return -1;
700 }
701 if (vie_channel->EnableTMMBR(enable) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000702 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000703 return -1;
704 }
705 return 0;
706}
707
mflodman@webrtc.org6cf529d2012-01-24 06:16:16 +0000708int ViERTP_RTCPImpl::SetRembStatus(int video_channel, bool sender,
mflodman@webrtc.org84dc3d12011-12-22 10:26:13 +0000709 bool receiver) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000710 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
711 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org84dc3d12011-12-22 10:26:13 +0000712 "ViERTP_RTCPImpl::SetRembStatus(%d, %d, %d)", video_channel,
713 sender, receiver);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000714 if (!shared_data_->channel_manager()->SetRembStatus(video_channel, sender,
715 receiver)) {
mflodman@webrtc.org6cf529d2012-01-24 06:16:16 +0000716 return -1;
717 }
718 return 0;
mflodman@webrtc.org84dc3d12011-12-22 10:26:13 +0000719}
720
mflodman@webrtc.org90071dd2012-08-13 17:13:27 +0000721int ViERTP_RTCPImpl::SetSendTimestampOffsetStatus(int video_channel,
722 bool enable,
723 int id) {
724 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
725 ViEId(shared_data_->instance_id(), video_channel),
726 "ViERTP_RTCPImpl::SetSendTimestampOffsetStatus(%d, %d, %d)",
727 video_channel, enable, id);
728
729 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
730 ViEChannel* vie_channel = cs.Channel(video_channel);
731 if (!vie_channel) {
732 WEBRTC_TRACE(kTraceError, kTraceVideo,
733 ViEId(shared_data_->instance_id(), video_channel),
734 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
735 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
736 return -1;
737 }
738 if (vie_channel->SetSendTimestampOffsetStatus(enable, id) != 0) {
739 shared_data_->SetLastError(kViERtpRtcpUnknownError);
740 return -1;
741 }
742 return 0;
743}
744
745int ViERTP_RTCPImpl::SetReceiveTimestampOffsetStatus(int video_channel,
746 bool enable,
747 int id) {
748 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
749 ViEId(shared_data_->instance_id(), video_channel),
750 "ViERTP_RTCPImpl::SetReceiveTimestampOffsetStatus(%d, %d, %d)",
751 video_channel, enable, id);
752 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
753 ViEChannel* vie_channel = cs.Channel(video_channel);
754 if (!vie_channel) {
755 WEBRTC_TRACE(kTraceError, kTraceVideo,
756 ViEId(shared_data_->instance_id(), video_channel),
757 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
758 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
759 return -1;
760 }
761 if (vie_channel->SetReceiveTimestampOffsetStatus(enable, id) != 0) {
762 shared_data_->SetLastError(kViERtpRtcpUnknownError);
763 return -1;
764 }
765 return 0;
766}
767
mflodman@webrtc.org5a7507f2012-09-12 13:47:06 +0000768int ViERTP_RTCPImpl::SetTransmissionSmoothingStatus(int video_channel,
769 bool enable) {
770 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
771 ViEId(shared_data_->instance_id(), video_channel),
772 "%s(channel: %d, enble: %d)", __FUNCTION__, video_channel,
773 enable);
774 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
775 ViEChannel* vie_channel = cs.Channel(video_channel);
776 if (!vie_channel) {
777 WEBRTC_TRACE(kTraceError, kTraceVideo,
778 ViEId(shared_data_->instance_id(), video_channel),
779 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
780 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
781 return -1;
782 }
783 vie_channel->SetTransmissionSmoothingStatus(enable);
784 return 0;
785}
786
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000787int ViERTP_RTCPImpl::GetReceivedRTCPStatistics(const int video_channel,
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000788 uint16_t& fraction_lost,
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000789 unsigned int& cumulative_lost,
790 unsigned int& extended_max,
791 unsigned int& jitter,
792 int& rtt_ms) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000793 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
794 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000795 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000796 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000797 ViEChannel* vie_channel = cs.Channel(video_channel);
798 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000799 WEBRTC_TRACE(kTraceError, kTraceVideo,
800 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000801 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000802 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000803 return -1;
804 }
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000805 if (vie_channel->GetReceivedRtcpStatistics(&fraction_lost,
806 &cumulative_lost,
807 &extended_max,
808 &jitter,
809 &rtt_ms) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000810 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000811 return -1;
812 }
813 return 0;
814}
815
816int ViERTP_RTCPImpl::GetSentRTCPStatistics(const int video_channel,
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000817 uint16_t& fraction_lost,
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000818 unsigned int& cumulative_lost,
819 unsigned int& extended_max,
820 unsigned int& jitter,
821 int& rtt_ms) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000822 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
823 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000824 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000825 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000826 ViEChannel* vie_channel = cs.Channel(video_channel);
827 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000828 WEBRTC_TRACE(kTraceError, kTraceVideo,
829 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000830 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000831 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000832 return -1;
833 }
834
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000835 if (vie_channel->GetSendRtcpStatistics(&fraction_lost, &cumulative_lost,
836 &extended_max, &jitter,
837 &rtt_ms) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000838 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000839 return -1;
840 }
841 return 0;
842}
843
844int ViERTP_RTCPImpl::GetRTPStatistics(const int video_channel,
845 unsigned int& bytes_sent,
846 unsigned int& packets_sent,
847 unsigned int& bytes_received,
848 unsigned int& packets_received) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000849 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
850 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000851 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000852 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000853 ViEChannel* vie_channel = cs.Channel(video_channel);
854 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000855 WEBRTC_TRACE(kTraceError, kTraceVideo,
856 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000857 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000858 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000859 return -1;
860 }
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000861 if (vie_channel->GetRtpStatistics(&bytes_sent,
862 &packets_sent,
863 &bytes_received,
864 &packets_received) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000865 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000866 return -1;
867 }
868 return 0;
869}
870
871int ViERTP_RTCPImpl::GetBandwidthUsage(const int video_channel,
872 unsigned int& total_bitrate_sent,
873 unsigned int& video_bitrate_sent,
874 unsigned int& fec_bitrate_sent,
875 unsigned int& nackBitrateSent) const {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000876 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
877 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000878 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000879 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000880 ViEChannel* vie_channel = cs.Channel(video_channel);
881 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000882 WEBRTC_TRACE(kTraceError, kTraceVideo,
883 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000884 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000885 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000886 return -1;
887 }
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000888 vie_channel->GetBandwidthUsage(&total_bitrate_sent,
889 &video_bitrate_sent,
890 &fec_bitrate_sent,
891 &nackBitrateSent);
stefan@webrtc.orgd0bdab02011-10-14 14:24:54 +0000892 return 0;
893}
894
stefan@webrtc.org439be292012-02-16 14:45:37 +0000895int ViERTP_RTCPImpl::GetEstimatedSendBandwidth(
stefan@webrtc.org07b45a52012-02-02 08:37:48 +0000896 const int video_channel,
897 unsigned int* estimated_bandwidth) const {
898 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
899 ViEId(shared_data_->instance_id(), video_channel),
900 "%s(channel: %d)", __FUNCTION__, video_channel);
901 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
902 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
903 if (!vie_encoder) {
904 WEBRTC_TRACE(kTraceError, kTraceVideo,
905 ViEId(shared_data_->instance_id(), video_channel),
906 "%s: Could not get encoder for channel %d", __FUNCTION__,
907 video_channel);
908 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
909 return -1;
910 }
stefan@webrtc.org439be292012-02-16 14:45:37 +0000911 return vie_encoder->EstimatedSendBandwidth(
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000912 static_cast<uint32_t*>(estimated_bandwidth));
stefan@webrtc.org439be292012-02-16 14:45:37 +0000913}
914
915int ViERTP_RTCPImpl::GetEstimatedReceiveBandwidth(
916 const int video_channel,
917 unsigned int* estimated_bandwidth) const {
918 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
919 ViEId(shared_data_->instance_id(), video_channel),
920 "%s(channel: %d)", __FUNCTION__, video_channel);
921 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
922 ViEChannel* vie_channel = cs.Channel(video_channel);
923 if (!vie_channel) {
924 WEBRTC_TRACE(kTraceError, kTraceVideo,
925 ViEId(shared_data_->instance_id(), video_channel),
926 "%s: Could not get channel %d", __FUNCTION__,
927 video_channel);
928 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
929 return -1;
930 }
mflodman@webrtc.org4fd55272013-02-06 17:46:39 +0000931 vie_channel->GetEstimatedReceiveBandwidth(
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000932 static_cast<uint32_t*>(estimated_bandwidth));
mflodman@webrtc.org4fd55272013-02-06 17:46:39 +0000933 return 0;
stefan@webrtc.org07b45a52012-02-02 08:37:48 +0000934}
935
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000936int ViERTP_RTCPImpl::StartRTPDump(const int video_channel,
937 const char file_nameUTF8[1024],
938 RTPDirections direction) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000939 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
940 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000941 "%s(channel: %d, file_name: %s, direction: %d)", __FUNCTION__,
942 video_channel, file_nameUTF8, direction);
943 assert(FileWrapper::kMaxFileNameSize == 1024);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000944 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000945 ViEChannel* vie_channel = cs.Channel(video_channel);
946 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000947 WEBRTC_TRACE(kTraceError, kTraceVideo,
948 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000949 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000950 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000951 return -1;
952 }
953 if (vie_channel->StartRTPDump(file_nameUTF8, direction) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000954 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000955 return -1;
956 }
957 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000958}
959
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000960int ViERTP_RTCPImpl::StopRTPDump(const int video_channel,
961 RTPDirections direction) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000962 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
963 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000964 "%s(channel: %d, direction: %d)", __FUNCTION__, video_channel,
965 direction);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000966 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000967 ViEChannel* vie_channel = cs.Channel(video_channel);
968 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000969 WEBRTC_TRACE(kTraceError, kTraceVideo,
970 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000971 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000972 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000973 return -1;
974 }
975 if (vie_channel->StopRTPDump(direction) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000976 shared_data_->SetLastError(kViERtpRtcpUnknownError);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000977 return -1;
978 }
979 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000980}
981
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000982int ViERTP_RTCPImpl::RegisterRTPObserver(const int video_channel,
983 ViERTPObserver& observer) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000984 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
985 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000986 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000987 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000988 ViEChannel* vie_channel = cs.Channel(video_channel);
989 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000990 WEBRTC_TRACE(kTraceError, kTraceVideo,
991 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000992 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000993 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000994 return -1;
995 }
996 if (vie_channel->RegisterRtpObserver(&observer) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000997 shared_data_->SetLastError(kViERtpRtcpObserverAlreadyRegistered);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +0000998 return -1;
999 }
1000 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001001}
1002
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001003int ViERTP_RTCPImpl::DeregisterRTPObserver(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001004 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
1005 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001006 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001007 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001008 ViEChannel* vie_channel = cs.Channel(video_channel);
1009 if (!vie_channel) {
1010 WEBRTC_TRACE(kTraceError, kTraceVideo,
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001011 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001012 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001013 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001014 return -1;
1015 }
1016 if (vie_channel->RegisterRtpObserver(NULL) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001017 shared_data_->SetLastError(kViERtpRtcpObserverNotRegistered);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001018 return -1;
1019 }
1020 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001021}
1022
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001023int ViERTP_RTCPImpl::RegisterRTCPObserver(const int video_channel,
1024 ViERTCPObserver& observer) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001025 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
1026 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001027 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001028 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001029 ViEChannel* vie_channel = cs.Channel(video_channel);
1030 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001031 WEBRTC_TRACE(kTraceError, kTraceVideo,
1032 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001033 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001034 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001035 return -1;
1036 }
1037 if (vie_channel->RegisterRtcpObserver(&observer) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001038 shared_data_->SetLastError(kViERtpRtcpObserverAlreadyRegistered);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001039 return -1;
1040 }
1041 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001042}
1043
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001044int ViERTP_RTCPImpl::DeregisterRTCPObserver(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001045 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
1046 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001047 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001048 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001049 ViEChannel* vie_channel = cs.Channel(video_channel);
1050 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001051 WEBRTC_TRACE(kTraceError, kTraceVideo,
1052 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001053 "%s: Channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001054 shared_data_->SetLastError(kViERtpRtcpInvalidChannelId);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001055 return -1;
1056 }
1057 if (vie_channel->RegisterRtcpObserver(NULL) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +00001058 shared_data_->SetLastError(kViERtpRtcpObserverNotRegistered);
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001059 return -1;
1060 }
1061 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +00001062}
1063
mflodman@webrtc.org8da24172011-12-19 14:18:41 +00001064} // namespace webrtc