| 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> |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 v4l2_control exposure_current = {}; | 587 v4l2_control exposure_current = {}; |
| 588 exposure_current.id = V4L2_CID_EXPOSURE_AUTO; | 588 exposure_current.id = V4L2_CID_EXPOSURE_AUTO; |
| 589 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)) >= |
| 590 0) { | 590 0) { |
| 591 photo_capabilities->current_exposure_mode = | 591 photo_capabilities->current_exposure_mode = |
| 592 exposure_current.value == V4L2_EXPOSURE_MANUAL | 592 exposure_current.value == V4L2_EXPOSURE_MANUAL |
| 593 ? MeteringMode::MANUAL | 593 ? MeteringMode::MANUAL |
| 594 : MeteringMode::CONTINUOUS; | 594 : MeteringMode::CONTINUOUS; |
| 595 } | 595 } |
| 596 | 596 |
| 597 photo_capabilities->exposure_compensation = |
| 598 RetrieveUserControlRange(device_fd_.get(), V4L2_CID_EXPOSURE_ABSOLUTE); |
| 599 |
| 597 photo_capabilities->color_temperature = RetrieveUserControlRange( | 600 photo_capabilities->color_temperature = RetrieveUserControlRange( |
| 598 device_fd_.get(), V4L2_CID_WHITE_BALANCE_TEMPERATURE); | 601 device_fd_.get(), V4L2_CID_WHITE_BALANCE_TEMPERATURE); |
| 599 if (photo_capabilities->color_temperature) { | 602 if (photo_capabilities->color_temperature) { |
| 600 photo_capabilities->supported_white_balance_modes.push_back( | 603 photo_capabilities->supported_white_balance_modes.push_back( |
| 601 MeteringMode::MANUAL); | 604 MeteringMode::MANUAL); |
| 602 } | 605 } |
| 603 | 606 |
| 604 v4l2_queryctrl white_balance_ctrl = {}; | 607 v4l2_queryctrl white_balance_ctrl = {}; |
| 605 white_balance_ctrl.id = V4L2_CID_AUTO_WHITE_BALANCE; | 608 white_balance_ctrl.id = V4L2_CID_AUTO_WHITE_BALANCE; |
| 606 if (RunIoctl(device_fd_.get(), VIDIOC_QUERYCTRL, &white_balance_ctrl)) { | 609 if (RunIoctl(device_fd_.get(), VIDIOC_QUERYCTRL, &white_balance_ctrl)) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 618 : MeteringMode::MANUAL; | 621 : MeteringMode::MANUAL; |
| 619 } | 622 } |
| 620 | 623 |
| 621 photo_capabilities->iso = mojom::Range::New(); | 624 photo_capabilities->iso = mojom::Range::New(); |
| 622 photo_capabilities->height = mojom::Range::New( | 625 photo_capabilities->height = mojom::Range::New( |
| 623 capture_format_.frame_size.height(), capture_format_.frame_size.height(), | 626 capture_format_.frame_size.height(), capture_format_.frame_size.height(), |
| 624 capture_format_.frame_size.height(), 0 /* step */); | 627 capture_format_.frame_size.height(), 0 /* step */); |
| 625 photo_capabilities->width = mojom::Range::New( | 628 photo_capabilities->width = mojom::Range::New( |
| 626 capture_format_.frame_size.width(), capture_format_.frame_size.width(), | 629 capture_format_.frame_size.width(), capture_format_.frame_size.width(), |
| 627 capture_format_.frame_size.width(), 0 /* step */); | 630 capture_format_.frame_size.width(), 0 /* step */); |
| 628 photo_capabilities->exposure_compensation = mojom::Range::New(); | |
| 629 photo_capabilities->red_eye_reduction = mojom::RedEyeReduction::NEVER; | 631 photo_capabilities->red_eye_reduction = mojom::RedEyeReduction::NEVER; |
| 630 photo_capabilities->torch = false; | 632 photo_capabilities->torch = false; |
| 631 | 633 |
| 632 photo_capabilities->brightness = | 634 photo_capabilities->brightness = |
| 633 RetrieveUserControlRange(device_fd_.get(), V4L2_CID_BRIGHTNESS); | 635 RetrieveUserControlRange(device_fd_.get(), V4L2_CID_BRIGHTNESS); |
| 634 photo_capabilities->contrast = | 636 photo_capabilities->contrast = |
| 635 RetrieveUserControlRange(device_fd_.get(), V4L2_CID_CONTRAST); | 637 RetrieveUserControlRange(device_fd_.get(), V4L2_CID_CONTRAST); |
| 636 photo_capabilities->saturation = | 638 photo_capabilities->saturation = |
| 637 RetrieveUserControlRange(device_fd_.get(), V4L2_CID_SATURATION); | 639 RetrieveUserControlRange(device_fd_.get(), V4L2_CID_SATURATION); |
| 638 photo_capabilities->sharpness = | 640 photo_capabilities->sharpness = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 659 if (settings->has_white_balance_mode && | 661 if (settings->has_white_balance_mode && |
| 660 (settings->white_balance_mode == mojom::MeteringMode::CONTINUOUS || | 662 (settings->white_balance_mode == mojom::MeteringMode::CONTINUOUS || |
| 661 settings->white_balance_mode == mojom::MeteringMode::MANUAL)) { | 663 settings->white_balance_mode == mojom::MeteringMode::MANUAL)) { |
| 662 v4l2_control white_balance_set = {}; | 664 v4l2_control white_balance_set = {}; |
| 663 white_balance_set.id = V4L2_CID_AUTO_WHITE_BALANCE; | 665 white_balance_set.id = V4L2_CID_AUTO_WHITE_BALANCE; |
| 664 white_balance_set.value = | 666 white_balance_set.value = |
| 665 settings->white_balance_mode == mojom::MeteringMode::CONTINUOUS; | 667 settings->white_balance_mode == mojom::MeteringMode::CONTINUOUS; |
| 666 HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_CTRL, &white_balance_set)); | 668 HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_CTRL, &white_balance_set)); |
| 667 } | 669 } |
| 668 | 670 |
| 669 // Color temperature can only be applied if Auto White Balance is off. | |
| 670 if (settings->has_color_temperature) { | 671 if (settings->has_color_temperature) { |
| 671 v4l2_control auto_white_balance_current = {}; | 672 v4l2_control auto_white_balance_current = {}; |
| 672 auto_white_balance_current.id = V4L2_CID_AUTO_WHITE_BALANCE; | 673 auto_white_balance_current.id = V4L2_CID_AUTO_WHITE_BALANCE; |
| 673 const int result = HANDLE_EINTR( | 674 const int result = HANDLE_EINTR( |
| 674 ioctl(device_fd_.get(), VIDIOC_G_CTRL, &auto_white_balance_current)); | 675 ioctl(device_fd_.get(), VIDIOC_G_CTRL, &auto_white_balance_current)); |
| 676 // Color temperature can only be applied if Auto White Balance is off. |
| 675 if (result >= 0 && !auto_white_balance_current.value) { | 677 if (result >= 0 && !auto_white_balance_current.value) { |
| 676 v4l2_control set_temperature = {}; | 678 v4l2_control set_temperature = {}; |
| 677 set_temperature.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE; | 679 set_temperature.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE; |
| 678 set_temperature.value = settings->color_temperature; | 680 set_temperature.value = settings->color_temperature; |
| 679 HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_CTRL, &set_temperature)); | 681 HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_CTRL, &set_temperature)); |
| 680 } | 682 } |
| 681 } | 683 } |
| 682 | 684 |
| 685 if (settings->has_exposure_mode && |
| 686 (settings->exposure_mode == mojom::MeteringMode::CONTINUOUS || |
| 687 settings->exposure_mode == mojom::MeteringMode::MANUAL)) { |
| 688 v4l2_control exposure_mode_set = {}; |
| 689 exposure_mode_set.id = V4L2_CID_EXPOSURE_AUTO; |
| 690 exposure_mode_set.value = |
| 691 settings->exposure_mode == mojom::MeteringMode::CONTINUOUS |
| 692 ? V4L2_EXPOSURE_APERTURE_PRIORITY |
| 693 : V4L2_EXPOSURE_MANUAL; |
| 694 HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_CTRL, &exposure_mode_set)); |
| 695 } |
| 696 |
| 697 if (settings->has_exposure_compensation) { |
| 698 v4l2_control auto_exposure_current = {}; |
| 699 auto_exposure_current.id = V4L2_CID_EXPOSURE_AUTO; |
| 700 const int result = HANDLE_EINTR( |
| 701 ioctl(device_fd_.get(), VIDIOC_G_CTRL, &auto_exposure_current)); |
| 702 // Exposure Compensation can only be applied if Auto Exposure is off. |
| 703 if (result >= 0 && auto_exposure_current.value == V4L2_EXPOSURE_MANUAL) { |
| 704 v4l2_control set_exposure = {}; |
| 705 set_exposure.id = V4L2_CID_EXPOSURE_ABSOLUTE; |
| 706 set_exposure.value = settings->exposure_compensation; |
| 707 HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_CTRL, &set_exposure)); |
| 708 } |
| 709 } |
| 710 |
| 683 if (settings->has_brightness) { | 711 if (settings->has_brightness) { |
| 684 v4l2_control current = {}; | 712 v4l2_control current = {}; |
| 685 current.id = V4L2_CID_BRIGHTNESS; | 713 current.id = V4L2_CID_BRIGHTNESS; |
| 686 current.value = settings->brightness; | 714 current.value = settings->brightness; |
| 687 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_CTRL, ¤t)) < 0) | 715 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_CTRL, ¤t)) < 0) |
| 688 DPLOG(ERROR) << "setting brightness to " << settings->brightness; | 716 DPLOG(ERROR) << "setting brightness to " << settings->brightness; |
| 689 } | 717 } |
| 690 if (settings->has_contrast) { | 718 if (settings->has_contrast) { |
| 691 v4l2_control current = {}; | 719 v4l2_control current = {}; |
| 692 current.id = V4L2_CID_CONTRAST; | 720 current.id = V4L2_CID_CONTRAST; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace"; | 882 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace"; |
| 855 return false; | 883 return false; |
| 856 } | 884 } |
| 857 start_ = static_cast<uint8_t*>(start); | 885 start_ = static_cast<uint8_t*>(start); |
| 858 length_ = buffer.length; | 886 length_ = buffer.length; |
| 859 payload_size_ = 0; | 887 payload_size_ = 0; |
| 860 return true; | 888 return true; |
| 861 } | 889 } |
| 862 | 890 |
| 863 } // namespace media | 891 } // namespace media |
| OLD | NEW |