blob: 28b4d19e0c5d782858b1d9fa023509c0569cf5c5 [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 }
mflodman@webrtc.org3ba883f2013-06-07 13:57:57 +0000200 if (vie_capture->RegisterFrameCallback(video_channel, vie_encoder) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000201 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000202 return -1;
203 }
204 return 0;
205}
206
207
208int ViECaptureImpl::DisconnectCaptureDevice(const int video_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000209 WEBRTC_TRACE(kTraceApiCall, kTraceVideo,
210 ViEId(shared_data_->instance_id(), video_channel),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000211 "%s(video_channel: %d)", __FUNCTION__, video_channel);
212
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000213 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000214 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
215 if (!vie_encoder) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000216 WEBRTC_TRACE(kTraceError, kTraceVideo,
217 ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000218 "%s: Channel %d doesn't exist", __FUNCTION__,
219 video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000220 shared_data_->SetLastError(kViECaptureDeviceInvalidChannelId);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000221 return -1;
222 }
223
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000224 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000225 ViEFrameProviderBase* frame_provider = is.FrameProvider(vie_encoder);
226 if (!frame_provider) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000227 WEBRTC_TRACE(kTraceWarning, kTraceVideo,
228 ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000229 "%s: No capture device connected to channel %d",
230 __FUNCTION__, video_channel);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000231 shared_data_->SetLastError(kViECaptureDeviceNotConnected);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000232 return -1;
233 }
234 if (frame_provider->Id() < kViECaptureIdBase ||
235 frame_provider->Id() > kViECaptureIdMax) {
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
244 if (frame_provider->DeregisterFrameCallback(vie_encoder) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000245 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000246 return -1;
247 }
248
249 return 0;
250}
251
252int ViECaptureImpl::StartCapture(const int capture_id,
mflodman@webrtc.orge5297d22012-01-17 12:44:41 +0000253 const CaptureCapability& capture_capability) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000254 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000255 "%s(capture_id: %d)", __FUNCTION__, capture_id);
256
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000257 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000258 ViECapturer* vie_capture = is.Capture(capture_id);
259 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000260 WEBRTC_TRACE(kTraceError, kTraceVideo,
261 ViEId(shared_data_->instance_id(), capture_id),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000262 "%s: Capture device %d doesn't exist", __FUNCTION__,
263 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000264 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000265 return -1;
266 }
267 if (vie_capture->Started()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000268 shared_data_->SetLastError(kViECaptureDeviceAlreadyStarted);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000269 return -1;
270 }
271 if (vie_capture->Start(capture_capability) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000272 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000273 return -1;
274 }
275 return 0;
276}
277
278int ViECaptureImpl::StopCapture(const int capture_id) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000279 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000280 "%s(capture_id: %d)", __FUNCTION__, capture_id);
281
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000282 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000283 ViECapturer* vie_capture = is.Capture(capture_id);
284 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000285 WEBRTC_TRACE(kTraceError, kTraceVideo,
286 ViEId(shared_data_->instance_id(), capture_id),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000287 "%s: Capture device %d doesn't exist", __FUNCTION__,
288 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000289 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000290 return -1;
291 }
292 if (!vie_capture->Started()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000293 shared_data_->SetLastError(kViECaptureDeviceNotStarted);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000294 return -1;
295 }
296 if (vie_capture->Stop() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000297 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000298 return -1;
299 }
300
301 return 0;
302}
303
304int ViECaptureImpl::SetRotateCapturedFrames(
305 const int capture_id,
306 const RotateCapturedFrame rotation) {
307 int i_rotation = -1;
308 switch (rotation) {
309 case RotateCapturedFrame_0:
310 i_rotation = 0;
311 break;
312 case RotateCapturedFrame_90:
313 i_rotation = 90;
314 break;
315 case RotateCapturedFrame_180:
316 i_rotation = 180;
317 break;
318 case RotateCapturedFrame_270:
319 i_rotation = 270;
320 break;
321 }
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000322 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000323 "%s(rotation: %d)", __FUNCTION__, i_rotation);
324
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000325 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000326 ViECapturer* vie_capture = is.Capture(capture_id);
327 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000328 WEBRTC_TRACE(kTraceError, kTraceVideo,
329 ViEId(shared_data_->instance_id(), capture_id),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000330 "%s: Capture device %d doesn't exist", __FUNCTION__,
331 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000332 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000333 return -1;
334 }
335 if (vie_capture->SetRotateCapturedFrames(rotation) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000336 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000337 return -1;
338 }
339 return 0;
340}
341
342int ViECaptureImpl::SetCaptureDelay(const int capture_id,
343 const unsigned int capture_delay_ms) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000344 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000345 "%s(capture_id: %d, capture_delay_ms %u)", __FUNCTION__,
346 capture_id, capture_delay_ms);
347
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000348 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000349 ViECapturer* vie_capture = is.Capture(capture_id);
350 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000351 WEBRTC_TRACE(kTraceError, kTraceVideo,
352 ViEId(shared_data_->instance_id(), capture_id),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000353 "%s: Capture device %d doesn't exist", __FUNCTION__,
354 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000355 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000356 return -1;
357 }
358
359 if (vie_capture->SetCaptureDelay(capture_delay_ms) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000360 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000361 return -1;
362 }
363 return 0;
364}
365
366int ViECaptureImpl::NumberOfCapabilities(
367 const char* unique_idUTF8,
368 const unsigned int unique_idUTF8Length) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000369 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000370 "%s(capture_device_name: %s)", __FUNCTION__, unique_idUTF8);
371
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000372#if defined(WEBRTC_MAC)
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000373 // TODO(mflodman) Move to capture module!
374 // QTKit framework handles all capabilities and capture settings
375 // automatically (mandatory).
376 // Thus this function cannot be supported on the Mac platform.
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000377 shared_data_->SetLastError(kViECaptureDeviceMacQtkitNotSupported);
378 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000379 "%s This API is not supported on Mac OS", __FUNCTION__,
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000380 shared_data_->instance_id());
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000381 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000382#endif
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000383 return shared_data_->input_manager()->NumberOfCaptureCapabilities(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000384 unique_idUTF8);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000385}
386
387
388int ViECaptureImpl::GetCaptureCapability(const char* unique_idUTF8,
389 const unsigned int unique_idUTF8Length,
390 const unsigned int capability_number,
391 CaptureCapability& capability) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000392 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000393 "%s(capture_device_name: %s)", __FUNCTION__, unique_idUTF8);
394
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000395#if defined(WEBRTC_MAC)
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000396 // TODO(mflodman) Move to capture module!
397 // QTKit framework handles all capabilities and capture settings
398 // automatically (mandatory).
399 // Thus this function cannot be supported on the Mac platform.
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000400 shared_data_->SetLastError(kViECaptureDeviceMacQtkitNotSupported);
401 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000402 "%s This API is not supported on Mac OS", __FUNCTION__,
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000403 shared_data_->instance_id());
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000404 return -1;
405#endif
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000406 if (shared_data_->input_manager()->GetCaptureCapability(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000407 unique_idUTF8, capability_number, capability) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000408 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000409 return -1;
410 }
411 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000412}
413
414int ViECaptureImpl::ShowCaptureSettingsDialogBox(
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000415 const char* unique_idUTF8,
416 const unsigned int unique_idUTF8Length,
417 const char* dialog_title,
418 void* parent_window,
419 const unsigned int x,
420 const unsigned int y) {
andrew@webrtc.orgf3b65db2012-09-06 18:17:00 +0000421#if defined(WEBRTC_MAC)
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000422 // TODO(mflodman) Move to capture module
423 // QTKit framework handles all capabilities and capture settings
424 // automatically (mandatory).
425 // Thus this function cannot be supported on the Mac platform.
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000426 shared_data_->SetLastError(kViECaptureDeviceMacQtkitNotSupported);
427 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000428 "%s This API is not supported on Mac OS", __FUNCTION__,
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000429 shared_data_->instance_id());
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000430 return -1;
431#endif
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000432 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000433 "%s capture_id (capture_device_name: %s)", __FUNCTION__,
434 unique_idUTF8);
435
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000436 return shared_data_->input_manager()->DisplayCaptureSettingsDialogBox(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000437 unique_idUTF8, dialog_title,
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000438 parent_window, x, y);
439}
440
441int ViECaptureImpl::GetOrientation(const char* unique_idUTF8,
442 RotateCapturedFrame& orientation) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000443 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000444 "%s (capture_device_name: %s)", __FUNCTION__, unique_idUTF8);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000445 if (shared_data_->input_manager()->GetOrientation(
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000446 unique_idUTF8,
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000447 orientation) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000448 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000449 return -1;
450 }
451 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000452}
453
niklase@google.com470e71d2011-07-07 08:21:25 +0000454
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000455int ViECaptureImpl::EnableBrightnessAlarm(const int capture_id,
456 const bool enable) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000457 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000458 ViECapturer* vie_capture = is.Capture(capture_id);
459 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000460 WEBRTC_TRACE(kTraceError, kTraceVideo,
461 ViEId(shared_data_->instance_id(), capture_id),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000462 "%s: Capture device %d doesn't exist", __FUNCTION__,
463 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000464 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000465 return -1;
466 }
467 if (vie_capture->EnableBrightnessAlarm(enable) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000468 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000469 return -1;
470 }
471 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000472}
473
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000474int ViECaptureImpl::RegisterObserver(const int capture_id,
475 ViECaptureObserver& observer) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000476 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000477 ViECapturer* vie_capture = is.Capture(capture_id);
478 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000479 WEBRTC_TRACE(kTraceError, kTraceVideo,
480 ViEId(shared_data_->instance_id(), capture_id),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000481 "%s: Capture device %d doesn't exist", __FUNCTION__,
482 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000483 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000484 return -1;
485 }
486 if (vie_capture->IsObserverRegistered()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000487 WEBRTC_TRACE(kTraceError, kTraceVideo,
488 ViEId(shared_data_->instance_id(), capture_id),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000489 "%s: Observer already registered", __FUNCTION__);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000490 shared_data_->SetLastError(kViECaptureObserverAlreadyRegistered);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000491 return -1;
492 }
mflodman@webrtc.org8baed512012-06-21 12:11:50 +0000493 if (vie_capture->RegisterObserver(&observer) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000494 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000495 return -1;
496 }
497 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000498}
499
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000500int ViECaptureImpl::DeregisterObserver(const int capture_id) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000501 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000502 ViECapturer* vie_capture = is.Capture(capture_id);
503 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000504 WEBRTC_TRACE(kTraceError, kTraceVideo,
505 ViEId(shared_data_->instance_id(), capture_id),
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000506 "%s: Capture device %d doesn't exist", __FUNCTION__,
507 capture_id);
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000508 shared_data_->SetLastError(kViECaptureDeviceDoesNotExist);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000509 return -1;
510 }
511 if (!vie_capture->IsObserverRegistered()) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000512 shared_data_->SetLastError(kViECaptureDeviceObserverNotRegistered);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000513 return -1;
514 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000515
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000516 if (vie_capture->DeRegisterObserver() != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000517 shared_data_->SetLastError(kViECaptureDeviceUnknownError);
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000518 return -1;
519 }
520 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000521}
522
mflodman@webrtc.org605972e2011-12-16 08:59:24 +0000523} // namespace webrtc