blob: 17e9a7442f13ea8db019897446bc50203c230989 [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
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000120int ViEBaseImpl::CreateChannel(int& video_channel) { // NOLINT
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000121 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000122 "%s", __FUNCTION__);
mflodman@webrtc.orgab2610f2012-06-29 10:05:28 +0000123 if (shared_data_.channel_manager()->CreateChannel(&video_channel) == -1) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000124 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000125 "%s: Could not create channel", __FUNCTION__);
126 video_channel = -1;
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000127 shared_data_.SetLastError(kViEBaseChannelCreationFailed);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000128 return -1;
129 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000130 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000131 "%s: channel created: %d", __FUNCTION__, video_channel);
132 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000133}
134
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000135int ViEBaseImpl::CreateChannel(int& video_channel, // NOLINT
136 int original_channel) {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000137 return CreateChannel(video_channel, original_channel, true);
138}
niklase@google.com470e71d2011-07-07 08:21:25 +0000139
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000140int ViEBaseImpl::CreateReceiveChannel(int& video_channel, // NOLINT
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000141 int original_channel) {
142 return CreateChannel(video_channel, original_channel, false);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000143}
niklase@google.com470e71d2011-07-07 08:21:25 +0000144
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000145int ViEBaseImpl::DeleteChannel(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000146 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000147 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000148 {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000149 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000150 ViEChannel* vie_channel = cs.Channel(video_channel);
151 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000152 WEBRTC_TRACE(kTraceError, kTraceVideo,
153 ViEId(shared_data_.instance_id()),
154 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
155 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000156 return -1;
157 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000158
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000159 // Deregister the ViEEncoder if no other channel is using it.
160 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
161 if (cs.ChannelUsingViEEncoder(video_channel) == false) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000162 ViEInputManagerScoped is(*(shared_data_.input_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000163 ViEFrameProviderBase* provider = is.FrameProvider(vie_encoder);
164 if (provider) {
165 provider->DeregisterFrameCallback(vie_encoder);
166 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000167 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000168 }
169
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000170 if (shared_data_.channel_manager()->DeleteChannel(video_channel) == -1) {
171 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000172 "%s: Could not delete channel %d", __FUNCTION__,
173 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000174 shared_data_.SetLastError(kViEBaseUnknownError);
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 deleted: %d", __FUNCTION__, video_channel);
179 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000180}
181
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000182int ViEBaseImpl::ConnectAudioChannel(const int video_channel,
183 const int audio_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000184 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000185 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000186 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000187 if (!cs.Channel(video_channel)) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000188 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000189 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000190 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000191 return -1;
192 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000193
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000194 if (shared_data_.channel_manager()->ConnectVoiceChannel(video_channel,
195 audio_channel) != 0) {
196 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000197 return -1;
198 }
199 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000200}
201
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000202int ViEBaseImpl::DisconnectAudioChannel(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000203 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000204 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000205 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000206 if (!cs.Channel(video_channel)) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000207 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000208 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000209 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000210 return -1;
211 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000212
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000213 if (shared_data_.channel_manager()->DisconnectVoiceChannel(
214 video_channel) != 0) {
215 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000216 return -1;
217 }
218 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000219}
220
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000221int ViEBaseImpl::StartSend(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000222 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
223 ViEId(shared_data_.instance_id(), video_channel),
224 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000225
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000226 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000227 ViEChannel* vie_channel = cs.Channel(video_channel);
228 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000229 WEBRTC_TRACE(kTraceError, kTraceVideo,
230 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000231 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000232 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000233 return -1;
234 }
mflodman@webrtc.org1a739ba2012-02-28 16:11:33 +0000235
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000236 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000237 assert(vie_encoder != NULL);
238 if (vie_encoder->Owner() != video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000239 WEBRTC_TRACE(kTraceError, kTraceVideo,
240 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000241 "Can't start ssend on a receive only channel.");
242 shared_data_.SetLastError(kViEBaseReceiveOnlyChannel);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000243 return -1;
244 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000245
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000246 // Pause and trigger a key frame.
247 vie_encoder->Pause();
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000248 int32_t error = vie_channel->StartSend();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000249 if (error != 0) {
250 vie_encoder->Restart();
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000251 WEBRTC_TRACE(kTraceError, kTraceVideo,
252 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000253 "%s: Could not start sending on channel %d", __FUNCTION__,
254 video_channel);
255 if (error == kViEBaseAlreadySending) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000256 shared_data_.SetLastError(kViEBaseAlreadySending);
niklase@google.com470e71d2011-07-07 08:21:25 +0000257 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000258 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000259 return -1;
260 }
261 vie_encoder->SendKeyFrame();
262 vie_encoder->Restart();
263 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000264}
265
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000266int ViEBaseImpl::StopSend(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 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000280
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000281 int32_t error = vie_channel->StopSend();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000282 if (error != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000283 WEBRTC_TRACE(kTraceError, kTraceVideo,
284 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000285 "%s: Could not stop sending on channel %d", __FUNCTION__,
286 video_channel);
287 if (error == kViEBaseNotSending) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000288 shared_data_.SetLastError(kViEBaseNotSending);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000289 } else {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000290 shared_data_.SetLastError(kViEBaseUnknownError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000291 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000292 return -1;
293 }
294 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000295}
296
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000297int ViEBaseImpl::StartReceive(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000298 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
299 ViEId(shared_data_.instance_id(), video_channel),
300 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000301
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000302 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000303 ViEChannel* vie_channel = cs.Channel(video_channel);
304 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000305 WEBRTC_TRACE(kTraceError, kTraceVideo,
306 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000307 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000308 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000309 return -1;
310 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000311 if (vie_channel->StartReceive() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000312 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000313 return -1;
314 }
315 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000316}
317
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000318int ViEBaseImpl::StopReceive(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000319 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
320 ViEId(shared_data_.instance_id(), video_channel),
321 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000322
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000323 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000324 ViEChannel* vie_channel = cs.Channel(video_channel);
325 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000326 WEBRTC_TRACE(kTraceError, kTraceVideo,
327 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000328 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000329 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000330 return -1;
331 }
332 if (vie_channel->StopReceive() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000333 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000334 return -1;
335 }
336 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000337}
338
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000339int ViEBaseImpl::GetVersion(char version[1024]) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000340 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
niklase@google.com470e71d2011-07-07 08:21:25 +0000341 "GetVersion(version=?)");
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000342 assert(kViEVersionMaxMessageSize == 1024);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000343 if (!version) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000344 shared_data_.SetLastError(kViEBaseInvalidArgument);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000345 return -1;
346 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000347
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000348 // Add WebRTC Version.
349 std::stringstream version_stream;
elham@webrtc.org8543c1c2013-07-15 17:19:45 +0000350 version_stream << "VideoEngine 3.36.0" << std::endl;
niklase@google.com470e71d2011-07-07 08:21:25 +0000351
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000352 // Add build info.
353 version_stream << "Build: svn:" << WEBRTC_SVNREVISION << " " << BUILDINFO
354 << std::endl;
niklase@google.com470e71d2011-07-07 08:21:25 +0000355
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000356#ifdef WEBRTC_EXTERNAL_TRANSPORT
357 version_stream << "External transport build" << std::endl;
358#endif
359 int version_length = version_stream.tellp();
360 assert(version_length < 1024);
361 memcpy(version, version_stream.str().c_str(), version_length);
leozwang@webrtc.org6c08f262012-07-13 22:00:16 +0000362 version[version_length] = '\0';
niklase@google.com470e71d2011-07-07 08:21:25 +0000363
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000364 WEBRTC_TRACE(kTraceStateInfo, kTraceVideo,
365 ViEId(shared_data_.instance_id()), "GetVersion() => %s",
366 version);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000367 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000368}
369
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000370int ViEBaseImpl::LastError() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000371 return shared_data_.LastErrorInternal();
niklase@google.com470e71d2011-07-07 08:21:25 +0000372}
373
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000374int ViEBaseImpl::CreateChannel(int& video_channel, // NOLINT
375 int original_channel, bool sender) {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000376 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
377 if (!cs.Channel(original_channel)) {
378 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
379 "%s - original_channel does not exist.", __FUNCTION__,
380 shared_data_.instance_id());
381 shared_data_.SetLastError(kViEBaseInvalidChannelId);
382 return -1;
383 }
384
mflodman@webrtc.orgab2610f2012-06-29 10:05:28 +0000385 if (shared_data_.channel_manager()->CreateChannel(&video_channel,
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000386 original_channel,
387 sender) == -1) {
388 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
389 "%s: Could not create channel", __FUNCTION__);
390 video_channel = -1;
391 shared_data_.SetLastError(kViEBaseChannelCreationFailed);
392 return -1;
393 }
394 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
395 "%s: channel created: %d", __FUNCTION__, video_channel);
396 return 0;
397}
398
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000399} // namespace webrtc