blob: d6ee0157aae97b06856b9f9ceb1d060ae4451874 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org1745e932012-03-01 16:30:40 +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_capture_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000013#include "webrtc/system_wrappers/interface/trace.h"
14#include "webrtc/video_engine/include/vie_errors.h"
15#include "webrtc/video_engine/vie_capturer.h"
16#include "webrtc/video_engine/vie_channel.h"
17#include "webrtc/video_engine/vie_channel_manager.h"
18#include "webrtc/video_engine/vie_defines.h"
19#include "webrtc/video_engine/vie_encoder.h"
20#include "webrtc/video_engine/vie_impl.h"
21#include "webrtc/video_engine/vie_input_manager.h"
22#include "webrtc/video_engine/vie_shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000024namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000025
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000026ViECapture* ViECapture::GetInterface(VideoEngine* video_engine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000027#ifdef WEBRTC_VIDEO_ENGINE_CAPTURE_API
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000028 if (!video_engine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000029 return NULL;
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000030 }
andrew@webrtc.orgd72262d2013-05-09 02:12:07 +000031 VideoEngineImpl* vie_impl = static_cast<VideoEngineImpl*>(video_engine);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000032 ViECaptureImpl* vie_capture_impl = vie_impl;
33 // Increase ref count.
34 (*vie_capture_impl)++;
35 return vie_capture_impl;
36#else
37 return NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +000038#endif
39}
40
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000041int ViECaptureImpl::Release() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000042 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000043 "ViECapture::Release()");
44 // Decrease ref count
45 (*this)--;
niklase@google.com470e71d2011-07-07 08:21:25 +000046
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000047 int32_t ref_count = GetCount();
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000048 if (ref_count < 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000049 WEBRTC_TRACE(kTraceWarning, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000050 "ViECapture release too many times");
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000051 shared_data_->SetLastError(kViEAPIDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000052 return -1;
53 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000054 WEBRTC_TRACE(kTraceInfo, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000055 "ViECapture reference count: %d", ref_count);
56 return ref_count;
niklase@google.com470e71d2011-07-07 08:21:25 +000057}
58
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000059ViECaptureImpl::ViECaptureImpl(ViESharedData* shared_data)
60 : shared_data_(shared_data) {
61 WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000062 "ViECaptureImpl::ViECaptureImpl() Ctor");
niklase@google.com470e71d2011-07-07 08:21:25 +000063}
64
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000065ViECaptureImpl::~ViECaptureImpl() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000066 WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000067 "ViECaptureImpl::~ViECaptureImpl() Dtor");
niklase@google.com470e71d2011-07-07 08:21:25 +000068}
69
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000070int ViECaptureImpl::NumberOfCaptureDevices() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000071 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
72 "%s", __FUNCTION__);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000073 return shared_data_->input_manager()->NumberOfCaptureDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +000074}
75
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000076
77int ViECaptureImpl::GetCaptureDevice(unsigned int list_number,
78 char* device_nameUTF8,
79 unsigned int device_nameUTF8Length,
80 char* unique_idUTF8,
81 unsigned int unique_idUTF8Length) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000082 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000083 "%s(list_number: %d)", __FUNCTION__, list_number);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000084 return shared_data_->input_manager()->GetDeviceName(
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000085 list_number,
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000086 device_nameUTF8, device_nameUTF8Length,
87 unique_idUTF8, unique_idUTF8Length);
niklase@google.com470e71d2011-07-07 08:21:25 +000088}
89
niklase@google.com470e71d2011-07-07 08:21:25 +000090int ViECaptureImpl::AllocateCaptureDevice(
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000091 const char* unique_idUTF8,
92 const unsigned int unique_idUTF8Length,
93 int& capture_id) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000094 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000095 "%s(unique_idUTF8: %s)", __FUNCTION__, unique_idUTF8);
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000096 const int32_t result =
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000097 shared_data_->input_manager()->CreateCaptureDevice(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000098 unique_idUTF8,
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000099 static_cast<const uint32_t>(unique_idUTF8Length),
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000100 capture_id);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000101 if (result != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000102 shared_data_->SetLastError(result);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000103 return -1;
104 }
105 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000106}
107
niklase@google.com470e71d2011-07-07 08:21:25 +0000108int ViECaptureImpl::AllocateExternalCaptureDevice(
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000109 int& capture_id, ViEExternalCapture*& external_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000110 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
111 "%s", __FUNCTION__);
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000112 const int32_t result =
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000113 shared_data_->input_manager()->CreateExternalCaptureDevice(
114 external_capture, capture_id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000115
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000116 if (result != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000117 shared_data_->SetLastError(result);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000118 return -1;
119 }
120 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000121}
122
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000123int ViECaptureImpl::AllocateCaptureDevice(
124 VideoCaptureModule& capture_module, int& capture_id) { // NOLINT
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000125 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
126 "%s", __FUNCTION__);
mflodman@webrtc.org4dee3092013-05-16 11:13:18 +0000127 int32_t result = shared_data_->input_manager()->CreateCaptureDevice(
128 &capture_module, capture_id);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000129 if (result != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000130 shared_data_->SetLastError(result);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000131 return -1;
132 }
133 return 0;
134}
135
136
137int ViECaptureImpl::ReleaseCaptureDevice(const int capture_id) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000138 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000139 "%s(capture_id: %d)", __FUNCTION__, capture_id);
140 {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000141 ViEInputManagerScoped is((*(shared_data_->input_manager())));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000142 ViECapturer* vie_capture = is.Capture(capture_id);
143 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000144 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000145 "%s: Capture device %d doesn't exist", __FUNCTION__,
146 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000147 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000148 return -1;
149 }
150 }
151
152 // Destroy the capture device.
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000153 return shared_data_->input_manager()->DestroyCaptureDevice(capture_id);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000154}
155
156int ViECaptureImpl::ConnectCaptureDevice(const int capture_id,
157 const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000158 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
159 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000160 "%s(capture_id: %d, video_channel: %d)", __FUNCTION__,
161 capture_id, video_channel);
162
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000163 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000164 ViECapturer* vie_capture = is.Capture(capture_id);
165 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000166 WEBRTC_TRACE(kTraceError, kTraceVideo,
167 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000168 "%s: Capture device %d doesn't exist", __FUNCTION__,
169 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000170 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000171 return -1;
172 }
173
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000174 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000175 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
176 if (!vie_encoder) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000177 WEBRTC_TRACE(kTraceError, kTraceVideo,
178 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000179 "%s: Channel %d doesn't exist", __FUNCTION__,
180 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000181 shared_data_->SetLastError(kViECaptureDeviceInvalidChannelId);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000182 return -1;
183 }
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000184 if (vie_encoder->Owner() != video_channel) {
185 WEBRTC_TRACE(kTraceError, kTraceVideo,
186 ViEId(shared_data_->instance_id(), video_channel),
187 "Can't connect capture device to a receive only channel.");
188 shared_data_->SetLastError(kViECaptureDeviceInvalidChannelId);
189 return -1;
190 }
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000191 // Check if the encoder already has a connected frame provider
192 if (is.FrameProvider(vie_encoder) != NULL) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000193 WEBRTC_TRACE(kTraceError, kTraceVideo,
194 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000195 "%s: Channel %d already connected to a capture device.",
196 __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000197 shared_data_->SetLastError(kViECaptureDeviceAlreadyConnected);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000198 return -1;
199 }
200 VideoCodec codec;
201 bool use_hardware_encoder = false;
mflodman@webrtc.orgf5e99db2012-06-27 09:49:37 +0000202 if (vie_encoder->GetEncoder(&codec) == 0) {
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000203 // Try to provide the encoder with pre-encoded frames if possible.
204 if (vie_capture->PreEncodeToViEEncoder(codec, *vie_encoder,
205 video_channel) == 0) {
206 use_hardware_encoder = true;
207 }
208 }
209 // If we don't use the camera as hardware encoder, we register the vie_encoder
210 // for callbacks.
211 if (!use_hardware_encoder &&
212 vie_capture->RegisterFrameCallback(video_channel, vie_encoder) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000213 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000214 return -1;
215 }
216 return 0;
217}
218
219
220int ViECaptureImpl::DisconnectCaptureDevice(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000221 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
222 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000223 "%s(video_channel: %d)", __FUNCTION__, video_channel);
224
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000225 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000226 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
227 if (!vie_encoder) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000228 WEBRTC_TRACE(kTraceError, kTraceVideo,
229 ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000230 "%s: Channel %d doesn't exist", __FUNCTION__,
231 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000232 shared_data_->SetLastError(kViECaptureDeviceInvalidChannelId);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000233 return -1;
234 }
235
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000236 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000237 ViEFrameProviderBase* frame_provider = is.FrameProvider(vie_encoder);
238 if (!frame_provider) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000239 WEBRTC_TRACE(kTraceWarning, kTraceVideo,
240 ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000241 "%s: No capture device connected to channel %d",
242 __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000243 shared_data_->SetLastError(kViECaptureDeviceNotConnected);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000244 return -1;
245 }
246 if (frame_provider->Id() < kViECaptureIdBase ||
247 frame_provider->Id() > kViECaptureIdMax) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000248 WEBRTC_TRACE(kTraceWarning, kTraceVideo,
249 ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000250 "%s: No capture device connected to channel %d",
251 __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000252 shared_data_->SetLastError(kViECaptureDeviceNotConnected);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000253 return -1;
254 }
255
256 if (frame_provider->DeregisterFrameCallback(vie_encoder) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000257 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000258 return -1;
259 }
260
261 return 0;
262}
263
264int ViECaptureImpl::StartCapture(const int capture_id,
mflodman@webrtc.orge5297d22012-01-17 12:44:41 +0000265 const CaptureCapability& capture_capability) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000266 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000267 "%s(capture_id: %d)", __FUNCTION__, capture_id);
268
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000269 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000270 ViECapturer* vie_capture = is.Capture(capture_id);
271 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000272 WEBRTC_TRACE(kTraceError, kTraceVideo,
273 ViEId(shared_data_->instance_id(), capture_id),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000274 "%s: Capture device %d doesn't exist", __FUNCTION__,
275 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000276 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000277 return -1;
278 }
279 if (vie_capture->Started()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000280 shared_data_->SetLastError(kViECaptureDeviceAlreadyStarted);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000281 return -1;
282 }
283 if (vie_capture->Start(capture_capability) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000284 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000285 return -1;
286 }
287 return 0;
288}
289
290int ViECaptureImpl::StopCapture(const int capture_id) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000291 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000292 "%s(capture_id: %d)", __FUNCTION__, capture_id);
293
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000294 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000295 ViECapturer* vie_capture = is.Capture(capture_id);
296 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000297 WEBRTC_TRACE(kTraceError, kTraceVideo,
298 ViEId(shared_data_->instance_id(), capture_id),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000299 "%s: Capture device %d doesn't exist", __FUNCTION__,
300 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000301 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000302 return -1;
303 }
304 if (!vie_capture->Started()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000305 shared_data_->SetLastError(kViECaptureDeviceNotStarted);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000306 return -1;
307 }
308 if (vie_capture->Stop() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000309 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000310 return -1;
311 }
312
313 return 0;
314}
315
316int ViECaptureImpl::SetRotateCapturedFrames(
317 const int capture_id,
318 const RotateCapturedFrame rotation) {
319 int i_rotation = -1;
320 switch (rotation) {
321 case RotateCapturedFrame_0:
322 i_rotation = 0;
323 break;
324 case RotateCapturedFrame_90:
325 i_rotation = 90;
326 break;
327 case RotateCapturedFrame_180:
328 i_rotation = 180;
329 break;
330 case RotateCapturedFrame_270:
331 i_rotation = 270;
332 break;
333 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000334 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000335 "%s(rotation: %d)", __FUNCTION__, i_rotation);
336
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000337 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000338 ViECapturer* vie_capture = is.Capture(capture_id);
339 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000340 WEBRTC_TRACE(kTraceError, kTraceVideo,
341 ViEId(shared_data_->instance_id(), capture_id),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000342 "%s: Capture device %d doesn't exist", __FUNCTION__,
343 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000344 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000345 return -1;
346 }
347 if (vie_capture->SetRotateCapturedFrames(rotation) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000348 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000349 return -1;
350 }
351 return 0;
352}
353
354int ViECaptureImpl::SetCaptureDelay(const int capture_id,
355 const unsigned int capture_delay_ms) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000356 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000357 "%s(capture_id: %d, capture_delay_ms %u)", __FUNCTION__,
358 capture_id, capture_delay_ms);
359
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000360 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000361 ViECapturer* vie_capture = is.Capture(capture_id);
362 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000363 WEBRTC_TRACE(kTraceError, kTraceVideo,
364 ViEId(shared_data_->instance_id(), capture_id),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000365 "%s: Capture device %d doesn't exist", __FUNCTION__,
366 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000367 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000368 return -1;
369 }
370
371 if (vie_capture->SetCaptureDelay(capture_delay_ms) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000372 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000373 return -1;
374 }
375 return 0;
376}
377
378int ViECaptureImpl::NumberOfCapabilities(
379 const char* unique_idUTF8,
380 const unsigned int unique_idUTF8Length) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000381 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000382 "%s(capture_device_name: %s)", __FUNCTION__, unique_idUTF8);
383
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000384#if defined(WEBRTC_MAC)
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000385 // TODO(mflodman) Move to capture module!
386 // QTKit framework handles all capabilities and capture settings
387 // automatically (mandatory).
388 // Thus this function cannot be supported on the Mac platform.
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000389 shared_data_->SetLastError(kViECaptureDeviceMacQtkitNotSupported);
390 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000391 "%s This API is not supported on Mac OS", __FUNCTION__,
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000392 shared_data_->instance_id());
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000393 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000394#endif
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000395 return shared_data_->input_manager()->NumberOfCaptureCapabilities(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000396 unique_idUTF8);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000397}
398
399
400int ViECaptureImpl::GetCaptureCapability(const char* unique_idUTF8,
401 const unsigned int unique_idUTF8Length,
402 const unsigned int capability_number,
403 CaptureCapability& capability) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000404 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000405 "%s(capture_device_name: %s)", __FUNCTION__, unique_idUTF8);
406
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000407#if defined(WEBRTC_MAC)
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000408 // TODO(mflodman) Move to capture module!
409 // QTKit framework handles all capabilities and capture settings
410 // automatically (mandatory).
411 // Thus this function cannot be supported on the Mac platform.
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000412 shared_data_->SetLastError(kViECaptureDeviceMacQtkitNotSupported);
413 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000414 "%s This API is not supported on Mac OS", __FUNCTION__,
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000415 shared_data_->instance_id());
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000416 return -1;
417#endif
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000418 if (shared_data_->input_manager()->GetCaptureCapability(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000419 unique_idUTF8, capability_number, capability) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000420 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000421 return -1;
422 }
423 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000424}
425
426int ViECaptureImpl::ShowCaptureSettingsDialogBox(
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000427 const char* unique_idUTF8,
428 const unsigned int unique_idUTF8Length,
429 const char* dialog_title,
430 void* parent_window,
431 const unsigned int x,
432 const unsigned int y) {
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000433#if defined(WEBRTC_MAC)
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000434 // TODO(mflodman) Move to capture module
435 // QTKit framework handles all capabilities and capture settings
436 // automatically (mandatory).
437 // Thus this function cannot be supported on the Mac platform.
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000438 shared_data_->SetLastError(kViECaptureDeviceMacQtkitNotSupported);
439 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000440 "%s This API is not supported on Mac OS", __FUNCTION__,
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000441 shared_data_->instance_id());
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000442 return -1;
443#endif
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000444 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000445 "%s capture_id (capture_device_name: %s)", __FUNCTION__,
446 unique_idUTF8);
447
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000448 return shared_data_->input_manager()->DisplayCaptureSettingsDialogBox(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000449 unique_idUTF8, dialog_title,
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000450 parent_window, x, y);
451}
452
453int ViECaptureImpl::GetOrientation(const char* unique_idUTF8,
454 RotateCapturedFrame& orientation) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000455 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000456 "%s (capture_device_name: %s)", __FUNCTION__, unique_idUTF8);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000457 if (shared_data_->input_manager()->GetOrientation(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000458 unique_idUTF8,
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000459 orientation) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000460 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000461 return -1;
462 }
463 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000464}
465
niklase@google.com470e71d2011-07-07 08:21:25 +0000466
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000467int ViECaptureImpl::EnableBrightnessAlarm(const int capture_id,
468 const bool enable) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000469 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000470 ViECapturer* vie_capture = is.Capture(capture_id);
471 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000472 WEBRTC_TRACE(kTraceError, kTraceVideo,
473 ViEId(shared_data_->instance_id(), capture_id),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000474 "%s: Capture device %d doesn't exist", __FUNCTION__,
475 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000476 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000477 return -1;
478 }
479 if (vie_capture->EnableBrightnessAlarm(enable) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000480 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000481 return -1;
482 }
483 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000484}
485
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000486int ViECaptureImpl::RegisterObserver(const int capture_id,
487 ViECaptureObserver& observer) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000488 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000489 ViECapturer* vie_capture = is.Capture(capture_id);
490 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000491 WEBRTC_TRACE(kTraceError, kTraceVideo,
492 ViEId(shared_data_->instance_id(), capture_id),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000493 "%s: Capture device %d doesn't exist", __FUNCTION__,
494 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000495 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000496 return -1;
497 }
498 if (vie_capture->IsObserverRegistered()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000499 WEBRTC_TRACE(kTraceError, kTraceVideo,
500 ViEId(shared_data_->instance_id(), capture_id),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000501 "%s: Observer already registered", __FUNCTION__);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000502 shared_data_->SetLastError(kViECaptureObserverAlreadyRegistered);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000503 return -1;
504 }
mflodman@webrtc.org8baed512012-06-21 12:11:50 +0000505 if (vie_capture->RegisterObserver(&observer) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000506 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000507 return -1;
508 }
509 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000510}
511
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000512int ViECaptureImpl::DeregisterObserver(const int capture_id) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000513 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000514 ViECapturer* vie_capture = is.Capture(capture_id);
515 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000516 WEBRTC_TRACE(kTraceError, kTraceVideo,
517 ViEId(shared_data_->instance_id(), capture_id),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000518 "%s: Capture device %d doesn't exist", __FUNCTION__,
519 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000520 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000521 return -1;
522 }
523 if (!vie_capture->IsObserverRegistered()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000524 shared_data_->SetLastError(kViECaptureDeviceObserverNotRegistered);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000525 return -1;
526 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000527
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000528 if (vie_capture->DeRegisterObserver() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000529 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000530 return -1;
531 }
532 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000533}
534
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000535} // namespace webrtc