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

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

Issue 2568883005: ImageCapture v4l2: reset user controls when opening the device (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 client_ = std::move(client); 351 client_ = std::move(client);
352 352
353 // Need to open camera with O_RDWR after Linux kernel 3.3. 353 // Need to open camera with O_RDWR after Linux kernel 3.3.
354 device_fd_.reset( 354 device_fd_.reset(
355 HANDLE_EINTR(open(device_descriptor_.device_id.c_str(), O_RDWR))); 355 HANDLE_EINTR(open(device_descriptor_.device_id.c_str(), O_RDWR)));
356 if (!device_fd_.is_valid()) { 356 if (!device_fd_.is_valid()) {
357 SetErrorState(FROM_HERE, "Failed to open V4L2 device driver file."); 357 SetErrorState(FROM_HERE, "Failed to open V4L2 device driver file.");
358 return; 358 return;
359 } 359 }
360 360
361 ResetUserAndCameraControlsToDefault(device_fd_.get());
362
361 v4l2_capability cap = {}; 363 v4l2_capability cap = {};
362 if (!((HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QUERYCAP, &cap)) == 0) && 364 if (!((HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QUERYCAP, &cap)) == 0) &&
363 ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) && 365 ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) &&
364 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)))) { 366 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)))) {
365 device_fd_.reset(); 367 device_fd_.reset();
366 SetErrorState(FROM_HERE, "This is not a V4L2 video capture device"); 368 SetErrorState(FROM_HERE, "This is not a V4L2 video capture device");
367 return; 369 return;
368 } 370 }
369 371
370 // Get supported video formats in preferred order. For large resolutions, 372 // Get supported video formats in preferred order. For large resolutions,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 return; 483 return;
482 } 484 }
483 485
484 buffer_tracker_pool_.clear(); 486 buffer_tracker_pool_.clear();
485 487
486 v4l2_requestbuffers r_buffer; 488 v4l2_requestbuffers r_buffer;
487 FillV4L2RequestBuffer(&r_buffer, 0); 489 FillV4L2RequestBuffer(&r_buffer, 0);
488 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_REQBUFS, &r_buffer)) < 0) 490 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_REQBUFS, &r_buffer)) < 0)
489 SetErrorState(FROM_HERE, "Failed to VIDIOC_REQBUFS with count = 0"); 491 SetErrorState(FROM_HERE, "Failed to VIDIOC_REQBUFS with count = 0");
490 492
491 ResetUserAndCameraControlsToDefault(device_fd_.get());
492 // At this point we can close the device. 493 // At this point we can close the device.
493 // This is also needed for correctly changing settings later via VIDIOC_S_FMT. 494 // This is also needed for correctly changing settings later via VIDIOC_S_FMT.
494 device_fd_.reset(); 495 device_fd_.reset();
495 is_capturing_ = false; 496 is_capturing_ = false;
496 client_.reset(); 497 client_.reset();
497 } 498 }
498 499
499 void V4L2CaptureDelegate::TakePhoto( 500 void V4L2CaptureDelegate::TakePhoto(
500 VideoCaptureDevice::TakePhotoCallback callback) { 501 VideoCaptureDevice::TakePhotoCallback callback) {
501 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); 502 DCHECK(v4l2_task_runner_->BelongsToCurrentThread());
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace"; 781 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace";
781 return false; 782 return false;
782 } 783 }
783 start_ = static_cast<uint8_t*>(start); 784 start_ = static_cast<uint8_t*>(start);
784 length_ = buffer.length; 785 length_ = buffer.length;
785 payload_size_ = 0; 786 payload_size_ = 0;
786 return true; 787 return true;
787 } 788 }
788 789
789 } // namespace media 790 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698