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 <linux/version.h> | 7 #include <linux/version.h> |
8 #include <linux/videodev2.h> | 8 #include <linux/videodev2.h> |
9 #include <poll.h> | 9 #include <poll.h> |
10 #include <sys/fcntl.h> | 10 #include <sys/fcntl.h> |
11 #include <sys/ioctl.h> | 11 #include <sys/ioctl.h> |
12 #include <sys/mman.h> | 12 #include <sys/mman.h> |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/files/file_enumerator.h" | 16 #include "base/files/file_enumerator.h" |
17 #include "base/posix/eintr_wrapper.h" | 17 #include "base/posix/eintr_wrapper.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "media/base/bind_to_current_loop.h" | 20 #include "media/base/bind_to_current_loop.h" |
21 #include "media/capture/video/blob_utils.h" | 21 #include "media/capture/video/blob_utils.h" |
22 #include "media/capture/video/linux/video_capture_device_linux.h" | 22 #include "media/capture/video/linux/video_capture_device_linux.h" |
23 | 23 |
24 using media::mojom::MeteringMode; | |
25 | |
24 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0) | 26 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0) |
25 // 16 bit depth, Realsense F200. | 27 // 16 bit depth, Realsense F200. |
26 #define V4L2_PIX_FMT_Z16 v4l2_fourcc('Z', '1', '6', ' ') | 28 #define V4L2_PIX_FMT_Z16 v4l2_fourcc('Z', '1', '6', ' ') |
27 #endif | 29 #endif |
28 | 30 |
29 // TODO(aleksandar.stojiljkovic): Wrap this with kernel version check once the | 31 // TODO(aleksandar.stojiljkovic): Wrap this with kernel version check once the |
30 // format is introduced to kernel. | 32 // format is introduced to kernel. |
31 // See https://crbug.com/661877 | 33 // See https://crbug.com/661877 |
32 #ifndef V4L2_PIX_FMT_INVZ | 34 #ifndef V4L2_PIX_FMT_INVZ |
33 // 16 bit depth, Realsense SR300. | 35 // 16 bit depth, Realsense SR300. |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); | 545 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); |
544 if (!device_fd_.is_valid() || !is_capturing_) | 546 if (!device_fd_.is_valid() || !is_capturing_) |
545 return; | 547 return; |
546 | 548 |
547 mojom::PhotoCapabilitiesPtr photo_capabilities = | 549 mojom::PhotoCapabilitiesPtr photo_capabilities = |
548 mojom::PhotoCapabilities::New(); | 550 mojom::PhotoCapabilities::New(); |
549 | 551 |
550 photo_capabilities->zoom = | 552 photo_capabilities->zoom = |
551 RetrieveUserControlRange(device_fd_.get(), V4L2_CID_ZOOM_ABSOLUTE); | 553 RetrieveUserControlRange(device_fd_.get(), V4L2_CID_ZOOM_ABSOLUTE); |
552 | 554 |
553 photo_capabilities->focus_mode = mojom::MeteringMode::NONE; | 555 v4l2_queryctrl manual_focus_ctrl = {}; |
556 manual_focus_ctrl.id = V4L2_CID_FOCUS_ABSOLUTE; | |
557 if (RunIoctl(device_fd_.get(), VIDIOC_QUERYCTRL, &manual_focus_ctrl)) | |
Reilly Grant (use Gerrit)
2017/04/08 00:30:52
This function didn't previously use RunIoctl. I'm
mcasas
2017/04/08 00:50:45
It did use RunIoctl() before, but it's hidden insi
| |
558 photo_capabilities->supported_focus_modes.push_back(MeteringMode::MANUAL); | |
559 | |
560 v4l2_queryctrl auto_focus_ctrl = {}; | |
561 auto_focus_ctrl.id = V4L2_CID_FOCUS_AUTO; | |
562 if (RunIoctl(device_fd_.get(), VIDIOC_QUERYCTRL, &auto_focus_ctrl)) { | |
563 photo_capabilities->supported_focus_modes.push_back( | |
564 MeteringMode::CONTINUOUS); | |
565 } | |
566 | |
567 photo_capabilities->current_focus_mode = MeteringMode::NONE; | |
554 v4l2_control auto_focus_current = {}; | 568 v4l2_control auto_focus_current = {}; |
555 auto_focus_current.id = V4L2_CID_FOCUS_AUTO; | 569 auto_focus_current.id = V4L2_CID_FOCUS_AUTO; |
556 if (HANDLE_EINTR( | 570 if (HANDLE_EINTR( |
557 ioctl(device_fd_.get(), VIDIOC_G_CTRL, &auto_focus_current)) >= 0) { | 571 ioctl(device_fd_.get(), VIDIOC_G_CTRL, &auto_focus_current)) >= 0) { |
558 photo_capabilities->focus_mode = auto_focus_current.value | 572 photo_capabilities->current_focus_mode = auto_focus_current.value |
559 ? mojom::MeteringMode::CONTINUOUS | 573 ? MeteringMode::CONTINUOUS |
560 : mojom::MeteringMode::MANUAL; | 574 : MeteringMode::MANUAL; |
561 } | 575 } |
562 | 576 |
563 photo_capabilities->exposure_mode = mojom::MeteringMode::NONE; | 577 v4l2_queryctrl auto_exposure_ctrl = {}; |
578 auto_exposure_ctrl.id = V4L2_CID_EXPOSURE_AUTO; | |
579 if (RunIoctl(device_fd_.get(), VIDIOC_QUERYCTRL, &auto_exposure_ctrl)) { | |
580 photo_capabilities->supported_exposure_modes.push_back( | |
581 MeteringMode::MANUAL); | |
582 photo_capabilities->supported_exposure_modes.push_back( | |
583 MeteringMode::CONTINUOUS); | |
584 } | |
585 | |
586 photo_capabilities->current_exposure_mode = MeteringMode::NONE; | |
564 v4l2_control exposure_current = {}; | 587 v4l2_control exposure_current = {}; |
565 exposure_current.id = V4L2_CID_EXPOSURE_AUTO; | 588 exposure_current.id = V4L2_CID_EXPOSURE_AUTO; |
566 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_G_CTRL, &exposure_current)) >= | 589 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_G_CTRL, &exposure_current)) >= |
567 0) { | 590 0) { |
568 photo_capabilities->exposure_mode = | 591 photo_capabilities->current_exposure_mode = |
569 exposure_current.value == V4L2_EXPOSURE_MANUAL | 592 exposure_current.value == V4L2_EXPOSURE_MANUAL |
570 ? mojom::MeteringMode::MANUAL | 593 ? MeteringMode::MANUAL |
571 : mojom::MeteringMode::CONTINUOUS; | 594 : MeteringMode::CONTINUOUS; |
572 } | 595 } |
573 | 596 |
574 photo_capabilities->white_balance_mode = mojom::MeteringMode::NONE; | 597 photo_capabilities->color_temperature = RetrieveUserControlRange( |
598 device_fd_.get(), V4L2_CID_WHITE_BALANCE_TEMPERATURE); | |
599 if (photo_capabilities->color_temperature) { | |
600 photo_capabilities->supported_white_balance_modes.push_back( | |
601 MeteringMode::MANUAL); | |
602 } | |
603 | |
604 v4l2_queryctrl white_balance_ctrl = {}; | |
605 white_balance_ctrl.id = V4L2_CID_AUTO_WHITE_BALANCE; | |
606 if (RunIoctl(device_fd_.get(), VIDIOC_QUERYCTRL, &white_balance_ctrl) && | |
607 !(white_balance_ctrl.flags && V4L2_CTRL_FLAG_DISABLED)) { | |
608 photo_capabilities->supported_white_balance_modes.push_back( | |
609 MeteringMode::CONTINUOUS); | |
610 } | |
611 | |
612 photo_capabilities->current_white_balance_mode = MeteringMode::NONE; | |
575 v4l2_control white_balance_current = {}; | 613 v4l2_control white_balance_current = {}; |
576 white_balance_current.id = V4L2_CID_AUTO_WHITE_BALANCE; | 614 white_balance_current.id = V4L2_CID_AUTO_WHITE_BALANCE; |
577 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_G_CTRL, | 615 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_G_CTRL, |
578 &white_balance_current)) >= 0) { | 616 &white_balance_current)) >= 0) { |
579 photo_capabilities->white_balance_mode = | 617 photo_capabilities->current_white_balance_mode = |
580 white_balance_current.value ? mojom::MeteringMode::CONTINUOUS | 618 white_balance_current.value ? MeteringMode::CONTINUOUS |
581 : mojom::MeteringMode::MANUAL; | 619 : MeteringMode::MANUAL; |
582 } | 620 } |
583 | 621 |
584 photo_capabilities->color_temperature = RetrieveUserControlRange( | |
585 device_fd_.get(), V4L2_CID_WHITE_BALANCE_TEMPERATURE); | |
586 | |
587 photo_capabilities->iso = mojom::Range::New(); | 622 photo_capabilities->iso = mojom::Range::New(); |
588 photo_capabilities->height = mojom::Range::New(); | 623 photo_capabilities->height = mojom::Range::New(); |
589 photo_capabilities->width = mojom::Range::New(); | 624 photo_capabilities->width = mojom::Range::New(); |
590 photo_capabilities->exposure_compensation = mojom::Range::New(); | 625 photo_capabilities->exposure_compensation = mojom::Range::New(); |
591 photo_capabilities->red_eye_reduction = mojom::RedEyeReduction::NEVER; | 626 photo_capabilities->red_eye_reduction = mojom::RedEyeReduction::NEVER; |
592 photo_capabilities->torch = false; | 627 photo_capabilities->torch = false; |
593 | 628 |
594 photo_capabilities->brightness = | 629 photo_capabilities->brightness = |
595 RetrieveUserControlRange(device_fd_.get(), V4L2_CID_BRIGHTNESS); | 630 RetrieveUserControlRange(device_fd_.get(), V4L2_CID_BRIGHTNESS); |
596 photo_capabilities->contrast = | 631 photo_capabilities->contrast = |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
816 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace"; | 851 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace"; |
817 return false; | 852 return false; |
818 } | 853 } |
819 start_ = static_cast<uint8_t*>(start); | 854 start_ = static_cast<uint8_t*>(start); |
820 length_ = buffer.length; | 855 length_ = buffer.length; |
821 payload_size_ = 0; | 856 payload_size_ = 0; |
822 return true; | 857 return true; |
823 } | 858 } |
824 | 859 |
825 } // namespace media | 860 } // namespace media |
OLD | NEW |