blob: 5c8b898b4f88cbb8c5d368301b26e0ee8abd1e21 [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"
24#include "webrtc/video_engine/vie_channel.h"
25#include "webrtc/video_engine/vie_channel_manager.h"
26#include "webrtc/video_engine/vie_defines.h"
27#include "webrtc/video_engine/vie_encoder.h"
28#include "webrtc/video_engine/vie_impl.h"
29#include "webrtc/video_engine/vie_input_manager.h"
30#include "webrtc/video_engine/vie_shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000031
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000032namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000033
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000034ViEBase* ViEBase::GetInterface(VideoEngine* video_engine) {
35 if (!video_engine) {
36 return NULL;
37 }
andrew@webrtc.orgd72262d2013-05-09 02:12:07 +000038 VideoEngineImpl* vie_impl = static_cast<VideoEngineImpl*>(video_engine);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000039 ViEBaseImpl* vie_base_impl = vie_impl;
40 (*vie_base_impl)++; // Increase ref count.
niklase@google.com470e71d2011-07-07 08:21:25 +000041
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000042 return vie_base_impl;
niklase@google.com470e71d2011-07-07 08:21:25 +000043}
44
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000045int ViEBaseImpl::Release() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000046 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_.instance_id(),
niklase@google.com470e71d2011-07-07 08:21:25 +000047 "ViEBase::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.orgb11424b2012-01-25 13:42:03 +000052 WEBRTC_TRACE(kTraceWarning, kTraceVideo, shared_data_.instance_id(),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000053 "ViEBase release too many times");
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000054 shared_data_.SetLastError(kViEAPIDoesNotExist);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000055 return -1;
56 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000057 WEBRTC_TRACE(kTraceInfo, kTraceVideo, shared_data_.instance_id(),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000058 "ViEBase reference count: %d", ref_count);
59 return ref_count;
niklase@google.com470e71d2011-07-07 08:21:25 +000060}
61
andresp@webrtc.org7707d062013-05-13 10:50:50 +000062ViEBaseImpl::ViEBaseImpl(const Config& config)
63 : shared_data_(config) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000064 WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_.instance_id(),
niklase@google.com470e71d2011-07-07 08:21:25 +000065 "ViEBaseImpl::ViEBaseImpl() Ctor");
66}
67
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000068ViEBaseImpl::~ViEBaseImpl() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000069 WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_.instance_id(),
niklase@google.com470e71d2011-07-07 08:21:25 +000070 "ViEBaseImpl::ViEBaseImpl() Dtor");
niklase@google.com470e71d2011-07-07 08:21:25 +000071}
72
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000073int ViEBaseImpl::Init() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000074 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_.instance_id(),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000075 "Init");
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000076 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000077}
78
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000079int ViEBaseImpl::SetVoiceEngine(VoiceEngine* voice_engine) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000080 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000081 "%s", __FUNCTION__);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000082 if (shared_data_.channel_manager()->SetVoiceEngine(voice_engine) != 0) {
83 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000084 return -1;
85 }
86 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000087}
88
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +000089int ViEBaseImpl::CreateChannel(int& video_channel) { // NOLINT
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000090 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000091 "%s", __FUNCTION__);
mflodman@webrtc.orgab2610f2012-06-29 10:05:28 +000092 if (shared_data_.channel_manager()->CreateChannel(&video_channel) == -1) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000093 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000094 "%s: Could not create channel", __FUNCTION__);
95 video_channel = -1;
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000096 shared_data_.SetLastError(kViEBaseChannelCreationFailed);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000097 return -1;
98 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000099 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000100 "%s: channel created: %d", __FUNCTION__, video_channel);
101 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000102}
103
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000104int ViEBaseImpl::CreateChannel(int& video_channel, // NOLINT
105 int original_channel) {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000106 return CreateChannel(video_channel, original_channel, true);
107}
niklase@google.com470e71d2011-07-07 08:21:25 +0000108
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000109int ViEBaseImpl::CreateReceiveChannel(int& video_channel, // NOLINT
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000110 int original_channel) {
111 return CreateChannel(video_channel, original_channel, false);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000112}
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000114int ViEBaseImpl::DeleteChannel(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000115 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000116 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000117 {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000118 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000119 ViEChannel* vie_channel = cs.Channel(video_channel);
120 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000121 WEBRTC_TRACE(kTraceError, kTraceVideo,
122 ViEId(shared_data_.instance_id()),
123 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
124 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000125 return -1;
126 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000127
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000128 // Deregister the ViEEncoder if no other channel is using it.
129 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
130 if (cs.ChannelUsingViEEncoder(video_channel) == false) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000131 ViEInputManagerScoped is(*(shared_data_.input_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000132 ViEFrameProviderBase* provider = is.FrameProvider(vie_encoder);
133 if (provider) {
134 provider->DeregisterFrameCallback(vie_encoder);
135 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000136 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000137 }
138
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000139 if (shared_data_.channel_manager()->DeleteChannel(video_channel) == -1) {
140 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000141 "%s: Could not delete channel %d", __FUNCTION__,
142 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000143 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000144 return -1;
145 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000146 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000147 "%s: channel deleted: %d", __FUNCTION__, video_channel);
148 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000149}
150
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000151int ViEBaseImpl::ConnectAudioChannel(const int video_channel,
152 const int audio_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000153 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000154 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000155 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000156 if (!cs.Channel(video_channel)) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000157 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000158 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000159 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000160 return -1;
161 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000162
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000163 if (shared_data_.channel_manager()->ConnectVoiceChannel(video_channel,
164 audio_channel) != 0) {
165 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000166 return -1;
167 }
168 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000169}
170
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000171int ViEBaseImpl::DisconnectAudioChannel(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000172 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000173 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000174 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000175 if (!cs.Channel(video_channel)) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000176 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000177 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000178 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000179 return -1;
180 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000181
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000182 if (shared_data_.channel_manager()->DisconnectVoiceChannel(
183 video_channel) != 0) {
184 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000185 return -1;
186 }
187 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000188}
189
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000190int ViEBaseImpl::StartSend(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000191 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
192 ViEId(shared_data_.instance_id(), video_channel),
193 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000194
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000195 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000196 ViEChannel* vie_channel = cs.Channel(video_channel);
197 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000198 WEBRTC_TRACE(kTraceError, kTraceVideo,
199 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000200 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000201 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000202 return -1;
203 }
mflodman@webrtc.org1a739ba2012-02-28 16:11:33 +0000204
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000205 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000206 assert(vie_encoder != NULL);
207 if (vie_encoder->Owner() != video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000208 WEBRTC_TRACE(kTraceError, kTraceVideo,
209 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000210 "Can't start ssend on a receive only channel.");
211 shared_data_.SetLastError(kViEBaseReceiveOnlyChannel);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000212 return -1;
213 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000214
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000215 // Pause and trigger a key frame.
216 vie_encoder->Pause();
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000217 int32_t error = vie_channel->StartSend();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000218 if (error != 0) {
219 vie_encoder->Restart();
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000220 WEBRTC_TRACE(kTraceError, kTraceVideo,
221 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000222 "%s: Could not start sending on channel %d", __FUNCTION__,
223 video_channel);
224 if (error == kViEBaseAlreadySending) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000225 shared_data_.SetLastError(kViEBaseAlreadySending);
niklase@google.com470e71d2011-07-07 08:21:25 +0000226 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000227 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000228 return -1;
229 }
230 vie_encoder->SendKeyFrame();
231 vie_encoder->Restart();
232 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000233}
234
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000235int ViEBaseImpl::StopSend(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000236 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
237 ViEId(shared_data_.instance_id(), video_channel),
238 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000239
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000240 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000241 ViEChannel* vie_channel = cs.Channel(video_channel);
242 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000243 WEBRTC_TRACE(kTraceError, kTraceVideo,
244 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000245 "%s: Channel %d does not exist", __FUNCTION__, video_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 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000249
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000250 int32_t error = vie_channel->StopSend();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000251 if (error != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000252 WEBRTC_TRACE(kTraceError, kTraceVideo,
253 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000254 "%s: Could not stop sending on channel %d", __FUNCTION__,
255 video_channel);
256 if (error == kViEBaseNotSending) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000257 shared_data_.SetLastError(kViEBaseNotSending);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000258 } else {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000259 shared_data_.SetLastError(kViEBaseUnknownError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000260 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000261 return -1;
262 }
263 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000264}
265
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000266int ViEBaseImpl::StartReceive(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000267 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
268 ViEId(shared_data_.instance_id(), video_channel),
269 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000270
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000271 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000272 ViEChannel* vie_channel = cs.Channel(video_channel);
273 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000274 WEBRTC_TRACE(kTraceError, kTraceVideo,
275 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000276 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000277 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000278 return -1;
279 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000280 if (vie_channel->StartReceive() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000281 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000282 return -1;
283 }
284 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000285}
286
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000287int ViEBaseImpl::StopReceive(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000288 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
289 ViEId(shared_data_.instance_id(), video_channel),
290 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000291
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000292 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000293 ViEChannel* vie_channel = cs.Channel(video_channel);
294 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000295 WEBRTC_TRACE(kTraceError, kTraceVideo,
296 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000297 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000298 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000299 return -1;
300 }
301 if (vie_channel->StopReceive() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000302 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000303 return -1;
304 }
305 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000306}
307
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000308int ViEBaseImpl::GetVersion(char version[1024]) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000309 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
niklase@google.com470e71d2011-07-07 08:21:25 +0000310 "GetVersion(version=?)");
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000311 assert(kViEVersionMaxMessageSize == 1024);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000312 if (!version) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000313 shared_data_.SetLastError(kViEBaseInvalidArgument);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000314 return -1;
315 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000316
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000317 // Add WebRTC Version.
318 std::stringstream version_stream;
elham@webrtc.org52b39052013-05-13 17:00:56 +0000319 version_stream << "VideoEngine 3.31.0" << std::endl;
niklase@google.com470e71d2011-07-07 08:21:25 +0000320
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000321 // Add build info.
322 version_stream << "Build: svn:" << WEBRTC_SVNREVISION << " " << BUILDINFO
323 << std::endl;
niklase@google.com470e71d2011-07-07 08:21:25 +0000324
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000325#ifdef WEBRTC_EXTERNAL_TRANSPORT
326 version_stream << "External transport build" << std::endl;
327#endif
328 int version_length = version_stream.tellp();
329 assert(version_length < 1024);
330 memcpy(version, version_stream.str().c_str(), version_length);
leozwang@webrtc.org6c08f262012-07-13 22:00:16 +0000331 version[version_length] = '\0';
niklase@google.com470e71d2011-07-07 08:21:25 +0000332
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000333 WEBRTC_TRACE(kTraceStateInfo, kTraceVideo,
334 ViEId(shared_data_.instance_id()), "GetVersion() => %s",
335 version);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000336 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000337}
338
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000339int ViEBaseImpl::LastError() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000340 return shared_data_.LastErrorInternal();
niklase@google.com470e71d2011-07-07 08:21:25 +0000341}
342
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000343int ViEBaseImpl::CreateChannel(int& video_channel, // NOLINT
344 int original_channel, bool sender) {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000345 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
346 if (!cs.Channel(original_channel)) {
347 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
348 "%s - original_channel does not exist.", __FUNCTION__,
349 shared_data_.instance_id());
350 shared_data_.SetLastError(kViEBaseInvalidChannelId);
351 return -1;
352 }
353
mflodman@webrtc.orgab2610f2012-06-29 10:05:28 +0000354 if (shared_data_.channel_manager()->CreateChannel(&video_channel,
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000355 original_channel,
356 sender) == -1) {
357 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
358 "%s: Could not create channel", __FUNCTION__);
359 video_channel = -1;
360 shared_data_.SetLastError(kViEBaseChannelCreationFailed);
361 return -1;
362 }
363 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
364 "%s: channel created: %d", __FUNCTION__, video_channel);
365 return 0;
366}
367
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000368} // namespace webrtc