blob: 9581fb7f2cf203d56567febd2c69f19c932e810c [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
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000013#include <map>
14
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +000015#include "webrtc/system_wrappers/interface/logging.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000016#include "webrtc/video_engine/include/vie_errors.h"
17#include "webrtc/video_engine/vie_capturer.h"
18#include "webrtc/video_engine/vie_channel.h"
19#include "webrtc/video_engine/vie_channel_manager.h"
20#include "webrtc/video_engine/vie_defines.h"
21#include "webrtc/video_engine/vie_encoder.h"
22#include "webrtc/video_engine/vie_impl.h"
23#include "webrtc/video_engine/vie_input_manager.h"
24#include "webrtc/video_engine/vie_shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000025
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000026namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000027
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000028class CpuOveruseObserver;
29
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000030ViECapture* ViECapture::GetInterface(VideoEngine* video_engine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000031#ifdef WEBRTC_VIDEO_ENGINE_CAPTURE_API
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000032 if (!video_engine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000033 return NULL;
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000034 }
andrew@webrtc.orgd72262d2013-05-09 02:12:07 +000035 VideoEngineImpl* vie_impl = static_cast<VideoEngineImpl*>(video_engine);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000036 ViECaptureImpl* vie_capture_impl = vie_impl;
37 // Increase ref count.
38 (*vie_capture_impl)++;
39 return vie_capture_impl;
40#else
41 return NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +000042#endif
43}
44
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000045int ViECaptureImpl::Release() {
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000046 // Decrease ref count
47 (*this)--;
niklase@google.com470e71d2011-07-07 08:21:25 +000048
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000049 int32_t ref_count = GetCount();
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000050 if (ref_count < 0) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +000051 LOG(LS_WARNING) << "ViECapture released too many times.";
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000052 shared_data_->SetLastError(kViEAPIDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000053 return -1;
54 }
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000055 return ref_count;
niklase@google.com470e71d2011-07-07 08:21:25 +000056}
57
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000058ViECaptureImpl::ViECaptureImpl(ViESharedData* shared_data)
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +000059 : shared_data_(shared_data) {}
niklase@google.com470e71d2011-07-07 08:21:25 +000060
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +000061ViECaptureImpl::~ViECaptureImpl() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000062
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000063int ViECaptureImpl::NumberOfCaptureDevices() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000064 return shared_data_->input_manager()->NumberOfCaptureDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +000065}
66
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000067
68int ViECaptureImpl::GetCaptureDevice(unsigned int list_number,
69 char* device_nameUTF8,
70 unsigned int device_nameUTF8Length,
71 char* unique_idUTF8,
72 unsigned int unique_idUTF8Length) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000073 return shared_data_->input_manager()->GetDeviceName(
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000074 list_number,
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000075 device_nameUTF8, device_nameUTF8Length,
76 unique_idUTF8, unique_idUTF8Length);
niklase@google.com470e71d2011-07-07 08:21:25 +000077}
78
niklase@google.com470e71d2011-07-07 08:21:25 +000079int ViECaptureImpl::AllocateCaptureDevice(
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000080 const char* unique_idUTF8,
81 const unsigned int unique_idUTF8Length,
82 int& capture_id) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +000083 LOG(LS_INFO) << "AllocateCaptureDevice " << unique_idUTF8;
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000084 const int32_t result =
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000085 shared_data_->input_manager()->CreateCaptureDevice(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000086 unique_idUTF8,
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000087 static_cast<const uint32_t>(unique_idUTF8Length),
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000088 capture_id);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000089 if (result != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000090 shared_data_->SetLastError(result);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000091 return -1;
92 }
93 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000094}
95
niklase@google.com470e71d2011-07-07 08:21:25 +000096int ViECaptureImpl::AllocateExternalCaptureDevice(
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000097 int& capture_id, ViEExternalCapture*& external_capture) {
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000098 const int32_t result =
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000099 shared_data_->input_manager()->CreateExternalCaptureDevice(
100 external_capture, capture_id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000102 if (result != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000103 shared_data_->SetLastError(result);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000104 return -1;
105 }
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000106 LOG(LS_INFO) << "External capture device allocated: " << capture_id;
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000107 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000108}
109
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000110int ViECaptureImpl::AllocateCaptureDevice(
111 VideoCaptureModule& capture_module, int& capture_id) { // NOLINT
mflodman@webrtc.org4dee3092013-05-16 11:13:18 +0000112 int32_t result = shared_data_->input_manager()->CreateCaptureDevice(
113 &capture_module, capture_id);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000114 if (result != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000115 shared_data_->SetLastError(result);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000116 return -1;
117 }
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000118 LOG(LS_INFO) << "External capture device, by module, allocated: "
119 << capture_id;
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000120 return 0;
121}
122
123
124int ViECaptureImpl::ReleaseCaptureDevice(const int capture_id) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000125 LOG(LS_INFO) << "ReleaseCaptureDevice " << capture_id;
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000126 {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000127 ViEInputManagerScoped is((*(shared_data_->input_manager())));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000128 ViECapturer* vie_capture = is.Capture(capture_id);
129 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000130 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000131 return -1;
132 }
133 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000134 return shared_data_->input_manager()->DestroyCaptureDevice(capture_id);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000135}
136
137int ViECaptureImpl::ConnectCaptureDevice(const int capture_id,
138 const int video_channel) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000139 LOG(LS_INFO) << "Connect capture id " << capture_id
140 << " to channel " << video_channel;
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000141
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000142 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000143 ViECapturer* vie_capture = is.Capture(capture_id);
144 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000145 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000146 return -1;
147 }
148
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000149 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000150 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
151 if (!vie_encoder) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000152 LOG(LS_ERROR) << "Channel doesn't exist.";
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000153 shared_data_->SetLastError(kViECaptureDeviceInvalidChannelId);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000154 return -1;
155 }
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000156 if (vie_encoder->Owner() != video_channel) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000157 LOG(LS_ERROR) << "Can't connect capture device to a receive device.";
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000158 shared_data_->SetLastError(kViECaptureDeviceInvalidChannelId);
159 return -1;
160 }
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000161 // Check if the encoder already has a connected frame provider
162 if (is.FrameProvider(vie_encoder) != NULL) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000163 LOG(LS_ERROR) << "Channel already connected to capture device.";
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000164 shared_data_->SetLastError(kViECaptureDeviceAlreadyConnected);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000165 return -1;
166 }
mflodman@webrtc.org3ba883f2013-06-07 13:57:57 +0000167 if (vie_capture->RegisterFrameCallback(video_channel, vie_encoder) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000168 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000169 return -1;
170 }
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +0000171 std::map<int, CpuOveruseObserver*>::iterator it =
172 shared_data_->overuse_observers()->find(video_channel);
173 if (it != shared_data_->overuse_observers()->end()) {
174 vie_capture->RegisterCpuOveruseObserver(it->second);
175 }
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000176 return 0;
177}
178
179
180int ViECaptureImpl::DisconnectCaptureDevice(const int video_channel) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000181 LOG(LS_INFO) << "DisconnectCaptureDevice " << video_channel;
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000182
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000183 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000184 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
185 if (!vie_encoder) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000186 LOG(LS_ERROR) << "Channel doesn't exist.";
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000187 shared_data_->SetLastError(kViECaptureDeviceInvalidChannelId);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000188 return -1;
189 }
190
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000191 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000192 ViEFrameProviderBase* frame_provider = is.FrameProvider(vie_encoder);
193 if (!frame_provider) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000194 shared_data_->SetLastError(kViECaptureDeviceNotConnected);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000195 return -1;
196 }
197 if (frame_provider->Id() < kViECaptureIdBase ||
198 frame_provider->Id() > kViECaptureIdMax) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000199 shared_data_->SetLastError(kViECaptureDeviceNotConnected);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000200 return -1;
201 }
202
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +0000203 ViECapturer* vie_capture = is.Capture(frame_provider->Id());
204 assert(vie_capture);
205 vie_capture->RegisterCpuOveruseObserver(NULL);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000206 if (frame_provider->DeregisterFrameCallback(vie_encoder) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000207 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000208 return -1;
209 }
210
211 return 0;
212}
213
214int ViECaptureImpl::StartCapture(const int capture_id,
mflodman@webrtc.orge5297d22012-01-17 12:44:41 +0000215 const CaptureCapability& capture_capability) {
asapersson@webrtc.org46106f22014-04-25 07:02:52 +0000216 LOG(LS_INFO) << "StartCapture " << capture_id;
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000217
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000218 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000219 ViECapturer* vie_capture = is.Capture(capture_id);
220 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000221 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000222 return -1;
223 }
224 if (vie_capture->Started()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000225 shared_data_->SetLastError(kViECaptureDeviceAlreadyStarted);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000226 return -1;
227 }
228 if (vie_capture->Start(capture_capability) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000229 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000230 return -1;
231 }
232 return 0;
233}
234
235int ViECaptureImpl::StopCapture(const int capture_id) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000236 LOG(LS_INFO) << "StopCapture " << capture_id;
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000237
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000238 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000239 ViECapturer* vie_capture = is.Capture(capture_id);
240 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000241 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000242 return -1;
243 }
244 if (!vie_capture->Started()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000245 shared_data_->SetLastError(kViECaptureDeviceNotStarted);
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000246 return 0;
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000247 }
248 if (vie_capture->Stop() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000249 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000250 return -1;
251 }
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000252 return 0;
253}
254
255int ViECaptureImpl::SetRotateCapturedFrames(
256 const int capture_id,
257 const RotateCapturedFrame rotation) {
258 int i_rotation = -1;
259 switch (rotation) {
260 case RotateCapturedFrame_0:
261 i_rotation = 0;
262 break;
263 case RotateCapturedFrame_90:
264 i_rotation = 90;
265 break;
266 case RotateCapturedFrame_180:
267 i_rotation = 180;
268 break;
269 case RotateCapturedFrame_270:
270 i_rotation = 270;
271 break;
272 }
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000273 LOG(LS_INFO) << "SetRotateCaptureFrames for " << capture_id
274 << ", rotation " << i_rotation;
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000275
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000276 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000277 ViECapturer* vie_capture = is.Capture(capture_id);
278 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000279 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000280 return -1;
281 }
282 if (vie_capture->SetRotateCapturedFrames(rotation) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000283 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000284 return -1;
285 }
286 return 0;
287}
288
289int ViECaptureImpl::SetCaptureDelay(const int capture_id,
290 const unsigned int capture_delay_ms) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000291 LOG(LS_INFO) << "SetCaptureDelay " << capture_delay_ms
292 << ", for device " << capture_id;
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000293
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 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000298 return -1;
299 }
300
301 if (vie_capture->SetCaptureDelay(capture_delay_ms) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000302 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000303 return -1;
304 }
305 return 0;
306}
307
308int ViECaptureImpl::NumberOfCapabilities(
309 const char* unique_idUTF8,
310 const unsigned int unique_idUTF8Length) {
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000311
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000312#if defined(WEBRTC_MAC)
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000313 // TODO(mflodman) Move to capture module!
314 // QTKit framework handles all capabilities and capture settings
315 // automatically (mandatory).
316 // Thus this function cannot be supported on the Mac platform.
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000317 shared_data_->SetLastError(kViECaptureDeviceMacQtkitNotSupported);
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000318 LOG_F(LS_ERROR) << "API not supported on Mac OS X.";
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000319 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000320#endif
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000321 return shared_data_->input_manager()->NumberOfCaptureCapabilities(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000322 unique_idUTF8);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000323}
324
325
326int ViECaptureImpl::GetCaptureCapability(const char* unique_idUTF8,
327 const unsigned int unique_idUTF8Length,
328 const unsigned int capability_number,
329 CaptureCapability& capability) {
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000330
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000331#if defined(WEBRTC_MAC)
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000332 // TODO(mflodman) Move to capture module!
333 // QTKit framework handles all capabilities and capture settings
334 // automatically (mandatory).
335 // Thus this function cannot be supported on the Mac platform.
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000336 LOG_F(LS_ERROR) << "API not supported on Mac OS X.";
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000337 shared_data_->SetLastError(kViECaptureDeviceMacQtkitNotSupported);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000338 return -1;
339#endif
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000340 if (shared_data_->input_manager()->GetCaptureCapability(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000341 unique_idUTF8, capability_number, capability) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000342 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000343 return -1;
344 }
345 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000346}
347
348int ViECaptureImpl::ShowCaptureSettingsDialogBox(
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000349 const char* unique_idUTF8,
350 const unsigned int unique_idUTF8Length,
351 const char* dialog_title,
352 void* parent_window,
353 const unsigned int x,
354 const unsigned int y) {
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000355#if defined(WEBRTC_MAC)
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000356 // TODO(mflodman) Move to capture module
357 // QTKit framework handles all capabilities and capture settings
358 // automatically (mandatory).
359 // Thus this function cannot be supported on the Mac platform.
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000360 shared_data_->SetLastError(kViECaptureDeviceMacQtkitNotSupported);
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000361 LOG_F(LS_ERROR) << "API not supported on Mac OS X.";
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000362 return -1;
363#endif
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000364 return shared_data_->input_manager()->DisplayCaptureSettingsDialogBox(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000365 unique_idUTF8, dialog_title,
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000366 parent_window, x, y);
367}
368
369int ViECaptureImpl::GetOrientation(const char* unique_idUTF8,
370 RotateCapturedFrame& orientation) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000371 if (shared_data_->input_manager()->GetOrientation(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000372 unique_idUTF8,
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000373 orientation) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000374 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000375 return -1;
376 }
377 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000378}
379
niklase@google.com470e71d2011-07-07 08:21:25 +0000380
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000381int ViECaptureImpl::EnableBrightnessAlarm(const int capture_id,
382 const bool enable) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000383 LOG(LS_INFO) << "EnableBrightnessAlarm for device " << capture_id
384 << ", status " << enable;
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000385 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000386 ViECapturer* vie_capture = is.Capture(capture_id);
387 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000388 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000389 return -1;
390 }
391 if (vie_capture->EnableBrightnessAlarm(enable) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000392 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000393 return -1;
394 }
395 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000396}
397
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000398int ViECaptureImpl::RegisterObserver(const int capture_id,
399 ViECaptureObserver& observer) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000400 LOG(LS_INFO) << "Register capture observer " << capture_id;
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000401 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000402 ViECapturer* vie_capture = is.Capture(capture_id);
403 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000404 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000405 return -1;
406 }
407 if (vie_capture->IsObserverRegistered()) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000408 LOG_F(LS_ERROR) << "Observer already registered.";
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000409 shared_data_->SetLastError(kViECaptureObserverAlreadyRegistered);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000410 return -1;
411 }
mflodman@webrtc.org8baed512012-06-21 12:11:50 +0000412 if (vie_capture->RegisterObserver(&observer) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000413 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000414 return -1;
415 }
416 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000417}
418
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000419int ViECaptureImpl::DeregisterObserver(const int capture_id) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000420 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000421 ViECapturer* vie_capture = is.Capture(capture_id);
422 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000423 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000424 return -1;
425 }
426 if (!vie_capture->IsObserverRegistered()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000427 shared_data_->SetLastError(kViECaptureDeviceObserverNotRegistered);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000428 return -1;
429 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000430
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000431 if (vie_capture->DeRegisterObserver() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000432 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000433 return -1;
434 }
435 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000436}
437
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000438} // namespace webrtc