blob: 9323879454fdcaffb578d84f9ab88b0b89631802 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org07c68b92012-02-29 16:09:51 +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
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000011#include "webrtc/video_engine/vie_network_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
pwestin@webrtc.org684f0572013-03-13 23:20:57 +000013#include <stdio.h>
14#if (defined(WIN32_) || defined(WIN64_))
15#include <qos.h>
16#endif
17
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000018#include "webrtc/engine_configurations.h"
19#include "webrtc/system_wrappers/interface/trace.h"
20#include "webrtc/video_engine/include/vie_errors.h"
21#include "webrtc/video_engine/vie_channel.h"
22#include "webrtc/video_engine/vie_channel_manager.h"
23#include "webrtc/video_engine/vie_defines.h"
24#include "webrtc/video_engine/vie_encoder.h"
25#include "webrtc/video_engine/vie_impl.h"
26#include "webrtc/video_engine/vie_shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000027
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000028namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000029
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000030ViENetwork* ViENetwork::GetInterface(VideoEngine* video_engine) {
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000031 if (!video_engine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000032 return NULL;
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000033 }
34 VideoEngineImpl* vie_impl = reinterpret_cast<VideoEngineImpl*>(video_engine);
35 ViENetworkImpl* vie_networkImpl = vie_impl;
36 // Increase ref count.
37 (*vie_networkImpl)++;
38 return vie_networkImpl;
niklase@google.com470e71d2011-07-07 08:21:25 +000039}
40
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000041int ViENetworkImpl::Release() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000042 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000043 "ViENetwork::Release()");
44 // Decrease ref count.
45 (*this)--;
niklase@google.com470e71d2011-07-07 08:21:25 +000046
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000047 int32_t ref_count = GetCount();
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000048 if (ref_count < 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000049 WEBRTC_TRACE(kTraceWarning, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000050 "ViENetwork release too many times");
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000051 shared_data_->SetLastError(kViEAPIDoesNotExist);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000052 return -1;
53 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000054 WEBRTC_TRACE(kTraceInfo, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000055 "ViENetwork reference count: %d", ref_count);
56 return ref_count;
niklase@google.com470e71d2011-07-07 08:21:25 +000057}
58
stefan@webrtc.orgbfacda62013-03-27 16:36:01 +000059void ViENetworkImpl::SetNetworkTransmissionState(const int video_channel,
60 const bool is_transmitting) {
61 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
62 ViEId(shared_data_->instance_id(), video_channel),
63 "%s(event: Network %s)", __FUNCTION__,
64 is_transmitting ? "transmitting" : "not transmitting");
65 if (!shared_data_->Initialized()) {
66 shared_data_->SetLastError(kViENotInitialized);
67 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
68 "%s - ViE instance %d not initialized", __FUNCTION__,
69 shared_data_->instance_id());
70 return;
71 }
72
73 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
74 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
75 if (!vie_encoder) {
76 WEBRTC_TRACE(kTraceError, kTraceVideo,
77 ViEId(shared_data_->instance_id(), video_channel),
78 "An encoder doesn't exist for this channel");
79 shared_data_->SetLastError(kViENetworkInvalidChannelId);
80 return;
81 }
82 vie_encoder->SetNetworkTransmissionState(is_transmitting);
83}
84
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000085ViENetworkImpl::ViENetworkImpl(ViESharedData* shared_data)
86 : shared_data_(shared_data) {
87 WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000088 "ViENetworkImpl::ViENetworkImpl() Ctor");
niklase@google.com470e71d2011-07-07 08:21:25 +000089}
90
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000091ViENetworkImpl::~ViENetworkImpl() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000092 WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000093 "ViENetworkImpl::~ViENetworkImpl() Dtor");
niklase@google.com470e71d2011-07-07 08:21:25 +000094}
95
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000096int ViENetworkImpl::RegisterSendTransport(const int video_channel,
97 Transport& transport) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000098 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
99 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000100 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000101 if (!shared_data_->Initialized()) {
102 shared_data_->SetLastError(kViENotInitialized);
103 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000104 "%s - ViE instance %d not initialized", __FUNCTION__,
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000105 shared_data_->instance_id());
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000106 return -1;
107 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000108 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000109 ViEChannel* vie_channel = cs.Channel(video_channel);
110 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000111 WEBRTC_TRACE(kTraceError, kTraceVideo,
112 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000113 "%s Channel doesn't exist", __FUNCTION__);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000114 shared_data_->SetLastError(kViENetworkInvalidChannelId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000115 return -1;
116 }
117 if (vie_channel->Sending()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000118 WEBRTC_TRACE(kTraceError, kTraceVideo,
119 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000120 "%s Channel already sending.", __FUNCTION__);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000121 shared_data_->SetLastError(kViENetworkAlreadySending);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000122 return -1;
123 }
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000124 if (vie_channel->RegisterSendTransport(&transport) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000125 shared_data_->SetLastError(kViENetworkUnknownError);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000126 return -1;
127 }
128 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000129}
130
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000131int ViENetworkImpl::DeregisterSendTransport(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000132 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
133 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000134 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000135 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000136 ViEChannel* vie_channel = cs.Channel(video_channel);
137 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000138 WEBRTC_TRACE(kTraceError, kTraceVideo,
139 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000140 "%s Channel doesn't exist", __FUNCTION__);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000141 shared_data_->SetLastError(kViENetworkInvalidChannelId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000142 return -1;
143 }
144 if (vie_channel->Sending()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000145 WEBRTC_TRACE(kTraceError, kTraceVideo,
146 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000147 "%s Channel already sending", __FUNCTION__);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000148 shared_data_->SetLastError(kViENetworkAlreadySending);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000149 return -1;
150 }
151 if (vie_channel->DeregisterSendTransport() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000152 shared_data_->SetLastError(kViENetworkUnknownError);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000153 return -1;
154 }
155 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000156}
157
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000158int ViENetworkImpl::ReceivedRTPPacket(const int video_channel, const void* data,
159 const int length) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000160 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
161 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000162 "%s(channel: %d, data: -, length: %d)", __FUNCTION__,
163 video_channel, length);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000164 if (!shared_data_->Initialized()) {
165 shared_data_->SetLastError(kViENotInitialized);
166 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000167 "%s - ViE instance %d not initialized", __FUNCTION__,
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000168 shared_data_->instance_id());
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000169 return -1;
170 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000171 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000172 ViEChannel* vie_channel = cs.Channel(video_channel);
173 if (!vie_channel) {
174 // The channel doesn't exists
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000175 WEBRTC_TRACE(kTraceError, kTraceVideo,
176 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000177 "Channel doesn't exist");
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000178 shared_data_->SetLastError(kViENetworkInvalidChannelId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000179 return -1;
180 }
181 return vie_channel->ReceivedRTPPacket(data, length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000182}
183
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000184int ViENetworkImpl::ReceivedRTCPPacket(const int video_channel,
185 const void* data, const int length) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000186 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
187 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000188 "%s(channel: %d, data: -, length: %d)", __FUNCTION__,
189 video_channel, length);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000190 if (!shared_data_->Initialized()) {
191 shared_data_->SetLastError(kViENotInitialized);
192 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000193 "%s - ViE instance %d not initialized", __FUNCTION__,
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000194 shared_data_->instance_id());
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000195 return -1;
196 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000197 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000198 ViEChannel* vie_channel = cs.Channel(video_channel);
199 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000200 WEBRTC_TRACE(kTraceError, kTraceVideo,
201 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000202 "Channel doesn't exist");
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000203 shared_data_->SetLastError(kViENetworkInvalidChannelId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000204 return -1;
205 }
206 return vie_channel->ReceivedRTCPPacket(data, length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000207}
208
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000209int ViENetworkImpl::SetMTU(int video_channel, unsigned int mtu) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000210 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
211 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000212 "%s(channel: %d, mtu: %u)", __FUNCTION__, video_channel, mtu);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000213 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000214 ViEChannel* vie_channel = cs.Channel(video_channel);
215 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000216 WEBRTC_TRACE(kTraceError, kTraceVideo,
217 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000218 "Channel doesn't exist");
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000219 shared_data_->SetLastError(kViENetworkInvalidChannelId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000220 return -1;
221 }
222 if (vie_channel->SetMTU(mtu) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000223 shared_data_->SetLastError(kViENetworkUnknownError);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000224 return -1;
225 }
226 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000227}
228
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000229int ViENetworkImpl::SetPacketTimeoutNotification(const int video_channel,
niklase@google.com470e71d2011-07-07 08:21:25 +0000230 bool enable,
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000231 int timeout_seconds) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000232 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
233 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000234 "%s(channel: %d, enable: %d, timeout_seconds: %u)",
235 __FUNCTION__, video_channel, enable, timeout_seconds);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000236 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000237 ViEChannel* vie_channel = cs.Channel(video_channel);
238 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000239 WEBRTC_TRACE(kTraceError, kTraceVideo,
240 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000241 "Channel doesn't exist");
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000242 shared_data_->SetLastError(kViENetworkInvalidChannelId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000243 return -1;
244 }
245 if (vie_channel->SetPacketTimeoutNotification(enable,
246 timeout_seconds) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000247 shared_data_->SetLastError(kViENetworkUnknownError);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000248 return -1;
249 }
250 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000251}
252
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000253int ViENetworkImpl::RegisterObserver(const int video_channel,
254 ViENetworkObserver& observer) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000255 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
256 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000257 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000258 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000259 ViEChannel* vie_channel = cs.Channel(video_channel);
260 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000261 WEBRTC_TRACE(kTraceError, kTraceVideo,
262 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000263 "Channel doesn't exist");
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000264 shared_data_->SetLastError(kViENetworkInvalidChannelId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000265 return -1;
266 }
267 if (vie_channel->RegisterNetworkObserver(&observer) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000268 shared_data_->SetLastError(kViENetworkObserverAlreadyRegistered);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000269 return -1;
270 }
271 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000272}
273
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000274int ViENetworkImpl::DeregisterObserver(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000275 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
276 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000277 "%s(channel: %d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000278 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000279 ViEChannel* vie_channel = cs.Channel(video_channel);
280 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000281 WEBRTC_TRACE(kTraceError, kTraceVideo,
282 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000283 "Channel doesn't exist");
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000284 shared_data_->SetLastError(kViENetworkInvalidChannelId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000285 return -1;
286 }
287 if (!vie_channel->NetworkObserverRegistered()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000288 shared_data_->SetLastError(kViENetworkObserverNotRegistered);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000289 return -1;
290 }
291 return vie_channel->RegisterNetworkObserver(NULL);
niklase@google.com470e71d2011-07-07 08:21:25 +0000292}
293
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000294int ViENetworkImpl::SetPeriodicDeadOrAliveStatus(
295 const int video_channel,
296 bool enable,
297 unsigned int sample_time_seconds) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000298 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
299 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000300 "%s(channel: %d, enable: %d, sample_time_seconds: %ul)",
301 __FUNCTION__, video_channel, enable, sample_time_seconds);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000302 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000303 ViEChannel* vie_channel = cs.Channel(video_channel);
304 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000305 WEBRTC_TRACE(kTraceError, kTraceVideo,
306 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000307 "Channel doesn't exist");
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000308 shared_data_->SetLastError(kViENetworkInvalidChannelId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000309 return -1;
310 }
311 if (!vie_channel->NetworkObserverRegistered()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000312 shared_data_->SetLastError(kViENetworkObserverNotRegistered);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000313 return -1;
314 }
315 if (vie_channel->SetPeriodicDeadOrAliveStatus(enable, sample_time_seconds)
316 != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000317 shared_data_->SetLastError(kViENetworkUnknownError);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000318 return -1;
319 }
320 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000321}
322
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000323} // namespace webrtc