blob: f4b87e8fa4bb40db401397b9c60c45fd43866f0c [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
mflodman@webrtc.org1a739ba2012-02-28 16:11:33 +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_base_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +000013#include <sstream>
14#include <string>
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +000015#include <utility>
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +000016
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000017#include "webrtc/engine_configurations.h"
18#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
19#include "webrtc/modules/video_coding/main/interface/video_coding.h"
20#include "webrtc/modules/video_processing/main/interface/video_processing.h"
andrew@webrtc.org9841d922012-10-31 05:22:11 +000021#include "webrtc/modules/video_render/include/video_render.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000022#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +000023#include "webrtc/system_wrappers/interface/logging.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000024#include "webrtc/video_engine/include/vie_errors.h"
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000025#include "webrtc/video_engine/vie_capturer.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000026#include "webrtc/video_engine/vie_channel.h"
27#include "webrtc/video_engine/vie_channel_manager.h"
28#include "webrtc/video_engine/vie_defines.h"
29#include "webrtc/video_engine/vie_encoder.h"
30#include "webrtc/video_engine/vie_impl.h"
31#include "webrtc/video_engine/vie_input_manager.h"
32#include "webrtc/video_engine/vie_shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000033
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000034namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000035
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000036ViEBase* ViEBase::GetInterface(VideoEngine* video_engine) {
37 if (!video_engine) {
38 return NULL;
39 }
andrew@webrtc.orgd72262d2013-05-09 02:12:07 +000040 VideoEngineImpl* vie_impl = static_cast<VideoEngineImpl*>(video_engine);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000041 ViEBaseImpl* vie_base_impl = vie_impl;
42 (*vie_base_impl)++; // Increase ref count.
niklase@google.com470e71d2011-07-07 08:21:25 +000043
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000044 return vie_base_impl;
niklase@google.com470e71d2011-07-07 08:21:25 +000045}
46
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000047int ViEBaseImpl::Release() {
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000048 (*this)--; // Decrease ref count.
niklase@google.com470e71d2011-07-07 08:21:25 +000049
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000050 int32_t ref_count = GetCount();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000051 if (ref_count < 0) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +000052 LOG(LS_WARNING) << "ViEBase released too many times.";
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000053 return -1;
54 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000055 return ref_count;
niklase@google.com470e71d2011-07-07 08:21:25 +000056}
57
andresp@webrtc.org7707d062013-05-13 10:50:50 +000058ViEBaseImpl::ViEBaseImpl(const Config& config)
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +000059 : shared_data_(config) {}
niklase@google.com470e71d2011-07-07 08:21:25 +000060
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +000061ViEBaseImpl::~ViEBaseImpl() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000062
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000063int ViEBaseImpl::Init() {
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000064 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000065}
66
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000067int ViEBaseImpl::SetVoiceEngine(VoiceEngine* voice_engine) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +000068 LOG_F(LS_INFO) << "SetVoiceEngine";
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000069 if (shared_data_.channel_manager()->SetVoiceEngine(voice_engine) != 0) {
70 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000071 return -1;
72 }
73 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000074}
75
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000076int ViEBaseImpl::RegisterCpuOveruseObserver(int video_channel,
77 CpuOveruseObserver* observer) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +000078 LOG_F(LS_INFO) << "RegisterCpuOveruseObserver on channel " << video_channel;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000079 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
80 ViEChannel* vie_channel = cs.Channel(video_channel);
81 if (!vie_channel) {
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000082 shared_data_.SetLastError(kViEBaseInvalidChannelId);
83 return -1;
84 }
85 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
86 assert(vie_encoder);
87
88 ViEInputManagerScoped is(*(shared_data_.input_manager()));
89 ViEFrameProviderBase* provider = is.FrameProvider(vie_encoder);
90 if (provider) {
91 ViECapturer* capturer = is.Capture(provider->Id());
92 assert(capturer);
93 capturer->RegisterCpuOveruseObserver(observer);
94 }
95
96 shared_data_.overuse_observers()->insert(
97 std::pair<int, CpuOveruseObserver*>(video_channel, observer));
98 return 0;
99}
100
asapersson@webrtc.org8a8c3ef2014-03-20 13:15:01 +0000101int ViEBaseImpl::SetCpuOveruseOptions(int video_channel,
102 const CpuOveruseOptions& options) {
103 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
104 ViEChannel* vie_channel = cs.Channel(video_channel);
105 if (!vie_channel) {
asapersson@webrtc.org8a8c3ef2014-03-20 13:15:01 +0000106 shared_data_.SetLastError(kViEBaseInvalidChannelId);
107 return -1;
108 }
109 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
110 assert(vie_encoder);
111
112 ViEInputManagerScoped is(*(shared_data_.input_manager()));
113 ViEFrameProviderBase* provider = is.FrameProvider(vie_encoder);
114 if (provider) {
115 ViECapturer* capturer = is.Capture(provider->Id());
116 if (capturer) {
117 capturer->SetCpuOveruseOptions(options);
118 return 0;
119 }
120 }
121 return -1;
122}
123
asapersson@webrtc.orgc7ff8f92013-11-26 11:12:33 +0000124int ViEBaseImpl::CpuOveruseMeasures(int video_channel,
125 int* capture_jitter_ms,
asapersson@webrtc.org9e5b0342013-12-04 13:47:44 +0000126 int* avg_encode_time_ms,
127 int* encode_usage_percent,
128 int* capture_queue_delay_ms_per_s) {
asapersson@webrtc.orgb24d3352013-11-20 13:51:40 +0000129 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
130 ViEChannel* vie_channel = cs.Channel(video_channel);
131 if (!vie_channel) {
asapersson@webrtc.orgb24d3352013-11-20 13:51:40 +0000132 shared_data_.SetLastError(kViEBaseInvalidChannelId);
133 return -1;
134 }
135 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
136 assert(vie_encoder);
137
138 ViEInputManagerScoped is(*(shared_data_.input_manager()));
139 ViEFrameProviderBase* provider = is.FrameProvider(vie_encoder);
140 if (provider) {
141 ViECapturer* capturer = is.Capture(provider->Id());
142 if (capturer) {
asapersson@webrtc.org9e5b0342013-12-04 13:47:44 +0000143 capturer->CpuOveruseMeasures(capture_jitter_ms,
144 avg_encode_time_ms,
145 encode_usage_percent,
146 capture_queue_delay_ms_per_s);
asapersson@webrtc.orgb24d3352013-11-20 13:51:40 +0000147 return 0;
148 }
149 }
150 return -1;
151}
152
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000153int ViEBaseImpl::CreateChannel(int& video_channel) { // NOLINT
henrik.lundin@webrtc.org41907742014-01-29 08:47:15 +0000154 return CreateChannel(video_channel, static_cast<const Config*>(NULL));
155}
156
157int ViEBaseImpl::CreateChannel(int& video_channel, // NOLINT
158 const Config* config) {
henrik.lundin@webrtc.org41907742014-01-29 08:47:15 +0000159 if (shared_data_.channel_manager()->CreateChannel(&video_channel,
160 config) == -1) {
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000161 video_channel = -1;
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000162 shared_data_.SetLastError(kViEBaseChannelCreationFailed);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000163 return -1;
164 }
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000165 LOG(LS_INFO) << "Video channel created: " << video_channel;
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000166 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000167}
168
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000169int ViEBaseImpl::CreateChannel(int& video_channel, // NOLINT
170 int original_channel) {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000171 return CreateChannel(video_channel, original_channel, true);
172}
niklase@google.com470e71d2011-07-07 08:21:25 +0000173
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000174int ViEBaseImpl::CreateReceiveChannel(int& video_channel, // NOLINT
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000175 int original_channel) {
176 return CreateChannel(video_channel, original_channel, false);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000177}
niklase@google.com470e71d2011-07-07 08:21:25 +0000178
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000179int ViEBaseImpl::DeleteChannel(const int video_channel) {
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000180 {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000181 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000182 ViEChannel* vie_channel = cs.Channel(video_channel);
183 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000184 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000185 return -1;
186 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000187
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000188 // Deregister the ViEEncoder if no other channel is using it.
189 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
190 if (cs.ChannelUsingViEEncoder(video_channel) == false) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000191 ViEInputManagerScoped is(*(shared_data_.input_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000192 ViEFrameProviderBase* provider = is.FrameProvider(vie_encoder);
193 if (provider) {
194 provider->DeregisterFrameCallback(vie_encoder);
195 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000196 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000197 }
198
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000199 if (shared_data_.channel_manager()->DeleteChannel(video_channel) == -1) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000200 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000201 return -1;
202 }
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000203 LOG(LS_INFO) << "Channel deleted " << video_channel;
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000204 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000205}
206
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000207int ViEBaseImpl::ConnectAudioChannel(const int video_channel,
208 const int audio_channel) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000209 LOG_F(LS_INFO) << "ConnectAudioChannel, video channel " << video_channel
210 << ", audio channel " << audio_channel;
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000211 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000212 if (!cs.Channel(video_channel)) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000213 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000214 return -1;
215 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000216
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000217 if (shared_data_.channel_manager()->ConnectVoiceChannel(video_channel,
218 audio_channel) != 0) {
219 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000220 return -1;
221 }
222 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000223}
224
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000225int ViEBaseImpl::DisconnectAudioChannel(const int video_channel) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000226 LOG_F(LS_INFO) << "DisconnectAudioChannel " << video_channel;
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000227 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000228 if (!cs.Channel(video_channel)) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000229 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000230 return -1;
231 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000232
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000233 if (shared_data_.channel_manager()->DisconnectVoiceChannel(
234 video_channel) != 0) {
235 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000236 return -1;
237 }
238 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000239}
240
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000241int ViEBaseImpl::StartSend(const int video_channel) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000242 LOG_F(LS_INFO) << "StartSend: " << video_channel;
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000243 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000244 ViEChannel* vie_channel = cs.Channel(video_channel);
245 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000246 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000247 return -1;
248 }
mflodman@webrtc.org1a739ba2012-02-28 16:11:33 +0000249
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000250 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000251 assert(vie_encoder != NULL);
252 if (vie_encoder->Owner() != video_channel) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000253 LOG_F(LS_ERROR) << "Can't start send on a receive only channel.";
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000254 shared_data_.SetLastError(kViEBaseReceiveOnlyChannel);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000255 return -1;
256 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000257
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000258 // Pause and trigger a key frame.
259 vie_encoder->Pause();
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000260 int32_t error = vie_channel->StartSend();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000261 if (error != 0) {
262 vie_encoder->Restart();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000263 if (error == kViEBaseAlreadySending) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000264 shared_data_.SetLastError(kViEBaseAlreadySending);
niklase@google.com470e71d2011-07-07 08:21:25 +0000265 }
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000266 LOG_F(LS_ERROR) << "Could not start sending " << video_channel;
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000267 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000268 return -1;
269 }
270 vie_encoder->SendKeyFrame();
271 vie_encoder->Restart();
272 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000273}
274
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000275int ViEBaseImpl::StopSend(const int video_channel) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000276 LOG_F(LS_INFO) << "StopSend " << video_channel;
niklase@google.com470e71d2011-07-07 08:21:25 +0000277
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000278 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000279 ViEChannel* vie_channel = cs.Channel(video_channel);
280 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000281 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000282 return -1;
283 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000284
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000285 int32_t error = vie_channel->StopSend();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000286 if (error != 0) {
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000287 if (error == kViEBaseNotSending) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000288 shared_data_.SetLastError(kViEBaseNotSending);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000289 } else {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000290 LOG_F(LS_ERROR) << "Could not stop sending " << video_channel;
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000291 shared_data_.SetLastError(kViEBaseUnknownError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000292 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000293 return -1;
294 }
295 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000296}
297
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000298int ViEBaseImpl::StartReceive(const int video_channel) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000299 LOG_F(LS_INFO) << "StartReceive " << video_channel;
niklase@google.com470e71d2011-07-07 08:21:25 +0000300
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000301 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000302 ViEChannel* vie_channel = cs.Channel(video_channel);
303 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000304 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000305 return -1;
306 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000307 if (vie_channel->StartReceive() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000308 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000309 return -1;
310 }
311 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000312}
313
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000314int ViEBaseImpl::StopReceive(const int video_channel) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000315 LOG_F(LS_INFO) << "StopReceive " << video_channel;
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000316 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000317 ViEChannel* vie_channel = cs.Channel(video_channel);
318 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000319 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000320 return -1;
321 }
322 if (vie_channel->StopReceive() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000323 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000324 return -1;
325 }
326 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000327}
328
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000329int ViEBaseImpl::GetVersion(char version[1024]) {
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000330 assert(kViEVersionMaxMessageSize == 1024);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000331 if (!version) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000332 shared_data_.SetLastError(kViEBaseInvalidArgument);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000333 return -1;
334 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000335
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000336 // Add WebRTC Version.
337 std::stringstream version_stream;
tnakamura@webrtc.org07207582014-05-22 17:51:18 +0000338 version_stream << "VideoEngine 3.54.0" << std::endl;
niklase@google.com470e71d2011-07-07 08:21:25 +0000339
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000340 // Add build info.
andrew@webrtc.org3054ba62013-12-04 17:00:44 +0000341 version_stream << "Build: " << BUILDINFO << std::endl;
niklase@google.com470e71d2011-07-07 08:21:25 +0000342
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000343 int version_length = version_stream.tellp();
344 assert(version_length < 1024);
345 memcpy(version, version_stream.str().c_str(), version_length);
leozwang@webrtc.org6c08f262012-07-13 22:00:16 +0000346 version[version_length] = '\0';
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000347 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000348}
349
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000350int ViEBaseImpl::LastError() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000351 return shared_data_.LastErrorInternal();
niklase@google.com470e71d2011-07-07 08:21:25 +0000352}
353
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000354int ViEBaseImpl::CreateChannel(int& video_channel, // NOLINT
355 int original_channel, bool sender) {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000356 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
357 if (!cs.Channel(original_channel)) {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000358 shared_data_.SetLastError(kViEBaseInvalidChannelId);
359 return -1;
360 }
361
mflodman@webrtc.orgab2610f2012-06-29 10:05:28 +0000362 if (shared_data_.channel_manager()->CreateChannel(&video_channel,
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000363 original_channel,
364 sender) == -1) {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000365 video_channel = -1;
366 shared_data_.SetLastError(kViEBaseChannelCreationFailed);
367 return -1;
368 }
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000369 LOG_F(LS_INFO) << "VideoChannel created: " << video_channel
370 << ", base channel " << original_channel
371 << ", is send channel : " << sender;
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000372 return 0;
373}
374
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000375} // namespace webrtc