blob: bd8f5245e0bc5ff289dd16254f65ececffb03d80 [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.orgb24d3352013-11-20 13:51:40 +0000120int ViEBaseImpl::CpuOveruseMeasure(int video_channel, int* capture_jitter_ms) {
121 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
122 ViEChannel* vie_channel = cs.Channel(video_channel);
123 if (!vie_channel) {
124 WEBRTC_TRACE(kTraceError,
125 kTraceVideo,
126 ViEId(shared_data_.instance_id()),
127 "%s: channel %d doesn't exist",
128 __FUNCTION__,
129 video_channel);
130 shared_data_.SetLastError(kViEBaseInvalidChannelId);
131 return -1;
132 }
133 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
134 assert(vie_encoder);
135
136 ViEInputManagerScoped is(*(shared_data_.input_manager()));
137 ViEFrameProviderBase* provider = is.FrameProvider(vie_encoder);
138 if (provider) {
139 ViECapturer* capturer = is.Capture(provider->Id());
140 if (capturer) {
141 *capture_jitter_ms = capturer->CpuOveruseMeasure();
142 return 0;
143 }
144 }
145 return -1;
146}
147
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000148int ViEBaseImpl::CreateChannel(int& video_channel) { // NOLINT
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000149 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000150 "%s", __FUNCTION__);
mflodman@webrtc.orgab2610f2012-06-29 10:05:28 +0000151 if (shared_data_.channel_manager()->CreateChannel(&video_channel) == -1) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000152 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000153 "%s: Could not create channel", __FUNCTION__);
154 video_channel = -1;
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000155 shared_data_.SetLastError(kViEBaseChannelCreationFailed);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000156 return -1;
157 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000158 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000159 "%s: channel created: %d", __FUNCTION__, video_channel);
160 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000161}
162
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000163int ViEBaseImpl::CreateChannel(int& video_channel, // NOLINT
164 int original_channel) {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000165 return CreateChannel(video_channel, original_channel, true);
166}
niklase@google.com470e71d2011-07-07 08:21:25 +0000167
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000168int ViEBaseImpl::CreateReceiveChannel(int& video_channel, // NOLINT
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000169 int original_channel) {
170 return CreateChannel(video_channel, original_channel, false);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000171}
niklase@google.com470e71d2011-07-07 08:21:25 +0000172
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000173int ViEBaseImpl::DeleteChannel(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000174 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000175 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000176 {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000177 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000178 ViEChannel* vie_channel = cs.Channel(video_channel);
179 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000180 WEBRTC_TRACE(kTraceError, kTraceVideo,
181 ViEId(shared_data_.instance_id()),
182 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
183 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000184 return -1;
185 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000186
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000187 // Deregister the ViEEncoder if no other channel is using it.
188 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
189 if (cs.ChannelUsingViEEncoder(video_channel) == false) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000190 ViEInputManagerScoped is(*(shared_data_.input_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000191 ViEFrameProviderBase* provider = is.FrameProvider(vie_encoder);
192 if (provider) {
193 provider->DeregisterFrameCallback(vie_encoder);
194 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000195 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000196 }
197
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000198 if (shared_data_.channel_manager()->DeleteChannel(video_channel) == -1) {
199 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000200 "%s: Could not delete channel %d", __FUNCTION__,
201 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000202 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000203 return -1;
204 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000205 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000206 "%s: channel deleted: %d", __FUNCTION__, video_channel);
207 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000208}
209
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000210int ViEBaseImpl::ConnectAudioChannel(const int video_channel,
211 const int audio_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000212 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000213 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000214 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000215 if (!cs.Channel(video_channel)) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000216 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000217 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000218 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000219 return -1;
220 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000221
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000222 if (shared_data_.channel_manager()->ConnectVoiceChannel(video_channel,
223 audio_channel) != 0) {
224 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000225 return -1;
226 }
227 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000228}
229
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000230int ViEBaseImpl::DisconnectAudioChannel(const int video_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()->DisconnectVoiceChannel(
242 video_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::StartSend(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000250 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
251 ViEId(shared_data_.instance_id(), video_channel),
252 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000253
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000254 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000255 ViEChannel* vie_channel = cs.Channel(video_channel);
256 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000257 WEBRTC_TRACE(kTraceError, kTraceVideo,
258 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000259 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000260 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000261 return -1;
262 }
mflodman@webrtc.org1a739ba2012-02-28 16:11:33 +0000263
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000264 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000265 assert(vie_encoder != NULL);
266 if (vie_encoder->Owner() != video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000267 WEBRTC_TRACE(kTraceError, kTraceVideo,
268 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000269 "Can't start ssend on a receive only channel.");
270 shared_data_.SetLastError(kViEBaseReceiveOnlyChannel);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000271 return -1;
272 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000273
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000274 // Pause and trigger a key frame.
275 vie_encoder->Pause();
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000276 int32_t error = vie_channel->StartSend();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000277 if (error != 0) {
278 vie_encoder->Restart();
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000279 WEBRTC_TRACE(kTraceError, kTraceVideo,
280 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000281 "%s: Could not start sending on channel %d", __FUNCTION__,
282 video_channel);
283 if (error == kViEBaseAlreadySending) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000284 shared_data_.SetLastError(kViEBaseAlreadySending);
niklase@google.com470e71d2011-07-07 08:21:25 +0000285 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000286 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000287 return -1;
288 }
289 vie_encoder->SendKeyFrame();
290 vie_encoder->Restart();
291 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000292}
293
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000294int ViEBaseImpl::StopSend(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000295 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
296 ViEId(shared_data_.instance_id(), video_channel),
297 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000298
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000299 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000300 ViEChannel* vie_channel = cs.Channel(video_channel);
301 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000302 WEBRTC_TRACE(kTraceError, kTraceVideo,
303 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000304 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000305 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000306 return -1;
307 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000308
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000309 int32_t error = vie_channel->StopSend();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000310 if (error != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000311 WEBRTC_TRACE(kTraceError, kTraceVideo,
312 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000313 "%s: Could not stop sending on channel %d", __FUNCTION__,
314 video_channel);
315 if (error == kViEBaseNotSending) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000316 shared_data_.SetLastError(kViEBaseNotSending);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000317 } else {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000318 shared_data_.SetLastError(kViEBaseUnknownError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000319 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000320 return -1;
321 }
322 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000323}
324
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000325int ViEBaseImpl::StartReceive(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000326 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
327 ViEId(shared_data_.instance_id(), video_channel),
328 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000329
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000330 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000331 ViEChannel* vie_channel = cs.Channel(video_channel);
332 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000333 WEBRTC_TRACE(kTraceError, kTraceVideo,
334 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000335 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000336 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000337 return -1;
338 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000339 if (vie_channel->StartReceive() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000340 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000341 return -1;
342 }
343 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000344}
345
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000346int ViEBaseImpl::StopReceive(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000347 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
348 ViEId(shared_data_.instance_id(), video_channel),
349 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000350
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000351 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000352 ViEChannel* vie_channel = cs.Channel(video_channel);
353 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000354 WEBRTC_TRACE(kTraceError, kTraceVideo,
355 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000356 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000357 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000358 return -1;
359 }
360 if (vie_channel->StopReceive() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000361 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000362 return -1;
363 }
364 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000365}
366
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000367int ViEBaseImpl::GetVersion(char version[1024]) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000368 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
niklase@google.com470e71d2011-07-07 08:21:25 +0000369 "GetVersion(version=?)");
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000370 assert(kViEVersionMaxMessageSize == 1024);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000371 if (!version) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000372 shared_data_.SetLastError(kViEBaseInvalidArgument);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000373 return -1;
374 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000375
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000376 // Add WebRTC Version.
377 std::stringstream version_stream;
elham@webrtc.org5adc8972013-11-06 22:27:51 +0000378 version_stream << "VideoEngine 3.46.0" << std::endl;
niklase@google.com470e71d2011-07-07 08:21:25 +0000379
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000380 // Add build info.
381 version_stream << "Build: svn:" << WEBRTC_SVNREVISION << " " << BUILDINFO
382 << std::endl;
niklase@google.com470e71d2011-07-07 08:21:25 +0000383
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000384#ifdef WEBRTC_EXTERNAL_TRANSPORT
385 version_stream << "External transport build" << std::endl;
386#endif
387 int version_length = version_stream.tellp();
388 assert(version_length < 1024);
389 memcpy(version, version_stream.str().c_str(), version_length);
leozwang@webrtc.org6c08f262012-07-13 22:00:16 +0000390 version[version_length] = '\0';
niklase@google.com470e71d2011-07-07 08:21:25 +0000391
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000392 WEBRTC_TRACE(kTraceStateInfo, kTraceVideo,
393 ViEId(shared_data_.instance_id()), "GetVersion() => %s",
394 version);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000395 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000396}
397
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000398int ViEBaseImpl::LastError() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000399 return shared_data_.LastErrorInternal();
niklase@google.com470e71d2011-07-07 08:21:25 +0000400}
401
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000402int ViEBaseImpl::CreateChannel(int& video_channel, // NOLINT
403 int original_channel, bool sender) {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000404 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
405 if (!cs.Channel(original_channel)) {
406 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
407 "%s - original_channel does not exist.", __FUNCTION__,
408 shared_data_.instance_id());
409 shared_data_.SetLastError(kViEBaseInvalidChannelId);
410 return -1;
411 }
412
mflodman@webrtc.orgab2610f2012-06-29 10:05:28 +0000413 if (shared_data_.channel_manager()->CreateChannel(&video_channel,
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000414 original_channel,
415 sender) == -1) {
416 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
417 "%s: Could not create channel", __FUNCTION__);
418 video_channel = -1;
419 shared_data_.SetLastError(kViEBaseChannelCreationFailed);
420 return -1;
421 }
422 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
423 "%s: channel created: %d", __FUNCTION__, video_channel);
424 return 0;
425}
426
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000427} // namespace webrtc