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 | |
pwestin@webrtc.org | 82dcc9f | 2013-04-02 20:37:14 +0000 | [diff] [blame] | 11 | #include "webrtc/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 | |
pwestin@webrtc.org | 82dcc9f | 2013-04-02 20:37:14 +0000 | [diff] [blame] | 18 | #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.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) { |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 31 | if (!video_engine) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | return NULL; |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 33 | } |
andrew@webrtc.org | d72262d | 2013-05-09 02:12:07 +0000 | [diff] [blame] | 34 | VideoEngineImpl* vie_impl = static_cast<VideoEngineImpl*>(video_engine); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 35 | ViENetworkImpl* vie_networkImpl = vie_impl; |
| 36 | // Increase ref count. |
| 37 | (*vie_networkImpl)++; |
| 38 | return vie_networkImpl; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | } |
| 40 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 41 | int ViENetworkImpl::Release() { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 42 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_->instance_id(), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 43 | "ViENetwork::Release()"); |
| 44 | // Decrease ref count. |
| 45 | (*this)--; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 47 | int32_t ref_count = GetCount(); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 48 | if (ref_count < 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 49 | WEBRTC_TRACE(kTraceWarning, kTraceVideo, shared_data_->instance_id(), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 50 | "ViENetwork release too many times"); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 51 | shared_data_->SetLastError(kViEAPIDoesNotExist); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 52 | return -1; |
| 53 | } |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 54 | WEBRTC_TRACE(kTraceInfo, kTraceVideo, shared_data_->instance_id(), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 55 | "ViENetwork reference count: %d", ref_count); |
| 56 | return ref_count; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | } |
| 58 | |
stefan@webrtc.org | bfacda6 | 2013-03-27 16:36:01 +0000 | [diff] [blame] | 59 | void 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"); |
stefan@webrtc.org | bfacda6 | 2013-03-27 16:36:01 +0000 | [diff] [blame] | 65 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 66 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 67 | if (!vie_encoder) { |
| 68 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 69 | ViEId(shared_data_->instance_id(), video_channel), |
| 70 | "An encoder doesn't exist for this channel"); |
| 71 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
| 72 | return; |
| 73 | } |
| 74 | vie_encoder->SetNetworkTransmissionState(is_transmitting); |
| 75 | } |
| 76 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 77 | ViENetworkImpl::ViENetworkImpl(ViESharedData* shared_data) |
| 78 | : shared_data_(shared_data) { |
| 79 | WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 80 | "ViENetworkImpl::ViENetworkImpl() Ctor"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | } |
| 82 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 83 | ViENetworkImpl::~ViENetworkImpl() { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 84 | WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 85 | "ViENetworkImpl::~ViENetworkImpl() Dtor"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | } |
| 87 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 88 | int ViENetworkImpl::RegisterSendTransport(const int video_channel, |
| 89 | Transport& transport) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 90 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 91 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 92 | "%s(channel: %d)", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 93 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 94 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 95 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 96 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 97 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 98 | "%s Channel doesn't exist", __FUNCTION__); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 99 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 100 | return -1; |
| 101 | } |
| 102 | if (vie_channel->Sending()) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 103 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 104 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 105 | "%s Channel already sending.", __FUNCTION__); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 106 | shared_data_->SetLastError(kViENetworkAlreadySending); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 107 | return -1; |
| 108 | } |
mflodman@webrtc.org | f5e99db | 2012-06-27 09:49:37 +0000 | [diff] [blame] | 109 | if (vie_channel->RegisterSendTransport(&transport) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 110 | shared_data_->SetLastError(kViENetworkUnknownError); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 111 | return -1; |
| 112 | } |
| 113 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | } |
| 115 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 116 | int ViENetworkImpl::DeregisterSendTransport(const int video_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 117 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 118 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 119 | "%s(channel: %d)", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 120 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 121 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 122 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 123 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 124 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 125 | "%s Channel doesn't exist", __FUNCTION__); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 126 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 127 | return -1; |
| 128 | } |
| 129 | if (vie_channel->Sending()) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 130 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 131 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 132 | "%s Channel already sending", __FUNCTION__); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 133 | shared_data_->SetLastError(kViENetworkAlreadySending); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 134 | return -1; |
| 135 | } |
| 136 | if (vie_channel->DeregisterSendTransport() != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 137 | shared_data_->SetLastError(kViENetworkUnknownError); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 138 | return -1; |
| 139 | } |
| 140 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 141 | } |
| 142 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 143 | int ViENetworkImpl::ReceivedRTPPacket(const int video_channel, const void* data, |
wu@webrtc.org | 2018269 | 2013-12-12 22:54:25 +0000 | [diff] [blame] | 144 | const int length) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 145 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 146 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 147 | "%s(channel: %d, data: -, length: %d)", __FUNCTION__, |
| 148 | video_channel, length); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 149 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 150 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 151 | if (!vie_channel) { |
| 152 | // The channel doesn't exists |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 153 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 154 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 155 | "Channel doesn't exist"); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 156 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 157 | return -1; |
| 158 | } |
wu@webrtc.org | 2018269 | 2013-12-12 22:54:25 +0000 | [diff] [blame] | 159 | return vie_channel->ReceivedRTPPacket(data, length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 160 | } |
| 161 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 162 | int ViENetworkImpl::ReceivedRTCPPacket(const int video_channel, |
| 163 | const void* data, const int length) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 164 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 165 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 166 | "%s(channel: %d, data: -, length: %d)", __FUNCTION__, |
| 167 | video_channel, length); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 168 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 169 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 170 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 171 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 172 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 173 | "Channel doesn't exist"); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 174 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 175 | return -1; |
| 176 | } |
| 177 | return vie_channel->ReceivedRTCPPacket(data, length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 178 | } |
| 179 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 180 | int ViENetworkImpl::SetMTU(int video_channel, unsigned int mtu) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 181 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 182 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 183 | "%s(channel: %d, mtu: %u)", __FUNCTION__, video_channel, mtu); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 184 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 185 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 186 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 187 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 188 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 189 | "Channel doesn't exist"); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 190 | shared_data_->SetLastError(kViENetworkInvalidChannelId); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 191 | return -1; |
| 192 | } |
| 193 | if (vie_channel->SetMTU(mtu) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 194 | shared_data_->SetLastError(kViENetworkUnknownError); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 195 | return -1; |
| 196 | } |
| 197 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 198 | } |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 199 | } // namespace webrtc |