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

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

Issue 2349693003: Image Capture Linux/CrOs: wire some capabilities set/get (Closed)
Patch Set: Created 4 years, 3 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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 is_capturing_ = false; 323 is_capturing_ = false;
324 client_.reset(); 324 client_.reset();
325 } 325 }
326 326
327 void V4L2CaptureDelegate::TakePhoto( 327 void V4L2CaptureDelegate::TakePhoto(
328 VideoCaptureDevice::TakePhotoCallback callback) { 328 VideoCaptureDevice::TakePhotoCallback callback) {
329 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); 329 DCHECK(v4l2_task_runner_->BelongsToCurrentThread());
330 take_photo_callbacks_.push(std::move(callback)); 330 take_photo_callbacks_.push(std::move(callback));
331 } 331 }
332 332
333 void V4L2CaptureDelegate::GetPhotoCapabilities(
334 VideoCaptureDevice::GetPhotoCapabilitiesCallback callback) {
335 DCHECK(v4l2_task_runner_->BelongsToCurrentThread());
336
337 mojom::PhotoCapabilitiesPtr photo_capabilities =
338 mojom::PhotoCapabilities::New();
339
340 photo_capabilities->zoom = mojom::Range::New();
341 v4l2_queryctrl zoom_range = {};
342 zoom_range.id = V4L2_CID_ZOOM_ABSOLUTE;
343 zoom_range.type = V4L2_CTRL_TYPE_INTEGER;
344 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QUERYCTRL, &zoom_range)) >=
345 0) {
346 photo_capabilities->zoom->max = zoom_range.maximum * 100;
347 photo_capabilities->zoom->min = zoom_range.minimum * 100;
348 }
xianglu 2016/09/20 22:18:40 What should be done if there is an error reading t
mcasas 2016/09/21 22:04:58 Nothing, l.340 initializes zoom_range.{minimum, m
349 v4l2_control zoom_current = {};
350 zoom_current.id = V4L2_CID_ZOOM_ABSOLUTE;
351 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_G_CTRL, &zoom_current)) >= 0)
352 photo_capabilities->zoom->current = zoom_current.value * 100;
353
354 photo_capabilities->focus_mode = mojom::MeteringMode::NONE;
355 v4l2_control auto_focus_current = {};
356 auto_focus_current.id = V4L2_CID_FOCUS_AUTO;
357 if (HANDLE_EINTR(
358 ioctl(device_fd_.get(), VIDIOC_G_CTRL, &auto_focus_current)) >= 0) {
359 photo_capabilities->focus_mode = auto_focus_current.value
360 ? mojom::MeteringMode::CONTINUOUS
361 : mojom::MeteringMode::MANUAL;
362 }
363
364 photo_capabilities->exposure_mode = mojom::MeteringMode::NONE;
365 v4l2_control exposure_current = {};
366 exposure_current.id = V4L2_CID_EXPOSURE_AUTO;
367 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_G_CTRL, &exposure_current)) >=
368 0) {
369 photo_capabilities->exposure_mode =
370 exposure_current.value == V4L2_EXPOSURE_MANUAL
371 ? mojom::MeteringMode::MANUAL
372 : mojom::MeteringMode::CONTINUOUS;
373 }
374
375 photo_capabilities->white_balance_mode = mojom::MeteringMode::NONE;
376 v4l2_control white_balance_current = {};
377 white_balance_current.id = V4L2_CID_AUTO_WHITE_BALANCE;
378 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_G_CTRL,
379 &white_balance_current)) >= 0) {
380 photo_capabilities->white_balance_mode =
381 white_balance_current.value ? mojom::MeteringMode::CONTINUOUS
382 : mojom::MeteringMode::MANUAL;
383 }
384
385 photo_capabilities->iso = mojom::Range::New();
386 photo_capabilities->height = mojom::Range::New();
387 photo_capabilities->width = mojom::Range::New();
388 photo_capabilities->exposure_compensation = mojom::Range::New();
389 photo_capabilities->fill_light_mode = mojom::FillLightMode::NONE;
390 photo_capabilities->red_eye_reduction = false;
391 callback.Run(std::move(photo_capabilities));
392 }
393
394 void V4L2CaptureDelegate::SetPhotoOptions(
395 mojom::PhotoSettingsPtr settings,
396 VideoCaptureDevice::SetPhotoOptionsCallback callback) {
397 if (settings->has_zoom) {
398 v4l2_control zoom_current = {};
399 zoom_current.id = V4L2_CID_ZOOM_ABSOLUTE;
400 zoom_current.value = settings->zoom / 100;
401 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_CTRL, &zoom_current)) < 0)
402 DLOG(ERROR) << "Error setting zoom value to " << settings->zoom;
xianglu 2016/09/20 22:18:40 Should it be settings->zoom / 100?
mcasas 2016/09/21 22:04:58 Done.
403 }
404 callback.Run(true);
405 }
406
333 void V4L2CaptureDelegate::SetRotation(int rotation) { 407 void V4L2CaptureDelegate::SetRotation(int rotation) {
334 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); 408 DCHECK(v4l2_task_runner_->BelongsToCurrentThread());
335 DCHECK(rotation >= 0 && rotation < 360 && rotation % 90 == 0); 409 DCHECK(rotation >= 0 && rotation < 360 && rotation % 90 == 0);
336 rotation_ = rotation; 410 rotation_ = rotation;
337 } 411 }
338 412
339 V4L2CaptureDelegate::~V4L2CaptureDelegate() {} 413 V4L2CaptureDelegate::~V4L2CaptureDelegate() {}
340 414
341 bool V4L2CaptureDelegate::MapAndQueueBuffer(int index) { 415 bool V4L2CaptureDelegate::MapAndQueueBuffer(int index) {
342 v4l2_buffer buffer; 416 v4l2_buffer buffer;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace"; 584 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace";
511 return false; 585 return false;
512 } 586 }
513 start_ = static_cast<uint8_t*>(start); 587 start_ = static_cast<uint8_t*>(start);
514 length_ = buffer.length; 588 length_ = buffer.length;
515 payload_size_ = 0; 589 payload_size_ = 0;
516 return true; 590 return true;
517 } 591 }
518 592
519 } // namespace media 593 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/linux/v4l2_capture_delegate.h ('k') | media/capture/video/linux/video_capture_device_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698