blob: 8d6aeb2193f476f4e8f3e0c79585e5f9b2bbef48 [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.orgb24d3352013-11-20 13:51:40 +0000123 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
124 ViEChannel* vie_channel = cs.Channel(video_channel);
125 if (!vie_channel) {
126 WEBRTC_TRACE(kTraceError,
127 kTraceVideo,
128 ViEId(shared_data_.instance_id()),
129 "%s: channel %d doesn't exist",
130 __FUNCTION__,
131 video_channel);
132 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.orgc7ff8f92013-11-26 11:12:33 +0000143 capturer->CpuOveruseMeasures(capture_jitter_ms, avg_encode_time_ms);
asapersson@webrtc.orgb24d3352013-11-20 13:51:40 +0000144 return 0;
145 }
146 }
147 return -1;
148}
149
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000150int ViEBaseImpl::CreateChannel(int& video_channel) { // NOLINT
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000151 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000152 "%s", __FUNCTION__);
mflodman@webrtc.orgab2610f2012-06-29 10:05:28 +0000153 if (shared_data_.channel_manager()->CreateChannel(&video_channel) == -1) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000154 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000155 "%s: Could not create channel", __FUNCTION__);
156 video_channel = -1;
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000157 shared_data_.SetLastError(kViEBaseChannelCreationFailed);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000158 return -1;
159 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000160 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000161 "%s: channel created: %d", __FUNCTION__, video_channel);
162 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000163}
164
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000165int ViEBaseImpl::CreateChannel(int& video_channel, // NOLINT
166 int original_channel) {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000167 return CreateChannel(video_channel, original_channel, true);
168}
niklase@google.com470e71d2011-07-07 08:21:25 +0000169
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000170int ViEBaseImpl::CreateReceiveChannel(int& video_channel, // NOLINT
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000171 int original_channel) {
172 return CreateChannel(video_channel, original_channel, false);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000173}
niklase@google.com470e71d2011-07-07 08:21:25 +0000174
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000175int ViEBaseImpl::DeleteChannel(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000176 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000177 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000178 {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000179 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000180 ViEChannel* vie_channel = cs.Channel(video_channel);
181 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000182 WEBRTC_TRACE(kTraceError, kTraceVideo,
183 ViEId(shared_data_.instance_id()),
184 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
185 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000186 return -1;
187 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000188
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000189 // Deregister the ViEEncoder if no other channel is using it.
190 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
191 if (cs.ChannelUsingViEEncoder(video_channel) == false) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000192 ViEInputManagerScoped is(*(shared_data_.input_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000193 ViEFrameProviderBase* provider = is.FrameProvider(vie_encoder);
194 if (provider) {
195 provider->DeregisterFrameCallback(vie_encoder);
196 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000197 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000198 }
199
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000200 if (shared_data_.channel_manager()->DeleteChannel(video_channel) == -1) {
201 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000202 "%s: Could not delete channel %d", __FUNCTION__,
203 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000204 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000205 return -1;
206 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000207 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000208 "%s: channel deleted: %d", __FUNCTION__, video_channel);
209 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000210}
211
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000212int ViEBaseImpl::ConnectAudioChannel(const int video_channel,
213 const int audio_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000214 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000215 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000216 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000217 if (!cs.Channel(video_channel)) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000218 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000219 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000220 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000221 return -1;
222 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000223
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000224 if (shared_data_.channel_manager()->ConnectVoiceChannel(video_channel,
225 audio_channel) != 0) {
226 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000227 return -1;
228 }
229 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000230}
231
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000232int ViEBaseImpl::DisconnectAudioChannel(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000233 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000234 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000235 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000236 if (!cs.Channel(video_channel)) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000237 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000238 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000239 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000240 return -1;
241 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000242
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000243 if (shared_data_.channel_manager()->DisconnectVoiceChannel(
244 video_channel) != 0) {
245 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000246 return -1;
247 }
248 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000249}
250
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000251int ViEBaseImpl::StartSend(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000252 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
253 ViEId(shared_data_.instance_id(), video_channel),
254 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000255
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000256 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000257 ViEChannel* vie_channel = cs.Channel(video_channel);
258 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000259 WEBRTC_TRACE(kTraceError, kTraceVideo,
260 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000261 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000262 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000263 return -1;
264 }
mflodman@webrtc.org1a739ba2012-02-28 16:11:33 +0000265
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000266 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000267 assert(vie_encoder != NULL);
268 if (vie_encoder->Owner() != video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000269 WEBRTC_TRACE(kTraceError, kTraceVideo,
270 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000271 "Can't start ssend on a receive only channel.");
272 shared_data_.SetLastError(kViEBaseReceiveOnlyChannel);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000273 return -1;
274 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000275
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000276 // Pause and trigger a key frame.
277 vie_encoder->Pause();
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000278 int32_t error = vie_channel->StartSend();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000279 if (error != 0) {
280 vie_encoder->Restart();
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000281 WEBRTC_TRACE(kTraceError, kTraceVideo,
282 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000283 "%s: Could not start sending on channel %d", __FUNCTION__,
284 video_channel);
285 if (error == kViEBaseAlreadySending) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000286 shared_data_.SetLastError(kViEBaseAlreadySending);
niklase@google.com470e71d2011-07-07 08:21:25 +0000287 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000288 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000289 return -1;
290 }
291 vie_encoder->SendKeyFrame();
292 vie_encoder->Restart();
293 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000294}
295
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000296int ViEBaseImpl::StopSend(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000297 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
298 ViEId(shared_data_.instance_id(), video_channel),
299 "%s(channel: %d)", __FUNCTION__, 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 WEBRTC_TRACE(kTraceError, kTraceVideo,
305 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000306 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000307 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000308 return -1;
309 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000310
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000311 int32_t error = vie_channel->StopSend();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000312 if (error != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000313 WEBRTC_TRACE(kTraceError, kTraceVideo,
314 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000315 "%s: Could not stop sending on channel %d", __FUNCTION__,
316 video_channel);
317 if (error == kViEBaseNotSending) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000318 shared_data_.SetLastError(kViEBaseNotSending);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000319 } else {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000320 shared_data_.SetLastError(kViEBaseUnknownError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000321 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000322 return -1;
323 }
324 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000325}
326
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000327int ViEBaseImpl::StartReceive(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000328 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
329 ViEId(shared_data_.instance_id(), video_channel),
330 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000331
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000332 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000333 ViEChannel* vie_channel = cs.Channel(video_channel);
334 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000335 WEBRTC_TRACE(kTraceError, kTraceVideo,
336 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000337 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000338 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000339 return -1;
340 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000341 if (vie_channel->StartReceive() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000342 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000343 return -1;
344 }
345 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000346}
347
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000348int ViEBaseImpl::StopReceive(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000349 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
350 ViEId(shared_data_.instance_id(), video_channel),
351 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000352
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000353 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000354 ViEChannel* vie_channel = cs.Channel(video_channel);
355 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000356 WEBRTC_TRACE(kTraceError, kTraceVideo,
357 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000358 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000359 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000360 return -1;
361 }
362 if (vie_channel->StopReceive() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000363 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000364 return -1;
365 }
366 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000367}
368
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000369int ViEBaseImpl::GetVersion(char version[1024]) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000370 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
niklase@google.com470e71d2011-07-07 08:21:25 +0000371 "GetVersion(version=?)");
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000372 assert(kViEVersionMaxMessageSize == 1024);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000373 if (!version) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000374 shared_data_.SetLastError(kViEBaseInvalidArgument);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000375 return -1;
376 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000377
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000378 // Add WebRTC Version.
379 std::stringstream version_stream;
elham@webrtc.org326bcff2013-11-25 17:19:46 +0000380 version_stream << "VideoEngine 3.47.0" << std::endl;
niklase@google.com470e71d2011-07-07 08:21:25 +0000381
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000382 // Add build info.
383 version_stream << "Build: svn:" << WEBRTC_SVNREVISION << " " << BUILDINFO
384 << std::endl;
niklase@google.com470e71d2011-07-07 08:21:25 +0000385
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000386#ifdef WEBRTC_EXTERNAL_TRANSPORT
387 version_stream << "External transport build" << std::endl;
388#endif
389 int version_length = version_stream.tellp();
390 assert(version_length < 1024);
391 memcpy(version, version_stream.str().c_str(), version_length);
leozwang@webrtc.org6c08f262012-07-13 22:00:16 +0000392 version[version_length] = '\0';
niklase@google.com470e71d2011-07-07 08:21:25 +0000393
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000394 WEBRTC_TRACE(kTraceStateInfo, kTraceVideo,
395 ViEId(shared_data_.instance_id()), "GetVersion() => %s",
396 version);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000397 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000398}
399
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000400int ViEBaseImpl::LastError() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000401 return shared_data_.LastErrorInternal();
niklase@google.com470e71d2011-07-07 08:21:25 +0000402}
403
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000404int ViEBaseImpl::CreateChannel(int& video_channel, // NOLINT
405 int original_channel, bool sender) {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000406 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
407 if (!cs.Channel(original_channel)) {
408 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
409 "%s - original_channel does not exist.", __FUNCTION__,
410 shared_data_.instance_id());
411 shared_data_.SetLastError(kViEBaseInvalidChannelId);
412 return -1;
413 }
414
mflodman@webrtc.orgab2610f2012-06-29 10:05:28 +0000415 if (shared_data_.channel_manager()->CreateChannel(&video_channel,
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000416 original_channel,
417 sender) == -1) {
418 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
419 "%s: Could not create channel", __FUNCTION__);
420 video_channel = -1;
421 shared_data_.SetLastError(kViEBaseChannelCreationFailed);
422 return -1;
423 }
424 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
425 "%s: channel created: %d", __FUNCTION__, video_channel);
426 return 0;
427}
428
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000429} // namespace webrtc