andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 | |
| 11 | #include "video_engine/vie_capture_impl.h" |
| 12 | |
| 13 | #include "system_wrappers/interface/trace.h" |
| 14 | #include "video_engine/include/vie_errors.h" |
| 15 | #include "video_engine/vie_capturer.h" |
| 16 | #include "video_engine/vie_channel.h" |
| 17 | #include "video_engine/vie_channel_manager.h" |
| 18 | #include "video_engine/vie_defines.h" |
| 19 | #include "video_engine/vie_encoder.h" |
| 20 | #include "video_engine/vie_impl.h" |
| 21 | #include "video_engine/vie_input_manager.h" |
| 22 | #include "video_engine/vie_shared_data.h" |
| 23 | |
| 24 | namespace webrtc { |
| 25 | |
| 26 | ViECapture* ViECapture::GetInterface(VideoEngine* video_engine) { |
| 27 | #ifdef WEBRTC_VIDEO_ENGINE_CAPTURE_API |
| 28 | if (!video_engine) { |
| 29 | return NULL; |
| 30 | } |
| 31 | VideoEngineImpl* vie_impl = reinterpret_cast<VideoEngineImpl*>(video_engine); |
| 32 | ViECaptureImpl* vie_capture_impl = vie_impl; |
| 33 | // Increase ref count. |
| 34 | (*vie_capture_impl)++; |
| 35 | return vie_capture_impl; |
| 36 | #else |
| 37 | return NULL; |
| 38 | #endif |
| 39 | } |
| 40 | |
| 41 | int ViECaptureImpl::Release() { |
| 42 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_->instance_id(), |
| 43 | "ViECapture::Release()"); |
| 44 | // Decrease ref count |
| 45 | (*this)--; |
| 46 | |
pbos@webrtc.org | 2a5d229 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 47 | int32_t ref_count = GetCount(); |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 48 | if (ref_count < 0) { |
| 49 | WEBRTC_TRACE(kTraceWarning, kTraceVideo, shared_data_->instance_id(), |
| 50 | "ViECapture release too many times"); |
| 51 | shared_data_->SetLastError(kViEAPIDoesNotExist); |
| 52 | return -1; |
| 53 | } |
| 54 | WEBRTC_TRACE(kTraceInfo, kTraceVideo, shared_data_->instance_id(), |
| 55 | "ViECapture reference count: %d", ref_count); |
| 56 | return ref_count; |
| 57 | } |
| 58 | |
| 59 | ViECaptureImpl::ViECaptureImpl(ViESharedData* shared_data) |
| 60 | : shared_data_(shared_data) { |
| 61 | WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(), |
| 62 | "ViECaptureImpl::ViECaptureImpl() Ctor"); |
| 63 | } |
| 64 | |
| 65 | ViECaptureImpl::~ViECaptureImpl() { |
| 66 | WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(), |
| 67 | "ViECaptureImpl::~ViECaptureImpl() Dtor"); |
| 68 | } |
| 69 | |
| 70 | int ViECaptureImpl::NumberOfCaptureDevices() { |
| 71 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 72 | "%s", __FUNCTION__); |
| 73 | if (!shared_data_->Initialized()) { |
| 74 | shared_data_->SetLastError(kViENotInitialized); |
| 75 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 76 | "%s - ViE instance %d not initialized", __FUNCTION__, |
| 77 | shared_data_->instance_id()); |
| 78 | return -1; |
| 79 | } |
| 80 | return shared_data_->input_manager()->NumberOfCaptureDevices(); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | int ViECaptureImpl::GetCaptureDevice(unsigned int list_number, |
| 85 | char* device_nameUTF8, |
| 86 | unsigned int device_nameUTF8Length, |
| 87 | char* unique_idUTF8, |
| 88 | unsigned int unique_idUTF8Length) { |
| 89 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 90 | "%s(list_number: %d)", __FUNCTION__, list_number); |
| 91 | if (!shared_data_->Initialized()) { |
| 92 | shared_data_->SetLastError(kViENotInitialized); |
| 93 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 94 | "%s - ViE instance %d not initialized", __FUNCTION__, |
| 95 | shared_data_->instance_id()); |
| 96 | return -1; |
| 97 | } |
| 98 | return shared_data_->input_manager()->GetDeviceName( |
| 99 | list_number, |
| 100 | device_nameUTF8, device_nameUTF8Length, |
| 101 | unique_idUTF8, unique_idUTF8Length); |
| 102 | } |
| 103 | |
| 104 | int ViECaptureImpl::AllocateCaptureDevice( |
| 105 | const char* unique_idUTF8, |
| 106 | const unsigned int unique_idUTF8Length, |
| 107 | int& capture_id) { |
| 108 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 109 | "%s(unique_idUTF8: %s)", __FUNCTION__, unique_idUTF8); |
| 110 | if (!shared_data_->Initialized()) { |
| 111 | shared_data_->SetLastError(kViENotInitialized); |
| 112 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 113 | "%s - ViE instance %d not initialized", __FUNCTION__, |
| 114 | shared_data_->instance_id()); |
| 115 | return -1; |
| 116 | } |
pbos@webrtc.org | 2a5d229 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 117 | const int32_t result = |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 118 | shared_data_->input_manager()->CreateCaptureDevice( |
| 119 | unique_idUTF8, |
pbos@webrtc.org | 2a5d229 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 120 | static_cast<const uint32_t>(unique_idUTF8Length), |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 121 | capture_id); |
| 122 | if (result != 0) { |
| 123 | shared_data_->SetLastError(result); |
| 124 | return -1; |
| 125 | } |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | int ViECaptureImpl::AllocateExternalCaptureDevice( |
| 130 | int& capture_id, ViEExternalCapture*& external_capture) { |
| 131 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 132 | "%s", __FUNCTION__); |
| 133 | |
| 134 | if (!shared_data_->Initialized()) { |
| 135 | shared_data_->SetLastError(kViENotInitialized); |
| 136 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 137 | "%s - ViE instance %d not initialized", __FUNCTION__, |
| 138 | shared_data_->instance_id()); |
| 139 | return -1; |
| 140 | } |
pbos@webrtc.org | 2a5d229 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 141 | const int32_t result = |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 142 | shared_data_->input_manager()->CreateExternalCaptureDevice( |
| 143 | external_capture, capture_id); |
| 144 | |
| 145 | if (result != 0) { |
| 146 | shared_data_->SetLastError(result); |
| 147 | return -1; |
| 148 | } |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | int ViECaptureImpl::AllocateCaptureDevice( |
| 153 | VideoCaptureModule& capture_module, int& capture_id) { // NOLINT |
| 154 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 155 | "%s", __FUNCTION__); |
| 156 | |
| 157 | if (!shared_data_->Initialized()) { |
| 158 | shared_data_->SetLastError(kViENotInitialized); |
| 159 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 160 | "%s - ViE instance %d not initialized", __FUNCTION__, |
| 161 | shared_data_->instance_id()); |
| 162 | return -1; |
| 163 | } |
pbos@webrtc.org | 2a5d229 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 164 | const int32_t result = |
andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 165 | shared_data_->input_manager()->CreateCaptureDevice(&capture_module, |
| 166 | capture_id); |
| 167 | if (result != 0) { |
| 168 | shared_data_->SetLastError(result); |
| 169 | return -1; |
| 170 | } |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | int ViECaptureImpl::ReleaseCaptureDevice(const int capture_id) { |
| 176 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 177 | "%s(capture_id: %d)", __FUNCTION__, capture_id); |
| 178 | { |
| 179 | ViEInputManagerScoped is((*(shared_data_->input_manager()))); |
| 180 | ViECapturer* vie_capture = is.Capture(capture_id); |
| 181 | if (!vie_capture) { |
| 182 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 183 | "%s: Capture device %d doesn't exist", __FUNCTION__, |
| 184 | capture_id); |
| 185 | shared_data_->SetLastError(kViECaptureDeviceDoesNotExist); |
| 186 | return -1; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | // Destroy the capture device. |
| 191 | return shared_data_->input_manager()->DestroyCaptureDevice(capture_id); |
| 192 | } |
| 193 | |
| 194 | int ViECaptureImpl::ConnectCaptureDevice(const int capture_id, |
| 195 | const int video_channel) { |
| 196 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 197 | ViEId(shared_data_->instance_id(), video_channel), |
| 198 | "%s(capture_id: %d, video_channel: %d)", __FUNCTION__, |
| 199 | capture_id, video_channel); |
| 200 | |
| 201 | ViEInputManagerScoped is(*(shared_data_->input_manager())); |
| 202 | ViECapturer* vie_capture = is.Capture(capture_id); |
| 203 | if (!vie_capture) { |
| 204 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 205 | ViEId(shared_data_->instance_id(), video_channel), |
| 206 | "%s: Capture device %d doesn't exist", __FUNCTION__, |
| 207 | capture_id); |
| 208 | shared_data_->SetLastError(kViECaptureDeviceDoesNotExist); |
| 209 | return -1; |
| 210 | } |
| 211 | |
| 212 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 213 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 214 | if (!vie_encoder) { |
| 215 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 216 | ViEId(shared_data_->instance_id(), video_channel), |
| 217 | "%s: Channel %d doesn't exist", __FUNCTION__, |
| 218 | video_channel); |
| 219 | shared_data_->SetLastError(kViECaptureDeviceInvalidChannelId); |
| 220 | return -1; |
| 221 | } |
| 222 | if (vie_encoder->Owner() != video_channel) { |
| 223 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 224 | ViEId(shared_data_->instance_id(), video_channel), |
| 225 | "Can't connect capture device to a receive only channel."); |
| 226 | shared_data_->SetLastError(kViECaptureDeviceInvalidChannelId); |
| 227 | return -1; |
| 228 | } |
| 229 | // Check if the encoder already has a connected frame provider |
| 230 | if (is.FrameProvider(vie_encoder) != NULL) { |
| 231 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 232 | ViEId(shared_data_->instance_id(), video_channel), |
| 233 | "%s: Channel %d already connected to a capture device.", |
| 234 | __FUNCTION__, video_channel); |
| 235 | shared_data_->SetLastError(kViECaptureDeviceAlreadyConnected); |
| 236 | return -1; |
| 237 | } |
| 238 | VideoCodec codec; |
| 239 | bool use_hardware_encoder = false; |
| 240 | if (vie_encoder->GetEncoder(&codec) == 0) { |
| 241 | // Try to provide the encoder with pre-encoded frames if possible. |
| 242 | if (vie_capture->PreEncodeToViEEncoder(codec, *vie_encoder, |
| 243 | video_channel) == 0) { |
| 244 | use_hardware_encoder = true; |
| 245 | } |
| 246 | } |
| 247 | // If we don't use the camera as hardware encoder, we register the vie_encoder |
| 248 | // for callbacks. |
| 249 | if (!use_hardware_encoder && |
| 250 | vie_capture->RegisterFrameCallback(video_channel, vie_encoder) != 0) { |
| 251 | shared_data_->SetLastError(kViECaptureDeviceUnknownError); |
| 252 | return -1; |
| 253 | } |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | |
| 258 | int ViECaptureImpl::DisconnectCaptureDevice(const int video_channel) { |
| 259 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 260 | ViEId(shared_data_->instance_id(), video_channel), |
| 261 | "%s(video_channel: %d)", __FUNCTION__, video_channel); |
| 262 | |
| 263 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 264 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 265 | if (!vie_encoder) { |
| 266 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 267 | ViEId(shared_data_->instance_id()), |
| 268 | "%s: Channel %d doesn't exist", __FUNCTION__, |
| 269 | video_channel); |
| 270 | shared_data_->SetLastError(kViECaptureDeviceInvalidChannelId); |
| 271 | return -1; |
| 272 | } |
| 273 | |
| 274 | ViEInputManagerScoped is(*(shared_data_->input_manager())); |
| 275 | ViEFrameProviderBase* frame_provider = is.FrameProvider(vie_encoder); |
| 276 | if (!frame_provider) { |
| 277 | WEBRTC_TRACE(kTraceWarning, kTraceVideo, |
| 278 | ViEId(shared_data_->instance_id()), |
| 279 | "%s: No capture device connected to channel %d", |
| 280 | __FUNCTION__, video_channel); |
| 281 | shared_data_->SetLastError(kViECaptureDeviceNotConnected); |
| 282 | return -1; |
| 283 | } |
| 284 | if (frame_provider->Id() < kViECaptureIdBase || |
| 285 | frame_provider->Id() > kViECaptureIdMax) { |
| 286 | WEBRTC_TRACE(kTraceWarning, kTraceVideo, |
| 287 | ViEId(shared_data_->instance_id()), |
| 288 | "%s: No capture device connected to channel %d", |
| 289 | __FUNCTION__, video_channel); |
| 290 | shared_data_->SetLastError(kViECaptureDeviceNotConnected); |
| 291 | return -1; |
| 292 | } |
| 293 | |
| 294 | if (frame_provider->DeregisterFrameCallback(vie_encoder) != 0) { |
| 295 | shared_data_->SetLastError(kViECaptureDeviceUnknownError); |
| 296 | return -1; |
| 297 | } |
| 298 | |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | int ViECaptureImpl::StartCapture(const int capture_id, |
| 303 | const CaptureCapability& capture_capability) { |
| 304 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 305 | "%s(capture_id: %d)", __FUNCTION__, capture_id); |
| 306 | |
| 307 | ViEInputManagerScoped is(*(shared_data_->input_manager())); |
| 308 | ViECapturer* vie_capture = is.Capture(capture_id); |
| 309 | if (!vie_capture) { |
| 310 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 311 | ViEId(shared_data_->instance_id(), capture_id), |
| 312 | "%s: Capture device %d doesn't exist", __FUNCTION__, |
| 313 | capture_id); |
| 314 | shared_data_->SetLastError(kViECaptureDeviceDoesNotExist); |
| 315 | return -1; |
| 316 | } |
| 317 | if (vie_capture->Started()) { |
| 318 | shared_data_->SetLastError(kViECaptureDeviceAlreadyStarted); |
| 319 | return -1; |
| 320 | } |
| 321 | if (vie_capture->Start(capture_capability) != 0) { |
| 322 | shared_data_->SetLastError(kViECaptureDeviceUnknownError); |
| 323 | return -1; |
| 324 | } |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | int ViECaptureImpl::StopCapture(const int capture_id) { |
| 329 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 330 | "%s(capture_id: %d)", __FUNCTION__, capture_id); |
| 331 | |
| 332 | ViEInputManagerScoped is(*(shared_data_->input_manager())); |
| 333 | ViECapturer* vie_capture = is.Capture(capture_id); |
| 334 | if (!vie_capture) { |
| 335 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 336 | ViEId(shared_data_->instance_id(), capture_id), |
| 337 | "%s: Capture device %d doesn't exist", __FUNCTION__, |
| 338 | capture_id); |
| 339 | shared_data_->SetLastError(kViECaptureDeviceDoesNotExist); |
| 340 | return -1; |
| 341 | } |
| 342 | if (!vie_capture->Started()) { |
| 343 | shared_data_->SetLastError(kViECaptureDeviceNotStarted); |
| 344 | return -1; |
| 345 | } |
| 346 | if (vie_capture->Stop() != 0) { |
| 347 | shared_data_->SetLastError(kViECaptureDeviceUnknownError); |
| 348 | return -1; |
| 349 | } |
| 350 | |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | int ViECaptureImpl::SetRotateCapturedFrames( |
| 355 | const int capture_id, |
| 356 | const RotateCapturedFrame rotation) { |
| 357 | int i_rotation = -1; |
| 358 | switch (rotation) { |
| 359 | case RotateCapturedFrame_0: |
| 360 | i_rotation = 0; |
| 361 | break; |
| 362 | case RotateCapturedFrame_90: |
| 363 | i_rotation = 90; |
| 364 | break; |
| 365 | case RotateCapturedFrame_180: |
| 366 | i_rotation = 180; |
| 367 | break; |
| 368 | case RotateCapturedFrame_270: |
| 369 | i_rotation = 270; |
| 370 | break; |
| 371 | } |
| 372 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 373 | "%s(rotation: %d)", __FUNCTION__, i_rotation); |
| 374 | |
| 375 | ViEInputManagerScoped is(*(shared_data_->input_manager())); |
| 376 | ViECapturer* vie_capture = is.Capture(capture_id); |
| 377 | if (!vie_capture) { |
| 378 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 379 | ViEId(shared_data_->instance_id(), capture_id), |
| 380 | "%s: Capture device %d doesn't exist", __FUNCTION__, |
| 381 | capture_id); |
| 382 | shared_data_->SetLastError(kViECaptureDeviceDoesNotExist); |
| 383 | return -1; |
| 384 | } |
| 385 | if (vie_capture->SetRotateCapturedFrames(rotation) != 0) { |
| 386 | shared_data_->SetLastError(kViECaptureDeviceUnknownError); |
| 387 | return -1; |
| 388 | } |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | int ViECaptureImpl::SetCaptureDelay(const int capture_id, |
| 393 | const unsigned int capture_delay_ms) { |
| 394 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 395 | "%s(capture_id: %d, capture_delay_ms %u)", __FUNCTION__, |
| 396 | capture_id, capture_delay_ms); |
| 397 | |
| 398 | ViEInputManagerScoped is(*(shared_data_->input_manager())); |
| 399 | ViECapturer* vie_capture = is.Capture(capture_id); |
| 400 | if (!vie_capture) { |
| 401 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 402 | ViEId(shared_data_->instance_id(), capture_id), |
| 403 | "%s: Capture device %d doesn't exist", __FUNCTION__, |
| 404 | capture_id); |
| 405 | shared_data_->SetLastError(kViECaptureDeviceDoesNotExist); |
| 406 | return -1; |
| 407 | } |
| 408 | |
| 409 | if (vie_capture->SetCaptureDelay(capture_delay_ms) != 0) { |
| 410 | shared_data_->SetLastError(kViECaptureDeviceUnknownError); |
| 411 | return -1; |
| 412 | } |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | int ViECaptureImpl::NumberOfCapabilities( |
| 417 | const char* unique_idUTF8, |
| 418 | const unsigned int unique_idUTF8Length) { |
| 419 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 420 | "%s(capture_device_name: %s)", __FUNCTION__, unique_idUTF8); |
| 421 | |
| 422 | #if defined(WEBRTC_MAC) |
| 423 | // TODO(mflodman) Move to capture module! |
| 424 | // QTKit framework handles all capabilities and capture settings |
| 425 | // automatically (mandatory). |
| 426 | // Thus this function cannot be supported on the Mac platform. |
| 427 | shared_data_->SetLastError(kViECaptureDeviceMacQtkitNotSupported); |
| 428 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 429 | "%s This API is not supported on Mac OS", __FUNCTION__, |
| 430 | shared_data_->instance_id()); |
| 431 | return -1; |
| 432 | #endif |
| 433 | |
| 434 | if (!shared_data_->Initialized()) { |
| 435 | shared_data_->SetLastError(kViENotInitialized); |
| 436 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 437 | "%s - ViE instance %d not initialized", __FUNCTION__, |
| 438 | shared_data_->instance_id()); |
| 439 | return -1; |
| 440 | } |
| 441 | return shared_data_->input_manager()->NumberOfCaptureCapabilities( |
| 442 | unique_idUTF8); |
| 443 | } |
| 444 | |
| 445 | |
| 446 | int ViECaptureImpl::GetCaptureCapability(const char* unique_idUTF8, |
| 447 | const unsigned int unique_idUTF8Length, |
| 448 | const unsigned int capability_number, |
| 449 | CaptureCapability& capability) { |
| 450 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 451 | "%s(capture_device_name: %s)", __FUNCTION__, unique_idUTF8); |
| 452 | |
| 453 | #if defined(WEBRTC_MAC) |
| 454 | // TODO(mflodman) Move to capture module! |
| 455 | // QTKit framework handles all capabilities and capture settings |
| 456 | // automatically (mandatory). |
| 457 | // Thus this function cannot be supported on the Mac platform. |
| 458 | shared_data_->SetLastError(kViECaptureDeviceMacQtkitNotSupported); |
| 459 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 460 | "%s This API is not supported on Mac OS", __FUNCTION__, |
| 461 | shared_data_->instance_id()); |
| 462 | return -1; |
| 463 | #endif |
| 464 | if (!shared_data_->Initialized()) { |
| 465 | shared_data_->SetLastError(kViENotInitialized); |
| 466 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 467 | "%s - ViE instance %d not initialized", __FUNCTION__, |
| 468 | shared_data_->instance_id()); |
| 469 | return -1; |
| 470 | } |
| 471 | if (shared_data_->input_manager()->GetCaptureCapability( |
| 472 | unique_idUTF8, capability_number, capability) != 0) { |
| 473 | shared_data_->SetLastError(kViECaptureDeviceUnknownError); |
| 474 | return -1; |
| 475 | } |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | int ViECaptureImpl::ShowCaptureSettingsDialogBox( |
| 480 | const char* unique_idUTF8, |
| 481 | const unsigned int unique_idUTF8Length, |
| 482 | const char* dialog_title, |
| 483 | void* parent_window, |
| 484 | const unsigned int x, |
| 485 | const unsigned int y) { |
| 486 | #if defined(WEBRTC_MAC) |
| 487 | // TODO(mflodman) Move to capture module |
| 488 | // QTKit framework handles all capabilities and capture settings |
| 489 | // automatically (mandatory). |
| 490 | // Thus this function cannot be supported on the Mac platform. |
| 491 | shared_data_->SetLastError(kViECaptureDeviceMacQtkitNotSupported); |
| 492 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 493 | "%s This API is not supported on Mac OS", __FUNCTION__, |
| 494 | shared_data_->instance_id()); |
| 495 | return -1; |
| 496 | #endif |
| 497 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 498 | "%s capture_id (capture_device_name: %s)", __FUNCTION__, |
| 499 | unique_idUTF8); |
| 500 | |
| 501 | return shared_data_->input_manager()->DisplayCaptureSettingsDialogBox( |
| 502 | unique_idUTF8, dialog_title, |
| 503 | parent_window, x, y); |
| 504 | } |
| 505 | |
| 506 | int ViECaptureImpl::GetOrientation(const char* unique_idUTF8, |
| 507 | RotateCapturedFrame& orientation) { |
| 508 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 509 | "%s (capture_device_name: %s)", __FUNCTION__, unique_idUTF8); |
| 510 | |
| 511 | if (!shared_data_->Initialized()) { |
| 512 | shared_data_->SetLastError(kViENotInitialized); |
| 513 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 514 | "%s - ViE instance %d not initialized", __FUNCTION__, |
| 515 | shared_data_->instance_id()); |
| 516 | return -1; |
| 517 | } |
| 518 | if (shared_data_->input_manager()->GetOrientation( |
| 519 | unique_idUTF8, |
| 520 | orientation) != 0) { |
| 521 | shared_data_->SetLastError(kViECaptureDeviceUnknownError); |
| 522 | return -1; |
| 523 | } |
| 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | |
| 528 | int ViECaptureImpl::EnableBrightnessAlarm(const int capture_id, |
| 529 | const bool enable) { |
| 530 | ViEInputManagerScoped is(*(shared_data_->input_manager())); |
| 531 | ViECapturer* vie_capture = is.Capture(capture_id); |
| 532 | if (!vie_capture) { |
| 533 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 534 | ViEId(shared_data_->instance_id(), capture_id), |
| 535 | "%s: Capture device %d doesn't exist", __FUNCTION__, |
| 536 | capture_id); |
| 537 | shared_data_->SetLastError(kViECaptureDeviceDoesNotExist); |
| 538 | return -1; |
| 539 | } |
| 540 | if (vie_capture->EnableBrightnessAlarm(enable) != 0) { |
| 541 | shared_data_->SetLastError(kViECaptureDeviceUnknownError); |
| 542 | return -1; |
| 543 | } |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | int ViECaptureImpl::RegisterObserver(const int capture_id, |
| 548 | ViECaptureObserver& observer) { |
| 549 | ViEInputManagerScoped is(*(shared_data_->input_manager())); |
| 550 | ViECapturer* vie_capture = is.Capture(capture_id); |
| 551 | if (!vie_capture) { |
| 552 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 553 | ViEId(shared_data_->instance_id(), capture_id), |
| 554 | "%s: Capture device %d doesn't exist", __FUNCTION__, |
| 555 | capture_id); |
| 556 | shared_data_->SetLastError(kViECaptureDeviceDoesNotExist); |
| 557 | return -1; |
| 558 | } |
| 559 | if (vie_capture->IsObserverRegistered()) { |
| 560 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 561 | ViEId(shared_data_->instance_id(), capture_id), |
| 562 | "%s: Observer already registered", __FUNCTION__); |
| 563 | shared_data_->SetLastError(kViECaptureObserverAlreadyRegistered); |
| 564 | return -1; |
| 565 | } |
| 566 | if (vie_capture->RegisterObserver(&observer) != 0) { |
| 567 | shared_data_->SetLastError(kViECaptureDeviceUnknownError); |
| 568 | return -1; |
| 569 | } |
| 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | int ViECaptureImpl::DeregisterObserver(const int capture_id) { |
| 574 | ViEInputManagerScoped is(*(shared_data_->input_manager())); |
| 575 | ViECapturer* vie_capture = is.Capture(capture_id); |
| 576 | if (!vie_capture) { |
| 577 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 578 | ViEId(shared_data_->instance_id(), capture_id), |
| 579 | "%s: Capture device %d doesn't exist", __FUNCTION__, |
| 580 | capture_id); |
| 581 | shared_data_->SetLastError(kViECaptureDeviceDoesNotExist); |
| 582 | return -1; |
| 583 | } |
| 584 | if (!vie_capture->IsObserverRegistered()) { |
| 585 | shared_data_->SetLastError(kViECaptureDeviceObserverNotRegistered); |
| 586 | return -1; |
| 587 | } |
| 588 | |
| 589 | if (vie_capture->DeRegisterObserver() != 0) { |
| 590 | shared_data_->SetLastError(kViECaptureDeviceUnknownError); |
| 591 | return -1; |
| 592 | } |
| 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | } // namespace webrtc |