Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: media/capture/video/linux/v4l2_capture_delegate.cc

Issue 2375543004: ImageCapture: wire |colorTemperature| set/get for Linux/Cros (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 photo_capabilities->white_balance_mode = mojom::MeteringMode::NONE; 379 photo_capabilities->white_balance_mode = mojom::MeteringMode::NONE;
380 v4l2_control white_balance_current = {}; 380 v4l2_control white_balance_current = {};
381 white_balance_current.id = V4L2_CID_AUTO_WHITE_BALANCE; 381 white_balance_current.id = V4L2_CID_AUTO_WHITE_BALANCE;
382 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_G_CTRL, 382 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_G_CTRL,
383 &white_balance_current)) >= 0) { 383 &white_balance_current)) >= 0) {
384 photo_capabilities->white_balance_mode = 384 photo_capabilities->white_balance_mode =
385 white_balance_current.value ? mojom::MeteringMode::CONTINUOUS 385 white_balance_current.value ? mojom::MeteringMode::CONTINUOUS
386 : mojom::MeteringMode::MANUAL; 386 : mojom::MeteringMode::MANUAL;
387 } 387 }
388 388
389 photo_capabilities->color_temperature = mojom::Range::New();
390 v4l2_queryctrl color_temperature_range = {};
391 color_temperature_range.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE;
392 color_temperature_range.type = V4L2_CTRL_TYPE_INTEGER;
393 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QUERYCTRL,
394 &color_temperature_range)) >= 0) {
395 photo_capabilities->color_temperature->max =
396 color_temperature_range.maximum;
397 photo_capabilities->color_temperature->min =
398 color_temperature_range.minimum;
399 }
400
401 v4l2_control color_temperature_current = {};
402 color_temperature_current.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE;
403 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_G_CTRL,
404 &color_temperature_current)) >= 0) {
405 photo_capabilities->color_temperature->current =
406 color_temperature_current.value;
chfremer 2016/09/27 21:46:39 nit: I am somewhat surprised that something called
mcasas 2016/09/27 21:57:38 Yeah heh, it comes straight from the W3C Spec: htt
407 }
408
389 photo_capabilities->iso = mojom::Range::New(); 409 photo_capabilities->iso = mojom::Range::New();
390 photo_capabilities->height = mojom::Range::New(); 410 photo_capabilities->height = mojom::Range::New();
391 photo_capabilities->width = mojom::Range::New(); 411 photo_capabilities->width = mojom::Range::New();
392 photo_capabilities->exposure_compensation = mojom::Range::New(); 412 photo_capabilities->exposure_compensation = mojom::Range::New();
393 photo_capabilities->fill_light_mode = mojom::FillLightMode::NONE; 413 photo_capabilities->fill_light_mode = mojom::FillLightMode::NONE;
394 photo_capabilities->red_eye_reduction = false; 414 photo_capabilities->red_eye_reduction = false;
395 callback.Run(std::move(photo_capabilities)); 415 callback.Run(std::move(photo_capabilities));
396 } 416 }
397 417
398 void V4L2CaptureDelegate::SetPhotoOptions( 418 void V4L2CaptureDelegate::SetPhotoOptions(
399 mojom::PhotoSettingsPtr settings, 419 mojom::PhotoSettingsPtr settings,
400 VideoCaptureDevice::SetPhotoOptionsCallback callback) { 420 VideoCaptureDevice::SetPhotoOptionsCallback callback) {
401 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); 421 DCHECK(v4l2_task_runner_->BelongsToCurrentThread());
402 if (!device_fd_.is_valid() || !is_capturing_) 422 if (!device_fd_.is_valid() || !is_capturing_)
403 return; 423 return;
404 424
405 if (settings->has_zoom) { 425 if (settings->has_zoom) {
406 v4l2_control zoom_current = {}; 426 v4l2_control zoom_current = {};
407 zoom_current.id = V4L2_CID_ZOOM_ABSOLUTE; 427 zoom_current.id = V4L2_CID_ZOOM_ABSOLUTE;
408 zoom_current.value = settings->zoom / kZoomMultiplier; 428 zoom_current.value = settings->zoom / kZoomMultiplier;
409 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_CTRL, &zoom_current)) < 0) 429 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_CTRL, &zoom_current)) < 0)
410 DPLOG(ERROR) << "setting zoom to " << settings->zoom / kZoomMultiplier; 430 DPLOG(ERROR) << "setting zoom to " << settings->zoom / kZoomMultiplier;
411 } 431 }
432
433 if (settings->has_white_balance_mode &&
434 (settings->white_balance_mode == mojom::MeteringMode::CONTINUOUS ||
435 settings->white_balance_mode == mojom::MeteringMode::MANUAL)) {
436 v4l2_control white_balance_set = {};
437 white_balance_set.id = V4L2_CID_AUTO_WHITE_BALANCE;
438 white_balance_set.value =
439 settings->white_balance_mode == mojom::MeteringMode::CONTINUOUS;
440 HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_CTRL, &white_balance_set));
441 }
442
443 // Color temperature can only be applied if Auto White Balance is off.
chfremer 2016/09/27 21:46:39 If auto white balance is on, we just ignore the re
mcasas 2016/09/27 21:57:38 Yeah, hmm, the Spec says so: " This field is only
444 if (settings->has_color_temperature) {
445 v4l2_control auto_white_balance_current = {};
446 auto_white_balance_current.id = V4L2_CID_AUTO_WHITE_BALANCE;
447 const int result = HANDLE_EINTR(
448 ioctl(device_fd_.get(), VIDIOC_G_CTRL, &auto_white_balance_current));
449 if (result >= 0 && !auto_white_balance_current.value) {
450 v4l2_control set_temperature = {};
451 set_temperature.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE;
452 set_temperature.value = settings->color_temperature;
453 HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_CTRL, &set_temperature));
454 }
455 }
456
412 callback.Run(true); 457 callback.Run(true);
413 } 458 }
414 459
415 void V4L2CaptureDelegate::SetRotation(int rotation) { 460 void V4L2CaptureDelegate::SetRotation(int rotation) {
416 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); 461 DCHECK(v4l2_task_runner_->BelongsToCurrentThread());
417 DCHECK(rotation >= 0 && rotation < 360 && rotation % 90 == 0); 462 DCHECK(rotation >= 0 && rotation < 360 && rotation % 90 == 0);
418 rotation_ = rotation; 463 rotation_ = rotation;
419 } 464 }
420 465
421 V4L2CaptureDelegate::~V4L2CaptureDelegate() {} 466 V4L2CaptureDelegate::~V4L2CaptureDelegate() {}
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace"; 585 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace";
541 return false; 586 return false;
542 } 587 }
543 start_ = static_cast<uint8_t*>(start); 588 start_ = static_cast<uint8_t*>(start);
544 length_ = buffer.length; 589 length_ = buffer.length;
545 payload_size_ = 0; 590 payload_size_ = 0;
546 return true; 591 return true;
547 } 592 }
548 593
549 } // namespace media 594 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/fake_video_capture_device_unittest.cc ('k') | media/mojo/interfaces/image_capture.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698