blob: 85353c30acc2964734bbdb74709e2908fa346d3d [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
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000015#include "webrtc/system_wrappers/interface/trace.h"
16#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.orgb11424b2012-01-25 13:42:03 +000046 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000047 "ViECapture::Release()");
48 // Decrease ref count
49 (*this)--;
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.org605972e2011-12-16 08:59:24 +000052 if (ref_count < 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000053 WEBRTC_TRACE(kTraceWarning, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000054 "ViECapture release too many times");
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000055 shared_data_->SetLastError(kViEAPIDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000056 return -1;
57 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000058 WEBRTC_TRACE(kTraceInfo, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000059 "ViECapture reference count: %d", ref_count);
60 return ref_count;
niklase@google.com470e71d2011-07-07 08:21:25 +000061}
62
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000063ViECaptureImpl::ViECaptureImpl(ViESharedData* shared_data)
64 : shared_data_(shared_data) {
65 WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000066 "ViECaptureImpl::ViECaptureImpl() Ctor");
niklase@google.com470e71d2011-07-07 08:21:25 +000067}
68
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000069ViECaptureImpl::~ViECaptureImpl() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000070 WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000071 "ViECaptureImpl::~ViECaptureImpl() Dtor");
niklase@google.com470e71d2011-07-07 08:21:25 +000072}
73
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000074int ViECaptureImpl::NumberOfCaptureDevices() {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000075 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
76 "%s", __FUNCTION__);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000077 return shared_data_->input_manager()->NumberOfCaptureDevices();
niklase@google.com470e71d2011-07-07 08:21:25 +000078}
79
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000080
81int ViECaptureImpl::GetCaptureDevice(unsigned int list_number,
82 char* device_nameUTF8,
83 unsigned int device_nameUTF8Length,
84 char* unique_idUTF8,
85 unsigned int unique_idUTF8Length) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000086 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000087 "%s(list_number: %d)", __FUNCTION__, list_number);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000088 return shared_data_->input_manager()->GetDeviceName(
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000089 list_number,
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000090 device_nameUTF8, device_nameUTF8Length,
91 unique_idUTF8, unique_idUTF8Length);
niklase@google.com470e71d2011-07-07 08:21:25 +000092}
93
niklase@google.com470e71d2011-07-07 08:21:25 +000094int ViECaptureImpl::AllocateCaptureDevice(
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000095 const char* unique_idUTF8,
96 const unsigned int unique_idUTF8Length,
97 int& capture_id) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000098 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +000099 "%s(unique_idUTF8: %s)", __FUNCTION__, unique_idUTF8);
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000100 const int32_t result =
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000101 shared_data_->input_manager()->CreateCaptureDevice(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000102 unique_idUTF8,
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000103 static_cast<const uint32_t>(unique_idUTF8Length),
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000104 capture_id);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000105 if (result != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000106 shared_data_->SetLastError(result);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000107 return -1;
108 }
109 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000110}
111
niklase@google.com470e71d2011-07-07 08:21:25 +0000112int ViECaptureImpl::AllocateExternalCaptureDevice(
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000113 int& capture_id, ViEExternalCapture*& external_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000114 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
115 "%s", __FUNCTION__);
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000116 const int32_t result =
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000117 shared_data_->input_manager()->CreateExternalCaptureDevice(
118 external_capture, capture_id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000119
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000120 if (result != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000121 shared_data_->SetLastError(result);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000122 return -1;
123 }
124 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000125}
126
mflodman@webrtc.org9ba151b2012-06-21 10:02:13 +0000127int ViECaptureImpl::AllocateCaptureDevice(
128 VideoCaptureModule& capture_module, int& capture_id) { // NOLINT
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000129 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
130 "%s", __FUNCTION__);
mflodman@webrtc.org4dee3092013-05-16 11:13:18 +0000131 int32_t result = shared_data_->input_manager()->CreateCaptureDevice(
132 &capture_module, capture_id);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000133 if (result != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000134 shared_data_->SetLastError(result);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000135 return -1;
136 }
137 return 0;
138}
139
140
141int ViECaptureImpl::ReleaseCaptureDevice(const int capture_id) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000142 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000143 "%s(capture_id: %d)", __FUNCTION__, capture_id);
144 {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000145 ViEInputManagerScoped is((*(shared_data_->input_manager())));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000146 ViECapturer* vie_capture = is.Capture(capture_id);
147 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000148 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000149 "%s: Capture device %d doesn't exist", __FUNCTION__,
150 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000151 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000152 return -1;
153 }
154 }
155
156 // Destroy the capture device.
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000157 return shared_data_->input_manager()->DestroyCaptureDevice(capture_id);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000158}
159
160int ViECaptureImpl::ConnectCaptureDevice(const int capture_id,
161 const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000162 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
163 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000164 "%s(capture_id: %d, video_channel: %d)", __FUNCTION__,
165 capture_id, video_channel);
166
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000167 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000168 ViECapturer* vie_capture = is.Capture(capture_id);
169 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000170 WEBRTC_TRACE(kTraceError, kTraceVideo,
171 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000172 "%s: Capture device %d doesn't exist", __FUNCTION__,
173 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000174 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000175 return -1;
176 }
177
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000178 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000179 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
180 if (!vie_encoder) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000181 WEBRTC_TRACE(kTraceError, kTraceVideo,
182 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000183 "%s: Channel %d doesn't exist", __FUNCTION__,
184 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000185 shared_data_->SetLastError(kViECaptureDeviceInvalidChannelId);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000186 return -1;
187 }
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000188 if (vie_encoder->Owner() != video_channel) {
189 WEBRTC_TRACE(kTraceError, kTraceVideo,
190 ViEId(shared_data_->instance_id(), video_channel),
191 "Can't connect capture device to a receive only channel.");
192 shared_data_->SetLastError(kViECaptureDeviceInvalidChannelId);
193 return -1;
194 }
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000195 // Check if the encoder already has a connected frame provider
196 if (is.FrameProvider(vie_encoder) != NULL) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000197 WEBRTC_TRACE(kTraceError, kTraceVideo,
198 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000199 "%s: Channel %d already connected to a capture device.",
200 __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000201 shared_data_->SetLastError(kViECaptureDeviceAlreadyConnected);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000202 return -1;
203 }
mflodman@webrtc.org3ba883f2013-06-07 13:57:57 +0000204 if (vie_capture->RegisterFrameCallback(video_channel, vie_encoder) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000205 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000206 return -1;
207 }
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +0000208 std::map<int, CpuOveruseObserver*>::iterator it =
209 shared_data_->overuse_observers()->find(video_channel);
210 if (it != shared_data_->overuse_observers()->end()) {
211 vie_capture->RegisterCpuOveruseObserver(it->second);
212 }
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000213 return 0;
214}
215
216
217int ViECaptureImpl::DisconnectCaptureDevice(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000218 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
219 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000220 "%s(video_channel: %d)", __FUNCTION__, video_channel);
221
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000222 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000223 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
224 if (!vie_encoder) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000225 WEBRTC_TRACE(kTraceError, kTraceVideo,
226 ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000227 "%s: Channel %d doesn't exist", __FUNCTION__,
228 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000229 shared_data_->SetLastError(kViECaptureDeviceInvalidChannelId);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000230 return -1;
231 }
232
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000233 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000234 ViEFrameProviderBase* frame_provider = is.FrameProvider(vie_encoder);
235 if (!frame_provider) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000236 WEBRTC_TRACE(kTraceWarning, kTraceVideo,
237 ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000238 "%s: No capture device connected to channel %d",
239 __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000240 shared_data_->SetLastError(kViECaptureDeviceNotConnected);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000241 return -1;
242 }
243 if (frame_provider->Id() < kViECaptureIdBase ||
244 frame_provider->Id() > kViECaptureIdMax) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000245 WEBRTC_TRACE(kTraceWarning, kTraceVideo,
246 ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000247 "%s: No capture device connected to channel %d",
248 __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000249 shared_data_->SetLastError(kViECaptureDeviceNotConnected);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000250 return -1;
251 }
252
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +0000253 ViECapturer* vie_capture = is.Capture(frame_provider->Id());
254 assert(vie_capture);
255 vie_capture->RegisterCpuOveruseObserver(NULL);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000256 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