| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/capture/video/linux/v4l2_capture_delegate.h" | 5 #include "media/capture/video/linux/v4l2_capture_delegate.h" |
| 6 | 6 |
| 7 #include <poll.h> | 7 #include <poll.h> |
| 8 #include <sys/fcntl.h> | 8 #include <sys/fcntl.h> |
| 9 #include <sys/ioctl.h> | 9 #include <sys/ioctl.h> |
| 10 #include <sys/mman.h> | 10 #include <sys/mman.h> |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 is_capturing_ = false; | 321 is_capturing_ = false; |
| 322 client_.reset(); | 322 client_.reset(); |
| 323 } | 323 } |
| 324 | 324 |
| 325 void V4L2CaptureDelegate::TakePhoto( | 325 void V4L2CaptureDelegate::TakePhoto( |
| 326 VideoCaptureDevice::TakePhotoCallback callback) { | 326 VideoCaptureDevice::TakePhotoCallback callback) { |
| 327 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); | 327 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); |
| 328 take_photo_callbacks_.push(std::move(callback)); | 328 take_photo_callbacks_.push(std::move(callback)); |
| 329 } | 329 } |
| 330 | 330 |
| 331 void V4L2CaptureDelegate::GetPhotoCapabilities( |
| 332 VideoCaptureDevice::GetPhotoCapabilitiesCallback callback) { |
| 333 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); |
| 334 |
| 335 mojom::PhotoCapabilitiesPtr photo_capabilities = |
| 336 mojom::PhotoCapabilities::New(); |
| 337 |
| 338 photo_capabilities->zoom = mojom::Range::New(); |
| 339 v4l2_queryctrl zoom_range = {}; |
| 340 zoom_range.id = V4L2_CID_ZOOM_ABSOLUTE; |
| 341 zoom_range.type = V4L2_CTRL_TYPE_INTEGER; |
| 342 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QUERYCTRL, &zoom_range)) >= |
| 343 0) { |
| 344 photo_capabilities->zoom->max = zoom_range.maximum * 100; |
| 345 photo_capabilities->zoom->min = zoom_range.minimum * 100; |
| 346 } |
| 347 v4l2_control zoom_current = {}; |
| 348 zoom_current.id = V4L2_CID_ZOOM_ABSOLUTE; |
| 349 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_G_CTRL, &zoom_current)) >= 0) |
| 350 photo_capabilities->zoom->current = zoom_current.value * 100; |
| 351 |
| 352 photo_capabilities->focus_mode = mojom::MeteringMode::NONE; |
| 353 v4l2_control auto_focus_current = {}; |
| 354 auto_focus_current.id = V4L2_CID_FOCUS_AUTO; |
| 355 if (HANDLE_EINTR( |
| 356 ioctl(device_fd_.get(), VIDIOC_G_CTRL, &auto_focus_current)) >= 0) { |
| 357 photo_capabilities->focus_mode = auto_focus_current.value |
| 358 ? mojom::MeteringMode::CONTINUOUS |
| 359 : mojom::MeteringMode::MANUAL; |
| 360 } |
| 361 |
| 362 photo_capabilities->exposure_mode = mojom::MeteringMode::NONE; |
| 363 v4l2_control exposure_current = {}; |
| 364 exposure_current.id = V4L2_CID_EXPOSURE_AUTO; |
| 365 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_G_CTRL, &exposure_current)) >= |
| 366 0) { |
| 367 photo_capabilities->exposure_mode = |
| 368 exposure_current.value == V4L2_EXPOSURE_MANUAL |
| 369 ? mojom::MeteringMode::MANUAL |
| 370 : mojom::MeteringMode::CONTINUOUS; |
| 371 } |
| 372 |
| 373 photo_capabilities->white_balance_mode = mojom::MeteringMode::NONE; |
| 374 v4l2_control white_balance_current = {}; |
| 375 white_balance_current.id = V4L2_CID_AUTO_WHITE_BALANCE; |
| 376 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_G_CTRL, |
| 377 &white_balance_current)) >= 0) { |
| 378 photo_capabilities->white_balance_mode = |
| 379 white_balance_current.value ? mojom::MeteringMode::CONTINUOUS |
| 380 : mojom::MeteringMode::MANUAL; |
| 381 } |
| 382 |
| 383 photo_capabilities->iso = mojom::Range::New(); |
| 384 photo_capabilities->height = mojom::Range::New(); |
| 385 photo_capabilities->width = mojom::Range::New(); |
| 386 photo_capabilities->exposure_compensation = mojom::Range::New(); |
| 387 photo_capabilities->fill_light_mode = mojom::FillLightMode::NONE; |
| 388 photo_capabilities->red_eye_reduction = false; |
| 389 callback.Run(std::move(photo_capabilities)); |
| 390 } |
| 391 |
| 392 void V4L2CaptureDelegate::SetPhotoOptions( |
| 393 mojom::PhotoSettingsPtr settings, |
| 394 VideoCaptureDevice::SetPhotoOptionsCallback callback) { |
| 395 if (settings->has_zoom) { |
| 396 v4l2_control zoom_current = {}; |
| 397 zoom_current.id = V4L2_CID_ZOOM_ABSOLUTE; |
| 398 zoom_current.value = settings->zoom / 100; |
| 399 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_CTRL, &zoom_current)) < 0) |
| 400 DLOG(ERROR) << "Error setting zoom value to " << (settings->zoom / 100); |
| 401 } |
| 402 callback.Run(true); |
| 403 } |
| 404 |
| 331 void V4L2CaptureDelegate::SetRotation(int rotation) { | 405 void V4L2CaptureDelegate::SetRotation(int rotation) { |
| 332 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); | 406 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); |
| 333 DCHECK(rotation >= 0 && rotation < 360 && rotation % 90 == 0); | 407 DCHECK(rotation >= 0 && rotation < 360 && rotation % 90 == 0); |
| 334 rotation_ = rotation; | 408 rotation_ = rotation; |
| 335 } | 409 } |
| 336 | 410 |
| 337 V4L2CaptureDelegate::~V4L2CaptureDelegate() {} | 411 V4L2CaptureDelegate::~V4L2CaptureDelegate() {} |
| 338 | 412 |
| 339 bool V4L2CaptureDelegate::MapAndQueueBuffer(int index) { | 413 bool V4L2CaptureDelegate::MapAndQueueBuffer(int index) { |
| 340 v4l2_buffer buffer; | 414 v4l2_buffer buffer; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace"; | 530 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace"; |
| 457 return false; | 531 return false; |
| 458 } | 532 } |
| 459 start_ = static_cast<uint8_t*>(start); | 533 start_ = static_cast<uint8_t*>(start); |
| 460 length_ = buffer.length; | 534 length_ = buffer.length; |
| 461 payload_size_ = 0; | 535 payload_size_ = 0; |
| 462 return true; | 536 return true; |
| 463 } | 537 } |
| 464 | 538 |
| 465 } // namespace media | 539 } // namespace media |
| OLD | NEW |