Index: media/video/capture/linux/video_capture_device_linux.cc |
diff --git a/media/video/capture/linux/video_capture_device_linux.cc b/media/video/capture/linux/video_capture_device_linux.cc |
index 0192daba3e7e2807a827edd1e6f35a9e8512bbcf..e7f2e23e1edd1d04ba4669428bb8e70091090ada 100644 |
--- a/media/video/capture/linux/video_capture_device_linux.cc |
+++ b/media/video/capture/linux/video_capture_device_linux.cc |
@@ -250,6 +250,32 @@ void VideoCaptureDeviceLinux::OnAllocateAndStart(int width, |
return; |
} |
+ // Check sensor orientation. |
+ struct v4l2_input first_input; |
+ first_input.index = 0; // First input type. |
+ if (HANDLE_EINTR(ioctl(device_fd_.get(), |
+ VIDIOC_ENUMINPUT, &first_input)) == 0) { |
+ struct v4l2_input second_input; |
+ second_input.index = 1; |
+ if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_ENUMINPUT, |
+ &second_input)) < 0) { |
+ // Only one input type |
+ if (first_input.status & V4L2_IN_ST_VFLIP) { |
+ DVLOG(1) << "Sensor is flipped vertically, rotating 180 deg."; |
+ if (!(first_input.status & V4L2_IN_ST_HFLIP)) { |
+ DVLOG(1) << "Sensor is only flipped vertically, " |
+ "image will be mirrored"; |
+ } |
+ SetRotation(180); |
+ } |
+ } else { |
+ // More than one input type, don't try to fix sensor orientation. |
+ DVLOG(1) << "Video capture device has more than one input type"; |
+ } |
+ } else { |
+ DVLOG(1) << "Failed to enumerate video input"; |
+ } |
+ |
// Set format and frame size now. |
v4l2_format video_fmt; |
memset(&video_fmt, 0, sizeof(v4l2_format)); |