niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 07c68b9 | 2012-02-29 16:09:51 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 11 | #include "video_engine/vie_network_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 13 | #include <stdio.h> |
| 14 | #if (defined(WIN32_) || defined(WIN64_)) |
| 15 | #include <qos.h> |
| 16 | #endif |
| 17 | |
mflodman@webrtc.org | 9ba151b | 2012-06-21 10:02:13 +0000 | [diff] [blame] | 18 | #include "engine_configurations.h" // NOLINT |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 19 | #include "system_wrappers/interface/trace.h" |
mflodman@webrtc.org | a4863db | 2011-12-22 08:51:52 +0000 | [diff] [blame] | 20 | #include "video_engine/include/vie_errors.h" |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 21 | #include "video_engine/vie_channel.h" |
| 22 | #include "video_engine/vie_channel_manager.h" |
| 23 | #include "video_engine/vie_defines.h" |
| 24 | #include "video_engine/vie_encoder.h" |
| 25 | #include "video_engine/vie_impl.h" |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 26 | #include "video_engine/vie_shared_data.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 28 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 30 | ViENetwork* ViENetwork::GetInterface(VideoEngine* video_engine) { |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 31 | #ifdef WEBRTC_VIDEO_ENGINE_NETWORK_API |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 32 | if (!video_engine) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | return NULL; |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 34 | } |
| 35 | VideoEngineImpl* vie_impl = reinterpret_cast<VideoEngineImpl*>(video_engine); |
| 36 | ViENetworkImpl* vie_networkImpl = vie_impl; |
| 37 | // Increase ref count. |
| 38 | (*vie_networkImpl)++; |
| 39 | return vie_networkImpl; |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 40 | #else |
| 41 | return NULL; |
| 42 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | } |
| 44 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 45 | int ViENetworkImpl::Release() { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 46 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_->instance_id(), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 47 | "ViENetwork::Release()"); |
| 48 | // Decrease ref count. |
| 49 | (*this)--; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 51 | WebRtc_Word32 ref_count = GetCount(); |
| 52 | if (ref_count < 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 53 | WEBRTC_TRACE(kTraceWarning, kTraceVideo, shared_data_->instance_id(), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 54 | "ViENetwork release too many times"); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 55 | shared_data_->SetLastError(kViEAPIDoesNotExist); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 56 | return -1; |
| 57 | } |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 58 | WEBRTC_TRACE(kTraceInfo, kTraceVideo, shared_data_->instance_id(), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 59 | "ViENetwork reference count: %d", ref_count); |
| 60 | return ref_count; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | } |
| 62 | |
stefan@webrtc.org | bfacda6 | 2013-03-27 16:36:01 +0000 | [diff] [blame^] | 63 | void ViENetworkImpl::SetNetworkTransmissionState(const int video_channel, |
| 64 | const bool is_transmitting) { |
| 65 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 66 | ViEId(shared_data_->instance_id(), video_channel), |
| 67 | "%s(event: Network %s)", __FUNCTION__, |
| 68 | is_transmitting ? "transmitting" : "not transmitting"); |
| 69 | if (!shared_data_->Initialized()) { |
| 70 | shared_data_->SetLastError(kViENotInitialized); |
| 71 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 72 | "%s - ViE instance %d not initialized", __FUNCTION__, |
| 73 | shared_data_->instance_id()); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 78 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 79 | if (!vie_encoder) { |
| 80 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 81 | ViEId(shared_data_->instance_id(), video_channel), |
| 82 | "An encoder doesn't exist for this channel"); |
| 83 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 84 | return; |
| 85 | } |
| 86 | vie_encoder->SetNetworkTransmissionState(is_transmitting); |
| 87 | } |
| 88 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 89 | ViENetworkImpl::ViENetworkImpl(ViESharedData* shared_data) |
| 90 | : shared_data_(shared_data) { |
| 91 | WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 92 | "ViENetworkImpl::ViENetworkImpl() Ctor"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | } |
| 94 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 95 | ViENetworkImpl::~ViENetworkImpl() { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 96 | WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 97 | "ViENetworkImpl::~ViENetworkImpl() Dtor"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | } |
| 99 | |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 100 | int ViENetworkImpl::SetLocalReceiver(const int video_channel, |
| 101 | const uint16_t rtp_port, |
| 102 | const uint16_t rtcp_port, |
| 103 | const char* ip_address) { |
| 104 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 105 | ViEId(shared_data_->instance_id(), video_channel), |
| 106 | "%s(channel: %d, rtp_port: %u, rtcp_port: %u, ip_address: %s)", |
| 107 | __FUNCTION__, video_channel, rtp_port, rtcp_port, ip_address); |
| 108 | if (!shared_data_->Initialized()) { |
| 109 | shared_data_->SetLastError(kViENotInitialized); |
| 110 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 111 | "%s - ViE instance %d not initialized", __FUNCTION__, |
| 112 | shared_data_->instance_id()); |
| 113 | return -1; |
| 114 | } |
| 115 | |
| 116 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 117 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 118 | if (!vie_channel) { |
| 119 | // The channel doesn't exists. |
| 120 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 121 | ViEId(shared_data_->instance_id(), video_channel), |
| 122 | "Channel doesn't exist"); |
| 123 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 124 | return -1; |
| 125 | } |
| 126 | |
| 127 | if (vie_channel->Receiving()) { |
| 128 | shared_data_->SetLastError(kViENetworkAlreadyReceiving); |
| 129 | return -1; |
| 130 | } |
| 131 | if (vie_channel->SetLocalReceiver(rtp_port, rtcp_port, ip_address) != 0) { |
| 132 | shared_data_->SetLastError(kViENetworkUnknownError); |
| 133 | return -1; |
| 134 | } |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | int ViENetworkImpl::GetLocalReceiver(const int video_channel, |
| 139 | uint16_t& rtp_port, |
| 140 | uint16_t& rtcp_port, |
| 141 | char* ip_address) { |
| 142 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 143 | ViEId(shared_data_->instance_id(), video_channel), |
| 144 | "%s(channel: %d)", __FUNCTION__, video_channel); |
| 145 | |
| 146 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 147 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 148 | if (!vie_channel) { |
| 149 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 150 | ViEId(shared_data_->instance_id(), video_channel), |
| 151 | "Channel doesn't exist"); |
| 152 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 153 | return -1; |
| 154 | } |
| 155 | if (vie_channel->GetLocalReceiver(&rtp_port, &rtcp_port, ip_address) != 0) { |
| 156 | shared_data_->SetLastError(kViENetworkLocalReceiverNotSet); |
| 157 | return -1; |
| 158 | } |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | int ViENetworkImpl::SetSendDestination(const int video_channel, |
| 163 | const char* ip_address, |
| 164 | const uint16_t rtp_port, |
| 165 | const uint16_t rtcp_port, |
| 166 | const uint16_t source_rtp_port, |
| 167 | const uint16_t source_rtcp_port) { |
| 168 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 169 | ViEId(shared_data_->instance_id(), video_channel), |
| 170 | "%s(channel: %d, ip_address: %s, rtp_port: %u, rtcp_port: %u, " |
| 171 | "sourceRtpPort: %u, source_rtcp_port: %u)", |
| 172 | __FUNCTION__, video_channel, ip_address, rtp_port, rtcp_port, |
| 173 | source_rtp_port, source_rtcp_port); |
| 174 | if (!shared_data_->Initialized()) { |
| 175 | shared_data_->SetLastError(kViENotInitialized); |
| 176 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 177 | "%s - ViE instance %d not initialized", __FUNCTION__, |
| 178 | shared_data_->instance_id()); |
| 179 | return -1; |
| 180 | } |
| 181 | |
| 182 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 183 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 184 | if (!vie_channel) { |
| 185 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 186 | ViEId(shared_data_->instance_id(), video_channel), |
| 187 | "%s Channel doesn't exist", __FUNCTION__); |
| 188 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 189 | return -1; |
| 190 | } |
| 191 | if (vie_channel->Sending()) { |
| 192 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 193 | ViEId(shared_data_->instance_id(), video_channel), |
| 194 | "%s Channel already sending.", __FUNCTION__); |
| 195 | shared_data_->SetLastError(kViENetworkAlreadySending); |
| 196 | return -1; |
| 197 | } |
| 198 | if (vie_channel->SetSendDestination(ip_address, rtp_port, rtcp_port, |
| 199 | source_rtp_port, |
| 200 | source_rtcp_port) != 0) { |
| 201 | shared_data_->SetLastError(kViENetworkUnknownError); |
| 202 | return -1; |
| 203 | } |
| 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | int ViENetworkImpl::GetSendDestination(const int video_channel, |
| 208 | char* ip_address, |
| 209 | uint16_t& rtp_port, |
| 210 | uint16_t& rtcp_port, |
| 211 | uint16_t& source_rtp_port, |
| 212 | uint16_t& source_rtcp_port) { |
| 213 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 214 | ViEId(shared_data_->instance_id(), video_channel), |
| 215 | "%s(channel: %d)", __FUNCTION__, video_channel); |
| 216 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 217 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 218 | if (!vie_channel) { |
| 219 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 220 | ViEId(shared_data_->instance_id(), video_channel), |
| 221 | "Channel doesn't exist"); |
| 222 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 223 | return -1; |
| 224 | } |
| 225 | if (vie_channel->GetSendDestination(ip_address, &rtp_port, &rtcp_port, |
| 226 | &source_rtp_port, |
| 227 | &source_rtcp_port) != 0) { |
| 228 | shared_data_->SetLastError(kViENetworkDestinationNotSet); |
| 229 | return -1; |
| 230 | } |
| 231 | return 0; |
| 232 | } |
| 233 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 234 | int ViENetworkImpl::RegisterSendTransport(const int video_channel, |
| 235 | Transport& transport) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 236 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 237 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 238 | "%s(channel: %d)", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 239 | if (!shared_data_->Initialized()) { |
| 240 | shared_data_->SetLastError(kViENotInitialized); |
| 241 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 242 | "%s - ViE instance %d not initialized", __FUNCTION__, |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 243 | shared_data_->instance_id()); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 244 | return -1; |
| 245 | } |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 246 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 247 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 248 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 249 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 250 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 251 | "%s Channel doesn't exist", __FUNCTION__); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 252 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 253 | return -1; |
| 254 | } |
| 255 | if (vie_channel->Sending()) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 256 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 257 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 258 | "%s Channel already sending.", __FUNCTION__); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 259 | shared_data_->SetLastError(kViENetworkAlreadySending); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 260 | return -1; |
| 261 | } |
mflodman@webrtc.org | f5e99db | 2012-06-27 09:49:37 +0000 | [diff] [blame] | 262 | if (vie_channel->RegisterSendTransport(&transport) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 263 | shared_data_->SetLastError(kViENetworkUnknownError); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 264 | return -1; |
| 265 | } |
| 266 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 267 | } |
| 268 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 269 | int ViENetworkImpl::DeregisterSendTransport(const int video_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 270 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 271 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 272 | "%s(channel: %d)", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 273 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 274 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 275 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 276 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 277 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 278 | "%s Channel doesn't exist", __FUNCTION__); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 279 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 280 | return -1; |
| 281 | } |
| 282 | if (vie_channel->Sending()) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 283 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 284 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 285 | "%s Channel already sending", __FUNCTION__); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 286 | shared_data_->SetLastError(kViENetworkAlreadySending); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 287 | return -1; |
| 288 | } |
| 289 | if (vie_channel->DeregisterSendTransport() != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 290 | shared_data_->SetLastError(kViENetworkUnknownError); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 291 | return -1; |
| 292 | } |
| 293 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 294 | } |
| 295 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 296 | int ViENetworkImpl::ReceivedRTPPacket(const int video_channel, const void* data, |
| 297 | const int length) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 298 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 299 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 300 | "%s(channel: %d, data: -, length: %d)", __FUNCTION__, |
| 301 | video_channel, length); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 302 | if (!shared_data_->Initialized()) { |
| 303 | shared_data_->SetLastError(kViENotInitialized); |
| 304 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 305 | "%s - ViE instance %d not initialized", __FUNCTION__, |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 306 | shared_data_->instance_id()); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 307 | return -1; |
| 308 | } |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 309 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 310 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 311 | if (!vie_channel) { |
| 312 | // The channel doesn't exists |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 313 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 314 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 315 | "Channel doesn't exist"); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 316 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 317 | return -1; |
| 318 | } |
| 319 | return vie_channel->ReceivedRTPPacket(data, length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 320 | } |
| 321 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 322 | int ViENetworkImpl::ReceivedRTCPPacket(const int video_channel, |
| 323 | const void* data, const int length) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 324 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 325 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 326 | "%s(channel: %d, data: -, length: %d)", __FUNCTION__, |
| 327 | video_channel, length); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 328 | if (!shared_data_->Initialized()) { |
| 329 | shared_data_->SetLastError(kViENotInitialized); |
| 330 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 331 | "%s - ViE instance %d not initialized", __FUNCTION__, |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 332 | shared_data_->instance_id()); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 333 | return -1; |
| 334 | } |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 335 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 336 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 337 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 338 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 339 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 340 | "Channel doesn't exist"); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 341 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 342 | return -1; |
| 343 | } |
| 344 | return vie_channel->ReceivedRTCPPacket(data, length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 345 | } |
| 346 | |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 347 | int ViENetworkImpl::GetSourceInfo(const int video_channel, |
| 348 | uint16_t& rtp_port, |
| 349 | uint16_t& rtcp_port, char* ip_address, |
| 350 | unsigned int ip_address_length) { |
| 351 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 352 | ViEId(shared_data_->instance_id(), video_channel), |
| 353 | "%s(channel: %d)", __FUNCTION__, video_channel); |
| 354 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 355 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 356 | if (!vie_channel) { |
| 357 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 358 | ViEId(shared_data_->instance_id(), video_channel), |
| 359 | "Channel doesn't exist"); |
| 360 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 361 | return -1; |
| 362 | } |
| 363 | if (vie_channel->GetSourceInfo(&rtp_port, &rtcp_port, ip_address, |
| 364 | ip_address_length) != 0) { |
| 365 | shared_data_->SetLastError(kViENetworkUnknownError); |
| 366 | return -1; |
| 367 | } |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | int ViENetworkImpl::GetLocalIP(char ip_address[64], bool ipv6) { |
| 372 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 373 | "%s( ip_address, ipV6: %d)", __FUNCTION__, ipv6); |
| 374 | |
| 375 | #ifndef WEBRTC_EXTERNAL_TRANSPORT |
| 376 | if (!shared_data_->Initialized()) { |
| 377 | shared_data_->SetLastError(kViENotInitialized); |
| 378 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 379 | "%s - ViE instance %d not initialized", __FUNCTION__, |
| 380 | shared_data_->instance_id()); |
| 381 | return -1; |
| 382 | } |
| 383 | |
| 384 | if (!ip_address) { |
| 385 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 386 | "%s: No argument", __FUNCTION__); |
| 387 | shared_data_->SetLastError(kViENetworkInvalidArgument); |
| 388 | return -1; |
| 389 | } |
| 390 | |
| 391 | WebRtc_UWord8 num_socket_threads = 1; |
| 392 | UdpTransport* socket_transport = UdpTransport::Create( |
| 393 | ViEModuleId(shared_data_->instance_id(), -1), num_socket_threads); |
| 394 | |
| 395 | if (!socket_transport) { |
| 396 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 397 | "%s: Could not create socket module", __FUNCTION__); |
| 398 | shared_data_->SetLastError(kViENetworkUnknownError); |
| 399 | return -1; |
| 400 | } |
| 401 | |
| 402 | char local_ip_address[64]; |
| 403 | if (ipv6) { |
| 404 | char local_ip[16]; |
| 405 | if (socket_transport->LocalHostAddressIPV6(local_ip) != 0) { |
| 406 | UdpTransport::Destroy(socket_transport); |
| 407 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 408 | "%s: Could not get local IP", __FUNCTION__); |
| 409 | shared_data_->SetLastError(kViENetworkUnknownError); |
| 410 | return -1; |
| 411 | } |
| 412 | // Convert 128-bit address to character string (a:b:c:d:e:f:g:h). |
| 413 | // TODO(mflodman) Change sprintf. |
| 414 | sprintf(local_ip_address, // NOLINT |
| 415 | "%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:" |
| 416 | "%.2x%.2x", |
| 417 | local_ip[0], local_ip[1], local_ip[2], local_ip[3], local_ip[4], |
| 418 | local_ip[5], local_ip[6], local_ip[7], local_ip[8], local_ip[9], |
| 419 | local_ip[10], local_ip[11], local_ip[12], local_ip[13], |
| 420 | local_ip[14], local_ip[15]); |
| 421 | } else { |
| 422 | WebRtc_UWord32 local_ip = 0; |
| 423 | if (socket_transport->LocalHostAddress(local_ip) != 0) { |
| 424 | UdpTransport::Destroy(socket_transport); |
| 425 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 426 | "%s: Could not get local IP", __FUNCTION__); |
| 427 | shared_data_->SetLastError(kViENetworkUnknownError); |
| 428 | return -1; |
| 429 | } |
| 430 | // Convert 32-bit address to character string (x.y.z.w). |
| 431 | // TODO(mflodman) Change sprintf. |
| 432 | sprintf(local_ip_address, "%d.%d.%d.%d", // NOLINT |
| 433 | static_cast<int>((local_ip >> 24) & 0x0ff), |
| 434 | static_cast<int>((local_ip >> 16) & 0x0ff), |
| 435 | static_cast<int>((local_ip >> 8) & 0x0ff), |
| 436 | static_cast<int>(local_ip & 0x0ff)); |
| 437 | } |
| 438 | strncpy(ip_address, local_ip_address, sizeof(local_ip_address)); |
| 439 | UdpTransport::Destroy(socket_transport); |
| 440 | WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 441 | "%s: local ip = %s", __FUNCTION__, local_ip_address); |
| 442 | return 0; |
| 443 | #else |
| 444 | WEBRTC_TRACE(kTraceStateInfo, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 445 | "%s: not available for external transport", __FUNCTION__); |
| 446 | |
| 447 | return -1; |
| 448 | #endif |
| 449 | } |
| 450 | |
| 451 | int ViENetworkImpl::EnableIPv6(int video_channel) { |
| 452 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 453 | ViEId(shared_data_->instance_id(), video_channel), |
| 454 | "%s(channel: %d)", __FUNCTION__, video_channel); |
| 455 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 456 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 457 | if (!vie_channel) { |
| 458 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 459 | ViEId(shared_data_->instance_id(), video_channel), |
| 460 | "Channel doesn't exist"); |
| 461 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 462 | return -1; |
| 463 | } |
| 464 | if (vie_channel->EnableIPv6() != 0) { |
| 465 | shared_data_->SetLastError(kViENetworkUnknownError); |
| 466 | return -1; |
| 467 | } |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | bool ViENetworkImpl::IsIPv6Enabled(int video_channel) { |
| 472 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 473 | ViEId(shared_data_->instance_id(), video_channel), |
| 474 | "%s(channel: %d)", __FUNCTION__, video_channel); |
| 475 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 476 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 477 | if (!vie_channel) { |
| 478 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 479 | ViEId(shared_data_->instance_id(), video_channel), |
| 480 | "Channel doesn't exist"); |
| 481 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 482 | return false; |
| 483 | } |
| 484 | return vie_channel->IsIPv6Enabled(); |
| 485 | } |
| 486 | |
| 487 | int ViENetworkImpl::SetSourceFilter(const int video_channel, |
| 488 | const uint16_t rtp_port, |
| 489 | const uint16_t rtcp_port, |
| 490 | const char* ip_address) { |
| 491 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 492 | ViEId(shared_data_->instance_id(), video_channel), |
| 493 | "%s(channel: %d, rtp_port: %u, rtcp_port: %u, ip_address: %s)", |
| 494 | __FUNCTION__, video_channel, rtp_port, rtcp_port, ip_address); |
| 495 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 496 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 497 | if (!vie_channel) { |
| 498 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 499 | ViEId(shared_data_->instance_id(), video_channel), |
| 500 | "Channel doesn't exist"); |
| 501 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 502 | return -1; |
| 503 | } |
| 504 | if (vie_channel->SetSourceFilter(rtp_port, rtcp_port, ip_address) != 0) { |
| 505 | shared_data_->SetLastError(kViENetworkUnknownError); |
| 506 | return -1; |
| 507 | } |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | int ViENetworkImpl::GetSourceFilter(const int video_channel, |
| 512 | uint16_t& rtp_port, |
| 513 | uint16_t& rtcp_port, |
| 514 | char* ip_address) { |
| 515 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 516 | ViEId(shared_data_->instance_id(), video_channel), |
| 517 | "%s(channel: %d)", __FUNCTION__, video_channel); |
| 518 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 519 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 520 | if (!vie_channel) { |
| 521 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 522 | ViEId(shared_data_->instance_id(), video_channel), |
| 523 | "Channel doesn't exist"); |
| 524 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 525 | return -1; |
| 526 | } |
| 527 | if (vie_channel->GetSourceFilter(&rtp_port, &rtcp_port, ip_address) != 0) { |
| 528 | shared_data_->SetLastError(kViENetworkUnknownError); |
| 529 | return -1; |
| 530 | } |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | int ViENetworkImpl::SetSendToS(const int video_channel, const int DSCP, |
| 535 | const bool use_set_sockOpt = false) { |
| 536 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 537 | ViEId(shared_data_->instance_id(), video_channel), |
| 538 | "%s(channel: %d, DSCP: %d, use_set_sockOpt: %d)", __FUNCTION__, |
| 539 | video_channel, DSCP, use_set_sockOpt); |
| 540 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 541 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 542 | if (!vie_channel) { |
| 543 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 544 | ViEId(shared_data_->instance_id(), video_channel), |
| 545 | "Channel doesn't exist"); |
| 546 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 547 | return -1; |
| 548 | } |
| 549 | |
| 550 | #if defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) |
| 551 | WEBRTC_TRACE(kTraceInfo, kTraceVideo, |
| 552 | ViEId(shared_data_->instance_id(), video_channel), |
| 553 | " force use_set_sockopt=true since there is no alternative" |
| 554 | " implementation"); |
| 555 | if (vie_channel->SetToS(DSCP, true) != 0) { |
| 556 | #else |
| 557 | if (vie_channel->SetToS(DSCP, use_set_sockOpt) != 0) { |
| 558 | #endif |
| 559 | shared_data_->SetLastError(kViENetworkUnknownError); |
| 560 | return -1; |
| 561 | } |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | int ViENetworkImpl::GetSendToS(const int video_channel, |
| 566 | int& DSCP, // NOLINT |
| 567 | bool& use_set_sockOpt) { // NOLINT |
| 568 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 569 | ViEId(shared_data_->instance_id(), video_channel), |
| 570 | "%s(channel: %d)", __FUNCTION__, video_channel); |
| 571 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 572 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 573 | if (!vie_channel) { |
| 574 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 575 | ViEId(shared_data_->instance_id(), video_channel), |
| 576 | "Channel doesn't exist"); |
| 577 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 578 | return -1; |
| 579 | } |
| 580 | if (vie_channel->GetToS(&DSCP, &use_set_sockOpt) != 0) { |
| 581 | shared_data_->SetLastError(kViENetworkUnknownError); |
| 582 | return -1; |
| 583 | } |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | int ViENetworkImpl::SetSendGQoS(const int video_channel, const bool enable, |
| 588 | const int service_type, |
| 589 | const int overrideDSCP) { |
| 590 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 591 | ViEId(shared_data_->instance_id(), video_channel), |
| 592 | "%s(channel: %d, enable: %d, service_type: %d, " |
| 593 | "overrideDSCP: %d)", __FUNCTION__, video_channel, enable, |
| 594 | service_type, overrideDSCP); |
| 595 | if (!shared_data_->Initialized()) { |
| 596 | shared_data_->SetLastError(kViENotInitialized); |
| 597 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 598 | "%s - ViE instance %d not initialized", __FUNCTION__, |
| 599 | shared_data_->instance_id()); |
| 600 | return -1; |
| 601 | } |
| 602 | |
| 603 | #if (defined(WIN32_) || defined(WIN64_)) |
| 604 | // Sanity check. We might crash if testing and relying on an OS socket error. |
| 605 | if (enable && |
| 606 | (service_type != SERVICETYPE_BESTEFFORT) && |
| 607 | (service_type != SERVICETYPE_CONTROLLEDLOAD) && |
| 608 | (service_type != SERVICETYPE_GUARANTEED) && |
| 609 | (service_type != SERVICETYPE_QUALITATIVE)) { |
| 610 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 611 | ViEId(shared_data_->instance_id(), video_channel), |
| 612 | "%s: service type %d not supported", __FUNCTION__, |
| 613 | video_channel, service_type); |
| 614 | shared_data_->SetLastError(kViENetworkServiceTypeNotSupported); |
| 615 | return -1; |
| 616 | } |
| 617 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 618 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 619 | if (!vie_channel) { |
| 620 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 621 | ViEId(shared_data_->instance_id(), video_channel), |
| 622 | "Channel doesn't exist"); |
| 623 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 624 | return -1; |
| 625 | } |
| 626 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 627 | if (!vie_encoder) { |
| 628 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 629 | ViEId(shared_data_->instance_id(), video_channel), |
| 630 | "Channel doesn't exist"); |
| 631 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 632 | return -1; |
| 633 | } |
| 634 | VideoCodec video_codec; |
| 635 | if (vie_encoder->GetEncoder(video_codec) != 0) { |
| 636 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 637 | ViEId(shared_data_->instance_id(), video_channel), |
| 638 | "%s: Could not get max bitrate for the channel", |
| 639 | __FUNCTION__); |
| 640 | shared_data_->SetLastError(kViENetworkSendCodecNotSet); |
| 641 | return -1; |
| 642 | } |
| 643 | if (vie_channel->SetSendGQoS(enable, service_type, video_codec.maxBitrate, |
| 644 | overrideDSCP) != 0) { |
| 645 | shared_data_->SetLastError(kViENetworkUnknownError); |
| 646 | return -1; |
| 647 | } |
| 648 | return 0; |
| 649 | #else |
| 650 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 651 | ViEId(shared_data_->instance_id(), video_channel), |
| 652 | "%s: Not supported", __FUNCTION__); |
| 653 | shared_data_->SetLastError(kViENetworkNotSupported); |
| 654 | return -1; |
| 655 | #endif |
| 656 | } |
| 657 | |
| 658 | int ViENetworkImpl::GetSendGQoS(const int video_channel, |
| 659 | bool& enabled, // NOLINT |
| 660 | int& service_type, // NOLINT |
| 661 | int& overrideDSCP) { // NOLINT |
| 662 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 663 | ViEId(shared_data_->instance_id(), video_channel), |
| 664 | "%s(channel: %d)", __FUNCTION__, video_channel); |
| 665 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 666 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 667 | if (!vie_channel) { |
| 668 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 669 | ViEId(shared_data_->instance_id(), video_channel), |
| 670 | "Channel doesn't exist"); |
| 671 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 672 | return -1; |
| 673 | } |
| 674 | if (vie_channel->GetSendGQoS(&enabled, &service_type, &overrideDSCP) != 0) { |
| 675 | shared_data_->SetLastError(kViENetworkUnknownError); |
| 676 | return -1; |
| 677 | } |
| 678 | return 0; |
| 679 | } |
| 680 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 681 | int ViENetworkImpl::SetMTU(int video_channel, unsigned int mtu) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 682 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 683 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 684 | "%s(channel: %d, mtu: %u)", __FUNCTION__, video_channel, mtu); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 685 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 686 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 687 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 688 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 689 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 690 | "Channel doesn't exist"); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 691 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 692 | return -1; |
| 693 | } |
| 694 | if (vie_channel->SetMTU(mtu) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 695 | shared_data_->SetLastError(kViENetworkUnknownError); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 696 | return -1; |
| 697 | } |
| 698 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 699 | } |
| 700 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 701 | int ViENetworkImpl::SetPacketTimeoutNotification(const int video_channel, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 702 | bool enable, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 703 | int timeout_seconds) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 704 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 705 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 706 | "%s(channel: %d, enable: %d, timeout_seconds: %u)", |
| 707 | __FUNCTION__, video_channel, enable, timeout_seconds); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 708 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 709 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 710 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 711 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 712 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 713 | "Channel doesn't exist"); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 714 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 715 | return -1; |
| 716 | } |
| 717 | if (vie_channel->SetPacketTimeoutNotification(enable, |
| 718 | timeout_seconds) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 719 | shared_data_->SetLastError(kViENetworkUnknownError); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 720 | return -1; |
| 721 | } |
| 722 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 723 | } |
| 724 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 725 | int ViENetworkImpl::RegisterObserver(const int video_channel, |
| 726 | ViENetworkObserver& observer) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 727 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 728 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 729 | "%s(channel: %d)", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 730 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 731 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 732 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 733 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 734 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 735 | "Channel doesn't exist"); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 736 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 737 | return -1; |
| 738 | } |
| 739 | if (vie_channel->RegisterNetworkObserver(&observer) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 740 | shared_data_->SetLastError(kViENetworkObserverAlreadyRegistered); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 741 | return -1; |
| 742 | } |
| 743 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 744 | } |
| 745 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 746 | int ViENetworkImpl::DeregisterObserver(const int video_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 747 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 748 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 749 | "%s(channel: %d)", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 750 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 751 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 752 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 753 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 754 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 755 | "Channel doesn't exist"); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 756 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 757 | return -1; |
| 758 | } |
| 759 | if (!vie_channel->NetworkObserverRegistered()) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 760 | shared_data_->SetLastError(kViENetworkObserverNotRegistered); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 761 | return -1; |
| 762 | } |
| 763 | return vie_channel->RegisterNetworkObserver(NULL); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 764 | } |
| 765 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 766 | int ViENetworkImpl::SetPeriodicDeadOrAliveStatus( |
| 767 | const int video_channel, |
| 768 | bool enable, |
| 769 | unsigned int sample_time_seconds) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 770 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 771 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 772 | "%s(channel: %d, enable: %d, sample_time_seconds: %ul)", |
| 773 | __FUNCTION__, video_channel, enable, sample_time_seconds); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 774 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 775 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 776 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 777 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 778 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 779 | "Channel doesn't exist"); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 780 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 781 | return -1; |
| 782 | } |
| 783 | if (!vie_channel->NetworkObserverRegistered()) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 784 | shared_data_->SetLastError(kViENetworkObserverNotRegistered); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 785 | return -1; |
| 786 | } |
| 787 | if (vie_channel->SetPeriodicDeadOrAliveStatus(enable, sample_time_seconds) |
| 788 | != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 789 | shared_data_->SetLastError(kViENetworkUnknownError); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 790 | return -1; |
| 791 | } |
| 792 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 793 | } |
| 794 | |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 795 | int ViENetworkImpl::SendUDPPacket(const int video_channel, const void* data, |
| 796 | const unsigned int length, |
| 797 | int& transmitted_bytes, |
| 798 | bool use_rtcp_socket = false) { |
| 799 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 800 | ViEId(shared_data_->instance_id(), video_channel), |
| 801 | "%s(channel: %d, data: -, length: %d, transmitter_bytes: -, " |
| 802 | "useRtcpSocket: %d)", __FUNCTION__, video_channel, length, |
| 803 | use_rtcp_socket); |
| 804 | if (!shared_data_->Initialized()) { |
| 805 | shared_data_->SetLastError(kViENotInitialized); |
| 806 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 807 | "%s - ViE instance %d not initialized", __FUNCTION__, |
| 808 | shared_data_->instance_id()); |
| 809 | return -1; |
| 810 | } |
| 811 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 812 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 813 | if (!vie_channel) { |
| 814 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 815 | ViEId(shared_data_->instance_id(), video_channel), |
| 816 | "Channel doesn't exist"); |
| 817 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 818 | return -1; |
| 819 | } |
| 820 | if (vie_channel->SendUDPPacket((const WebRtc_Word8*) data, length, |
| 821 | (WebRtc_Word32&) transmitted_bytes, |
| 822 | use_rtcp_socket) < 0) { |
| 823 | shared_data_->SetLastError(kViENetworkUnknownError); |
| 824 | return -1; |
| 825 | } |
| 826 | return 0; |
| 827 | } |
| 828 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 829 | } // namespace webrtc |