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

Unified Diff: media/capture/video/linux/video_capture_device_linux.cc

Issue 2508803002: Rotate frames correctly for back camera (Closed)
Patch Set: calculate rotation in video_capture_device_linux Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: media/capture/video/linux/video_capture_device_linux.cc
diff --git a/media/capture/video/linux/video_capture_device_linux.cc b/media/capture/video/linux/video_capture_device_linux.cc
index a1b2855055e853b5e1d9210f5da139f8740ef7ec..d1c69c8423845a07a55896f6f0c2675e3796578c 100644
--- a/media/capture/video/linux/video_capture_device_linux.cc
+++ b/media/capture/video/linux/video_capture_device_linux.cc
@@ -11,6 +11,7 @@
#include "base/bind.h"
#include "base/single_thread_task_runner.h"
#include "build/build_config.h"
+#include "media/capture/video/linux/camera_characteristics.h"
#include "media/capture/video/linux/v4l2_capture_delegate.h"
#if defined(OS_OPENBSD)
@@ -38,7 +39,8 @@ std::list<uint32_t> VideoCaptureDeviceLinux::GetListOfUsableFourCCs(
VideoCaptureDeviceLinux::VideoCaptureDeviceLinux(
const VideoCaptureDeviceDescriptor& device_descriptor)
: v4l2_thread_("V4L2CaptureThread"),
- device_descriptor_(device_descriptor) {}
+ device_descriptor_(device_descriptor),
+ is_back_camera_(GetCameraFacing(device_descriptor)) {}
VideoCaptureDeviceLinux::~VideoCaptureDeviceLinux() {
// Check if the thread is running.
@@ -113,6 +115,12 @@ void VideoCaptureDeviceLinux::SetPhotoOptions(
void VideoCaptureDeviceLinux::SetRotation(int rotation) {
if (v4l2_thread_.IsRunning()) {
+ if (is_back_camera_) {
+ // For back camera, we need to rotate (360 - screen_rotation).
+ // Ex: when screen rotation is 90, we have to rotate the frame by 270
wuchengli 2016/11/17 09:26:04 This example doesn't explain anything. This exampl
+ // clockwise.
+ rotation = (360 - rotation) % 360;
+ }
v4l2_thread_.task_runner()->PostTask(
FROM_HERE,
base::Bind(&V4L2CaptureDelegate::SetRotation, capture_impl_, rotation));
@@ -133,4 +141,11 @@ int VideoCaptureDeviceLinux::TranslatePowerLineFrequencyToV4L2(
}
}
+bool VideoCaptureDeviceLinux::GetCameraFacing(
+ const VideoCaptureDeviceDescriptor& descriptor) {
+ CameraCharacteristics characteristics;
+ return characteristics.GetCameraFacing(descriptor.model_id) ==
+ DeviceInfo::LENS_FACING_BACK;
+}
+
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698