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

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

Issue 558663006: Linux video capture: rotate image if V4L2_IN_ST_VFLIP is set (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: check number of input types Created 6 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
« 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/video/capture/linux/video_capture_device_linux.h" 5 #include "media/video/capture/linux/video_capture_device_linux.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #if defined(OS_OPENBSD) 9 #if defined(OS_OPENBSD)
10 #include <sys/videoio.h> 10 #include <sys/videoio.h>
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 0) { 243 0) {
244 best = std::find(v4l2_formats.begin(), best, fmtdesc.pixelformat); 244 best = std::find(v4l2_formats.begin(), best, fmtdesc.pixelformat);
245 fmtdesc.index++; 245 fmtdesc.index++;
246 } 246 }
247 247
248 if (best == v4l2_formats.end()) { 248 if (best == v4l2_formats.end()) {
249 SetErrorState("Failed to find a supported camera format."); 249 SetErrorState("Failed to find a supported camera format.");
250 return; 250 return;
251 } 251 }
252 252
253 // Check sensor orientation.
254 struct v4l2_input first_input;
255 first_input.index = 0; // First input type.
256 if (HANDLE_EINTR(ioctl(device_fd_.get(),
257 VIDIOC_ENUMINPUT, &first_input)) == 0) {
258 struct v4l2_input second_input;
259 second_input.index = 1;
260 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_ENUMINPUT,
261 &second_input)) < 0) {
262 // Only one input type
263 if (first_input.status & V4L2_IN_ST_VFLIP) {
264 DVLOG(1) << "Sensor is flipped vertically, rotating 180 deg.";
265 if (!(first_input.status & V4L2_IN_ST_HFLIP)) {
266 DVLOG(1) << "Sensor is only flipped vertically, "
267 "image will be mirrored";
268 }
269 SetRotation(180);
270 }
271 } else {
272 // More than one input type, don't try to fix sensor orientation.
273 DVLOG(1) << "Video capture device has more than one input type";
274 }
275 } else {
276 DVLOG(1) << "Failed to enumerate video input";
277 }
278
253 // Set format and frame size now. 279 // Set format and frame size now.
254 v4l2_format video_fmt; 280 v4l2_format video_fmt;
255 memset(&video_fmt, 0, sizeof(v4l2_format)); 281 memset(&video_fmt, 0, sizeof(v4l2_format));
256 video_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 282 video_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
257 video_fmt.fmt.pix.sizeimage = 0; 283 video_fmt.fmt.pix.sizeimage = 0;
258 video_fmt.fmt.pix.width = width; 284 video_fmt.fmt.pix.width = width;
259 video_fmt.fmt.pix.height = height; 285 video_fmt.fmt.pix.height = height;
260 video_fmt.fmt.pix.pixelformat = *best; 286 video_fmt.fmt.pix.pixelformat = *best;
261 287
262 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_FMT, &video_fmt)) < 0) { 288 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_FMT, &video_fmt)) < 0) {
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 } 531 }
506 532
507 void VideoCaptureDeviceLinux::SetErrorState(const std::string& reason) { 533 void VideoCaptureDeviceLinux::SetErrorState(const std::string& reason) {
508 DCHECK(!v4l2_thread_.IsRunning() || 534 DCHECK(!v4l2_thread_.IsRunning() ||
509 v4l2_thread_.message_loop() == base::MessageLoop::current()); 535 v4l2_thread_.message_loop() == base::MessageLoop::current());
510 state_ = kError; 536 state_ = kError;
511 client_->OnError(reason); 537 client_->OnError(reason);
512 } 538 }
513 539
514 } // namespace media 540 } // 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