blob: 17aab2e4f459dad77ff5ed5e7f5f95d505478087 [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>
15
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000016#include "webrtc/engine_configurations.h"
17#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
18#include "webrtc/modules/video_coding/main/interface/video_coding.h"
19#include "webrtc/modules/video_processing/main/interface/video_processing.h"
andrew@webrtc.org9841d922012-10-31 05:22:11 +000020#include "webrtc/modules/video_render/include/video_render.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000021#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
22#include "webrtc/system_wrappers/interface/trace.h"
23#include "webrtc/video_engine/include/vie_errors.h"
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000024#include "webrtc/video_engine/vie_capturer.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000025#include "webrtc/video_engine/vie_channel.h"
26#include "webrtc/video_engine/vie_channel_manager.h"
27#include "webrtc/video_engine/vie_defines.h"
28#include "webrtc/video_engine/vie_encoder.h"
29#include "webrtc/video_engine/vie_impl.h"
30#include "webrtc/video_engine/vie_input_manager.h"
31#include "webrtc/video_engine/vie_shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000032
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000033namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000034
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000035ViEBase* ViEBase::GetInterface(VideoEngine* video_engine) {
36 if (!video_engine) {
37 return NULL;
38 }
andrew@webrtc.orgd72262d2013-05-09 02:12:07 +000039 VideoEngineImpl* vie_impl = static_cast<VideoEngineImpl*>(video_engine);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000040 ViEBaseImpl* vie_base_impl = vie_impl;
41 (*vie_base_impl)++; // Increase ref count.
niklase@google.com470e71d2011-07-07 08:21:25 +000042
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000043 return vie_base_impl;
niklase@google.com470e71d2011-07-07 08:21:25 +000044}
45
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000046int ViEBaseImpl::Release() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000047 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_.instance_id(),
niklase@google.com470e71d2011-07-07 08:21:25 +000048 "ViEBase::Release()");
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000049 (*this)--; // Decrease ref count.
niklase@google.com470e71d2011-07-07 08:21:25 +000050
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000051 int32_t ref_count = GetCount();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000052 if (ref_count < 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000053 WEBRTC_TRACE(kTraceWarning, kTraceVideo, shared_data_.instance_id(),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000054 "ViEBase release too many times");
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000055 shared_data_.SetLastError(kViEAPIDoesNotExist);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000056 return -1;
57 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000058 WEBRTC_TRACE(kTraceInfo, kTraceVideo, shared_data_.instance_id(),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000059 "ViEBase reference count: %d", ref_count);
60 return ref_count;
niklase@google.com470e71d2011-07-07 08:21:25 +000061}
62
andresp@webrtc.org7707d062013-05-13 10:50:50 +000063ViEBaseImpl::ViEBaseImpl(const Config& config)
64 : shared_data_(config) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000065 WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_.instance_id(),
niklase@google.com470e71d2011-07-07 08:21:25 +000066 "ViEBaseImpl::ViEBaseImpl() Ctor");
67}
68
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000069ViEBaseImpl::~ViEBaseImpl() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000070 WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_.instance_id(),
niklase@google.com470e71d2011-07-07 08:21:25 +000071 "ViEBaseImpl::ViEBaseImpl() Dtor");
niklase@google.com470e71d2011-07-07 08:21:25 +000072}
73
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000074int ViEBaseImpl::Init() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000075 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_.instance_id(),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000076 "Init");
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000077 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000078}
79
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000080int ViEBaseImpl::SetVoiceEngine(VoiceEngine* voice_engine) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000081 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000082 "%s", __FUNCTION__);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000083 if (shared_data_.channel_manager()->SetVoiceEngine(voice_engine) != 0) {
84 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000085 return -1;
86 }
87 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000088}
89
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000090int ViEBaseImpl::RegisterCpuOveruseObserver(int video_channel,
91 CpuOveruseObserver* observer) {
92 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
93 ViEChannel* vie_channel = cs.Channel(video_channel);
94 if (!vie_channel) {
95 WEBRTC_TRACE(kTraceError,
96 kTraceVideo,
97 ViEId(shared_data_.instance_id()),
98 "%s: channel %d doesn't exist",
99 __FUNCTION__,
100 video_channel);
101 shared_data_.SetLastError(kViEBaseInvalidChannelId);
102 return -1;
103 }
104 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
105 assert(vie_encoder);
106
107 ViEInputManagerScoped is(*(shared_data_.input_manager()));
108 ViEFrameProviderBase* provider = is.FrameProvider(vie_encoder);
109 if (provider) {
110 ViECapturer* capturer = is.Capture(provider->Id());
111 assert(capturer);
112 capturer->RegisterCpuOveruseObserver(observer);
113 }
114
115 shared_data_.overuse_observers()->insert(
116 std::pair<int, CpuOveruseObserver*>(video_channel, observer));
117 return 0;
118}
119
asapersson@webrtc.orgc7ff8f92013-11-26 11:12:33 +0000120int ViEBaseImpl::CpuOveruseMeasures(int video_channel,
121 int* capture_jitter_ms,
122 int* avg_encode_time_ms) {
asapersson@webrtc.org9e5b0342013-12-04 13:47:44 +0000123 int encode_usage_percent;
124 int capture_queue_delay_ms_per_s;
125 return CpuOveruseMeasures(video_channel,
126 capture_jitter_ms,
127 avg_encode_time_ms,
128 &encode_usage_percent,
129 &capture_queue_delay_ms_per_s);
130}
131
132int ViEBaseImpl::CpuOveruseMeasures(int video_channel,
133 int* capture_jitter_ms,
134 int* avg_encode_time_ms,
135 int* encode_usage_percent,
136 int* capture_queue_delay_ms_per_s) {
asapersson@webrtc.orgb24d3352013-11-20 13:51:40 +0000137 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
138 ViEChannel* vie_channel = cs.Channel(video_channel);
139 if (!vie_channel) {
140 WEBRTC_TRACE(kTraceError,
141 kTraceVideo,
142 ViEId(shared_data_.instance_id()),
143 "%s: channel %d doesn't exist",
144 __FUNCTION__,
145 video_channel);
146 shared_data_.SetLastError(kViEBaseInvalidChannelId);
147 return -1;
148 }
149 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
150 assert(vie_encoder);
151
152 ViEInputManagerScoped is(*(shared_data_.input_manager()));
153 ViEFrameProviderBase* provider = is.FrameProvider(vie_encoder);
154 if (provider) {
155 ViECapturer* capturer = is.Capture(provider->Id());
156 if (capturer) {
asapersson@webrtc.org9e5b0342013-12-04 13:47:44 +0000157 capturer->CpuOveruseMeasures(capture_jitter_ms,
158 avg_encode_time_ms,
159 encode_usage_percent,
160 capture_queue_delay_ms_per_s);
asapersson@webrtc.orgb24d3352013-11-20 13:51:40 +0000161 return 0;
162 }
163 }
164 return -1;
165}
166
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000167int ViEBaseImpl::CreateChannel(int& video_channel) { // NOLINT
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000168 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000169 "%s", __FUNCTION__);
mflodman@webrtc.orgab2610f2012-06-29 10:05:28 +0000170 if (shared_data_.channel_manager()->CreateChannel(&video_channel) == -1) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000171 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000172 "%s: Could not create channel", __FUNCTION__);
173 video_channel = -1;
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000174 shared_data_.SetLastError(kViEBaseChannelCreationFailed);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000175 return -1;
176 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000177 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000178 "%s: channel created: %d", __FUNCTION__, video_channel);
179 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000180}
181
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000182int ViEBaseImpl::CreateChannel(int& video_channel, // NOLINT
183 int original_channel) {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000184 return CreateChannel(video_channel, original_channel, true);
185}
niklase@google.com470e71d2011-07-07 08:21:25 +0000186
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000187int ViEBaseImpl::CreateReceiveChannel(int& video_channel, // NOLINT
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000188 int original_channel) {
189 return CreateChannel(video_channel, original_channel, false);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000190}
niklase@google.com470e71d2011-07-07 08:21:25 +0000191
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000192int ViEBaseImpl::DeleteChannel(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000193 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000194 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000195 {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000196 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000197 ViEChannel* vie_channel = cs.Channel(video_channel);
198 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000199 WEBRTC_TRACE(kTraceError, kTraceVideo,
200 ViEId(shared_data_.instance_id()),
201 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
202 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000203 return -1;
204 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000205
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000206 // Deregister the ViEEncoder if no other channel is using it.
207 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
208 if (cs.ChannelUsingViEEncoder(video_channel) == false) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000209 ViEInputManagerScoped is(*(shared_data_.input_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000210 ViEFrameProviderBase* provider = is.FrameProvider(vie_encoder);
211 if (provider) {
212 provider->DeregisterFrameCallback(vie_encoder);
213 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000214 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000215 }
216
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000217 if (shared_data_.channel_manager()->DeleteChannel(video_channel) == -1) {
218 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000219 "%s: Could not delete channel %d", __FUNCTION__,
220 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000221 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000222 return -1;
223 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000224 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000225 "%s: channel deleted: %d", __FUNCTION__, video_channel);
226 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000227}
228
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000229int ViEBaseImpl::ConnectAudioChannel(const int video_channel,
230 const int audio_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000231 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000232 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000233 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000234 if (!cs.Channel(video_channel)) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000235 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000236 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000237 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000238 return -1;
239 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000240
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000241 if (shared_data_.channel_manager()->ConnectVoiceChannel(video_channel,
242 audio_channel) != 0) {
243 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000244 return -1;
245 }
246 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000247}
248
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000249int ViEBaseImpl::DisconnectAudioChannel(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000250 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000251 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000252 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000253 if (!cs.Channel(video_channel)) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000254 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000255 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000256 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000257 return -1;
258 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000259
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000260 if (shared_data_.channel_manager()->DisconnectVoiceChannel(
261 video_channel) != 0) {
262 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000263 return -1;
264 }
265 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000266}
267
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000268int ViEBaseImpl::StartSend(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000269 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
270 ViEId(shared_data_.instance_id(), video_channel),
271 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000272
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000273 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000274 ViEChannel* vie_channel = cs.Channel(video_channel);
275 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000276 WEBRTC_TRACE(kTraceError, kTraceVideo,
277 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000278 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000279 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000280 return -1;
281 }
mflodman@webrtc.org1a739ba2012-02-28 16:11:33 +0000282
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000283 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000284 assert(vie_encoder != NULL);
285 if (vie_encoder->Owner() != video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000286 WEBRTC_TRACE(kTraceError, kTraceVideo,
287 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000288 "Can't start ssend on a receive only channel.");
289 shared_data_.SetLastError(kViEBaseReceiveOnlyChannel);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000290 return -1;
291 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000292
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000293 // Pause and trigger a key frame.
294 vie_encoder->Pause();
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000295 int32_t error = vie_channel->StartSend();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000296 if (error != 0) {
297 vie_encoder->Restart();
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000298 WEBRTC_TRACE(kTraceError, kTraceVideo,
299 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000300 "%s: Could not start sending on channel %d", __FUNCTION__,
301 video_channel);
302 if (error == kViEBaseAlreadySending) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000303 shared_data_.SetLastError(kViEBaseAlreadySending);
niklase@google.com470e71d2011-07-07 08:21:25 +0000304 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000305 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000306 return -1;
307 }
308 vie_encoder->SendKeyFrame();
309 vie_encoder->Restart();
310 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000311}
312
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000313int ViEBaseImpl::StopSend(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000314 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
315 ViEId(shared_data_.instance_id(), video_channel),
316 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000317
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000318 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000319 ViEChannel* vie_channel = cs.Channel(video_channel);
320 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000321 WEBRTC_TRACE(kTraceError, kTraceVideo,
322 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000323 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000324 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000325 return -1;
326 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000327
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000328 int32_t error = vie_channel->StopSend();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000329 if (error != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000330 WEBRTC_TRACE(kTraceError, kTraceVideo,
331 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000332 "%s: Could not stop sending on channel %d", __FUNCTION__,
333 video_channel);
334 if (error == kViEBaseNotSending) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000335 shared_data_.SetLastError(kViEBaseNotSending);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000336 } else {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000337 shared_data_.SetLastError(kViEBaseUnknownError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000338 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000339 return -1;
340 }
341 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000342}
343
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000344int ViEBaseImpl::StartReceive(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000345 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
346 ViEId(shared_data_.instance_id(), video_channel),
347 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000348
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000349 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000350 ViEChannel* vie_channel = cs.Channel(video_channel);
351 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000352 WEBRTC_TRACE(kTraceError, kTraceVideo,
353 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000354 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000355 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000356 return -1;
357 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000358 if (vie_channel->StartReceive() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000359 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000360 return -1;
361 }
362 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000363}
364
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000365int ViEBaseImpl::StopReceive(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000366 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
367 ViEId(shared_data_.instance_id(), video_channel),
368 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000369
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000370 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000371 ViEChannel* vie_channel = cs.Channel(video_channel);
372 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000373 WEBRTC_TRACE(kTraceError, kTraceVideo,
374 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000375 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000376 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000377 return -1;
378 }
379 if (vie_channel->StopReceive() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000380 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000381 return -1;
382 }
383 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000384}
385
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000386int ViEBaseImpl::GetVersion(char version[1024]) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000387 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
niklase@google.com470e71d2011-07-07 08:21:25 +0000388 "GetVersion(version=?)");
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000389 assert(kViEVersionMaxMessageSize == 1024);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000390 if (!version) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000391 shared_data_.SetLastError(kViEBaseInvalidArgument);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000392 return -1;
393 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000394
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000395 // Add WebRTC Version.
396 std::stringstream version_stream;
elham@webrtc.org326bcff2013-11-25 17:19:46 +0000397 version_stream << "VideoEngine 3.47.0" << std::endl;
niklase@google.com470e71d2011-07-07 08:21:25 +0000398
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000399 // Add build info.
400 version_stream << "Build: svn:" << WEBRTC_SVNREVISION << " " << BUILDINFO
401 << std::endl;
niklase@google.com470e71d2011-07-07 08:21:25 +0000402
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000403#ifdef WEBRTC_EXTERNAL_TRANSPORT
404 version_stream << "External transport build" << std::endl;
405#endif
406 int version_length = version_stream.tellp();
407 assert(version_length < 1024);
408 memcpy(version, version_stream.str().c_str(), version_length);
leozwang@webrtc.org6c08f262012-07-13 22:00:16 +0000409 version[version_length] = '\0';
niklase@google.com470e71d2011-07-07 08:21:25 +0000410
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000411 WEBRTC_TRACE(kTraceStateInfo, kTraceVideo,
412 ViEId(shared_data_.instance_id()), "GetVersion() => %s",
413 version);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000414 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000415}
416
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000417int ViEBaseImpl::LastError() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000418 return shared_data_.LastErrorInternal();
niklase@google.com470e71d2011-07-07 08:21:25 +0000419}
420
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000421int ViEBaseImpl::CreateChannel(int& video_channel, // NOLINT
422 int original_channel, bool sender) {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000423 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
424 if (!cs.Channel(original_channel)) {
425 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
426 "%s - original_channel does not exist.", __FUNCTION__,
427 shared_data_.instance_id());
428 shared_data_.SetLastError(kViEBaseInvalidChannelId);
429 return -1;
430 }
431
mflodman@webrtc.orgab2610f2012-06-29 10:05:28 +0000432 if (shared_data_.channel_manager()->CreateChannel(&video_channel,
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000433 original_channel,
434 sender) == -1) {
435 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
436 "%s: Could not create channel", __FUNCTION__);
437 video_channel = -1;
438 shared_data_.SetLastError(kViEBaseChannelCreationFailed);
439 return -1;
440 }
441 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
442 "%s: channel created: %d", __FUNCTION__, video_channel);
443 return 0;
444}
445
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000446} // namespace webrtc