blob: 35fd26f8b5b7b50b58ceb8df4cee0af06b6c922d [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>
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +000015#include <utility>
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +000016
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000017#include "webrtc/engine_configurations.h"
18#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
19#include "webrtc/modules/video_coding/main/interface/video_coding.h"
20#include "webrtc/modules/video_processing/main/interface/video_processing.h"
andrew@webrtc.org9841d922012-10-31 05:22:11 +000021#include "webrtc/modules/video_render/include/video_render.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000022#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
23#include "webrtc/system_wrappers/interface/trace.h"
24#include "webrtc/video_engine/include/vie_errors.h"
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000025#include "webrtc/video_engine/vie_capturer.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000026#include "webrtc/video_engine/vie_channel.h"
27#include "webrtc/video_engine/vie_channel_manager.h"
28#include "webrtc/video_engine/vie_defines.h"
29#include "webrtc/video_engine/vie_encoder.h"
30#include "webrtc/video_engine/vie_impl.h"
31#include "webrtc/video_engine/vie_input_manager.h"
32#include "webrtc/video_engine/vie_shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000033
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000034namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000035
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000036ViEBase* ViEBase::GetInterface(VideoEngine* video_engine) {
37 if (!video_engine) {
38 return NULL;
39 }
andrew@webrtc.orgd72262d2013-05-09 02:12:07 +000040 VideoEngineImpl* vie_impl = static_cast<VideoEngineImpl*>(video_engine);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000041 ViEBaseImpl* vie_base_impl = vie_impl;
42 (*vie_base_impl)++; // Increase ref count.
niklase@google.com470e71d2011-07-07 08:21:25 +000043
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000044 return vie_base_impl;
niklase@google.com470e71d2011-07-07 08:21:25 +000045}
46
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000047int ViEBaseImpl::Release() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000048 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_.instance_id(),
niklase@google.com470e71d2011-07-07 08:21:25 +000049 "ViEBase::Release()");
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000050 (*this)--; // Decrease ref count.
niklase@google.com470e71d2011-07-07 08:21:25 +000051
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000052 int32_t ref_count = GetCount();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000053 if (ref_count < 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000054 WEBRTC_TRACE(kTraceWarning, kTraceVideo, shared_data_.instance_id(),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000055 "ViEBase release too many times");
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000056 shared_data_.SetLastError(kViEAPIDoesNotExist);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000057 return -1;
58 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000059 WEBRTC_TRACE(kTraceInfo, kTraceVideo, shared_data_.instance_id(),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000060 "ViEBase reference count: %d", ref_count);
61 return ref_count;
niklase@google.com470e71d2011-07-07 08:21:25 +000062}
63
andresp@webrtc.org7707d062013-05-13 10:50:50 +000064ViEBaseImpl::ViEBaseImpl(const Config& config)
65 : shared_data_(config) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000066 WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_.instance_id(),
niklase@google.com470e71d2011-07-07 08:21:25 +000067 "ViEBaseImpl::ViEBaseImpl() Ctor");
68}
69
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000070ViEBaseImpl::~ViEBaseImpl() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000071 WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_.instance_id(),
niklase@google.com470e71d2011-07-07 08:21:25 +000072 "ViEBaseImpl::ViEBaseImpl() Dtor");
niklase@google.com470e71d2011-07-07 08:21:25 +000073}
74
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000075int ViEBaseImpl::Init() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000076 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_.instance_id(),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000077 "Init");
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000078 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000079}
80
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000081int ViEBaseImpl::SetVoiceEngine(VoiceEngine* voice_engine) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000082 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000083 "%s", __FUNCTION__);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000084 if (shared_data_.channel_manager()->SetVoiceEngine(voice_engine) != 0) {
85 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +000086 return -1;
87 }
88 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000089}
90
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000091int ViEBaseImpl::RegisterCpuOveruseObserver(int video_channel,
92 CpuOveruseObserver* observer) {
93 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
94 ViEChannel* vie_channel = cs.Channel(video_channel);
95 if (!vie_channel) {
96 WEBRTC_TRACE(kTraceError,
97 kTraceVideo,
98 ViEId(shared_data_.instance_id()),
99 "%s: channel %d doesn't exist",
100 __FUNCTION__,
101 video_channel);
102 shared_data_.SetLastError(kViEBaseInvalidChannelId);
103 return -1;
104 }
105 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
106 assert(vie_encoder);
107
108 ViEInputManagerScoped is(*(shared_data_.input_manager()));
109 ViEFrameProviderBase* provider = is.FrameProvider(vie_encoder);
110 if (provider) {
111 ViECapturer* capturer = is.Capture(provider->Id());
112 assert(capturer);
113 capturer->RegisterCpuOveruseObserver(observer);
114 }
115
116 shared_data_.overuse_observers()->insert(
117 std::pair<int, CpuOveruseObserver*>(video_channel, observer));
118 return 0;
119}
120
asapersson@webrtc.orgc7ff8f92013-11-26 11:12:33 +0000121int ViEBaseImpl::CpuOveruseMeasures(int video_channel,
122 int* capture_jitter_ms,
asapersson@webrtc.org9e5b0342013-12-04 13:47:44 +0000123 int* avg_encode_time_ms,
124 int* encode_usage_percent,
125 int* capture_queue_delay_ms_per_s) {
asapersson@webrtc.orgb24d3352013-11-20 13:51:40 +0000126 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
127 ViEChannel* vie_channel = cs.Channel(video_channel);
128 if (!vie_channel) {
129 WEBRTC_TRACE(kTraceError,
130 kTraceVideo,
131 ViEId(shared_data_.instance_id()),
132 "%s: channel %d doesn't exist",
133 __FUNCTION__,
134 video_channel);
135 shared_data_.SetLastError(kViEBaseInvalidChannelId);
136 return -1;
137 }
138 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
139 assert(vie_encoder);
140
141 ViEInputManagerScoped is(*(shared_data_.input_manager()));
142 ViEFrameProviderBase* provider = is.FrameProvider(vie_encoder);
143 if (provider) {
144 ViECapturer* capturer = is.Capture(provider->Id());
145 if (capturer) {
asapersson@webrtc.org9e5b0342013-12-04 13:47:44 +0000146 capturer->CpuOveruseMeasures(capture_jitter_ms,
147 avg_encode_time_ms,
148 encode_usage_percent,
149 capture_queue_delay_ms_per_s);
asapersson@webrtc.orgb24d3352013-11-20 13:51:40 +0000150 return 0;
151 }
152 }
153 return -1;
154}
155
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000156int ViEBaseImpl::CreateChannel(int& video_channel) { // NOLINT
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000157 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000158 "%s", __FUNCTION__);
mflodman@webrtc.orgab2610f2012-06-29 10:05:28 +0000159 if (shared_data_.channel_manager()->CreateChannel(&video_channel) == -1) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000160 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000161 "%s: Could not create channel", __FUNCTION__);
162 video_channel = -1;
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000163 shared_data_.SetLastError(kViEBaseChannelCreationFailed);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000164 return -1;
165 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000166 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000167 "%s: channel created: %d", __FUNCTION__, video_channel);
168 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000169}
170
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000171int ViEBaseImpl::CreateChannel(int& video_channel, // NOLINT
172 int original_channel) {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000173 return CreateChannel(video_channel, original_channel, true);
174}
niklase@google.com470e71d2011-07-07 08:21:25 +0000175
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000176int ViEBaseImpl::CreateReceiveChannel(int& video_channel, // NOLINT
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000177 int original_channel) {
178 return CreateChannel(video_channel, original_channel, false);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000179}
niklase@google.com470e71d2011-07-07 08:21:25 +0000180
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000181int ViEBaseImpl::DeleteChannel(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000182 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000183 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000184 {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000185 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000186 ViEChannel* vie_channel = cs.Channel(video_channel);
187 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000188 WEBRTC_TRACE(kTraceError, kTraceVideo,
189 ViEId(shared_data_.instance_id()),
190 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
191 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000192 return -1;
193 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000194
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000195 // Deregister the ViEEncoder if no other channel is using it.
196 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
197 if (cs.ChannelUsingViEEncoder(video_channel) == false) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000198 ViEInputManagerScoped is(*(shared_data_.input_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000199 ViEFrameProviderBase* provider = is.FrameProvider(vie_encoder);
200 if (provider) {
201 provider->DeregisterFrameCallback(vie_encoder);
202 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000203 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000204 }
205
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000206 if (shared_data_.channel_manager()->DeleteChannel(video_channel) == -1) {
207 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000208 "%s: Could not delete channel %d", __FUNCTION__,
209 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000210 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000211 return -1;
212 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000213 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000214 "%s: channel deleted: %d", __FUNCTION__, video_channel);
215 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000216}
217
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000218int ViEBaseImpl::ConnectAudioChannel(const int video_channel,
219 const int audio_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000220 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000221 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000222 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000223 if (!cs.Channel(video_channel)) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000224 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000225 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000226 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000227 return -1;
228 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000229
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000230 if (shared_data_.channel_manager()->ConnectVoiceChannel(video_channel,
231 audio_channel) != 0) {
232 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000233 return -1;
234 }
235 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000236}
237
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000238int ViEBaseImpl::DisconnectAudioChannel(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000239 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000240 "%s(%d)", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000241 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000242 if (!cs.Channel(video_channel)) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000243 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000244 "%s: channel %d doesn't exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000245 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000246 return -1;
247 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000248
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000249 if (shared_data_.channel_manager()->DisconnectVoiceChannel(
250 video_channel) != 0) {
251 shared_data_.SetLastError(kViEBaseVoEFailure);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000252 return -1;
253 }
254 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000255}
256
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000257int ViEBaseImpl::StartSend(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000258 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
259 ViEId(shared_data_.instance_id(), video_channel),
260 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000261
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000262 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000263 ViEChannel* vie_channel = cs.Channel(video_channel);
264 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000265 WEBRTC_TRACE(kTraceError, kTraceVideo,
266 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000267 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000268 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000269 return -1;
270 }
mflodman@webrtc.org1a739ba2012-02-28 16:11:33 +0000271
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000272 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000273 assert(vie_encoder != NULL);
274 if (vie_encoder->Owner() != video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000275 WEBRTC_TRACE(kTraceError, kTraceVideo,
276 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000277 "Can't start ssend on a receive only channel.");
278 shared_data_.SetLastError(kViEBaseReceiveOnlyChannel);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000279 return -1;
280 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000281
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000282 // Pause and trigger a key frame.
283 vie_encoder->Pause();
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000284 int32_t error = vie_channel->StartSend();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000285 if (error != 0) {
286 vie_encoder->Restart();
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000287 WEBRTC_TRACE(kTraceError, kTraceVideo,
288 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000289 "%s: Could not start sending on channel %d", __FUNCTION__,
290 video_channel);
291 if (error == kViEBaseAlreadySending) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000292 shared_data_.SetLastError(kViEBaseAlreadySending);
niklase@google.com470e71d2011-07-07 08:21:25 +0000293 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000294 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000295 return -1;
296 }
297 vie_encoder->SendKeyFrame();
298 vie_encoder->Restart();
299 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000300}
301
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000302int ViEBaseImpl::StopSend(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000303 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
304 ViEId(shared_data_.instance_id(), video_channel),
305 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000306
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000307 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000308 ViEChannel* vie_channel = cs.Channel(video_channel);
309 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000310 WEBRTC_TRACE(kTraceError, kTraceVideo,
311 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000312 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000313 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000314 return -1;
315 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000316
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000317 int32_t error = vie_channel->StopSend();
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000318 if (error != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000319 WEBRTC_TRACE(kTraceError, kTraceVideo,
320 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000321 "%s: Could not stop sending on channel %d", __FUNCTION__,
322 video_channel);
323 if (error == kViEBaseNotSending) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000324 shared_data_.SetLastError(kViEBaseNotSending);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000325 } else {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000326 shared_data_.SetLastError(kViEBaseUnknownError);
niklase@google.com470e71d2011-07-07 08:21:25 +0000327 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000328 return -1;
329 }
330 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000331}
332
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000333int ViEBaseImpl::StartReceive(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000334 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
335 ViEId(shared_data_.instance_id(), video_channel),
336 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000337
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000338 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000339 ViEChannel* vie_channel = cs.Channel(video_channel);
340 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000341 WEBRTC_TRACE(kTraceError, kTraceVideo,
342 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000343 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000344 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000345 return -1;
346 }
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000347 if (vie_channel->StartReceive() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000348 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000349 return -1;
350 }
351 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000352}
353
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000354int ViEBaseImpl::StopReceive(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000355 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
356 ViEId(shared_data_.instance_id(), video_channel),
357 "%s(channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000358
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000359 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000360 ViEChannel* vie_channel = cs.Channel(video_channel);
361 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000362 WEBRTC_TRACE(kTraceError, kTraceVideo,
363 ViEId(shared_data_.instance_id(), video_channel),
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000364 "%s: Channel %d does not exist", __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000365 shared_data_.SetLastError(kViEBaseInvalidChannelId);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000366 return -1;
367 }
368 if (vie_channel->StopReceive() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000369 shared_data_.SetLastError(kViEBaseUnknownError);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000370 return -1;
371 }
372 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000373}
374
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000375int ViEBaseImpl::GetVersion(char version[1024]) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000376 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
niklase@google.com470e71d2011-07-07 08:21:25 +0000377 "GetVersion(version=?)");
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000378 assert(kViEVersionMaxMessageSize == 1024);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000379 if (!version) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000380 shared_data_.SetLastError(kViEBaseInvalidArgument);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000381 return -1;
382 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000383
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000384 // Add WebRTC Version.
385 std::stringstream version_stream;
elham@webrtc.org326bcff2013-11-25 17:19:46 +0000386 version_stream << "VideoEngine 3.47.0" << std::endl;
niklase@google.com470e71d2011-07-07 08:21:25 +0000387
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000388 // Add build info.
andrew@webrtc.org3054ba62013-12-04 17:00:44 +0000389 version_stream << "Build: " << BUILDINFO << std::endl;
niklase@google.com470e71d2011-07-07 08:21:25 +0000390
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000391#ifdef WEBRTC_EXTERNAL_TRANSPORT
392 version_stream << "External transport build" << std::endl;
393#endif
394 int version_length = version_stream.tellp();
395 assert(version_length < 1024);
396 memcpy(version, version_stream.str().c_str(), version_length);
leozwang@webrtc.org6c08f262012-07-13 22:00:16 +0000397 version[version_length] = '\0';
niklase@google.com470e71d2011-07-07 08:21:25 +0000398
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000399 WEBRTC_TRACE(kTraceStateInfo, kTraceVideo,
400 ViEId(shared_data_.instance_id()), "GetVersion() => %s",
401 version);
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000402 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000403}
404
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000405int ViEBaseImpl::LastError() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000406 return shared_data_.LastErrorInternal();
niklase@google.com470e71d2011-07-07 08:21:25 +0000407}
408
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000409int ViEBaseImpl::CreateChannel(int& video_channel, // NOLINT
410 int original_channel, bool sender) {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000411 ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
412 if (!cs.Channel(original_channel)) {
413 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
414 "%s - original_channel does not exist.", __FUNCTION__,
415 shared_data_.instance_id());
416 shared_data_.SetLastError(kViEBaseInvalidChannelId);
417 return -1;
418 }
419
mflodman@webrtc.orgab2610f2012-06-29 10:05:28 +0000420 if (shared_data_.channel_manager()->CreateChannel(&video_channel,
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000421 original_channel,
422 sender) == -1) {
423 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
424 "%s: Could not create channel", __FUNCTION__);
425 video_channel = -1;
426 shared_data_.SetLastError(kViEBaseChannelCreationFailed);
427 return -1;
428 }
429 WEBRTC_TRACE(kTraceInfo, kTraceVideo, ViEId(shared_data_.instance_id()),
430 "%s: channel created: %d", __FUNCTION__, video_channel);
431 return 0;
432}
433
mflodman@webrtc.org27a82a62011-11-30 18:04:26 +0000434} // namespace webrtc