summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Strømme <christian.stromme@qt.io>2017-04-04 13:10:02 +0200
committerChristian Stromme <christian.stromme@qt.io>2017-04-20 13:20:43 +0000
commit021e8989308fba30425e7a0f34f4e176a8aa3ccf (patch)
tree02e885adf87a052344ad77bb8908c5b5e247478e
parent7caf543280bf8bdb0d3ea18d6c1a2537fdccfe6e (diff)
downloadqtmultimedia-021e8989308fba30425e7a0f34f4e176a8aa3ccf.tar.gz
Android: Fix camera preview orientation
Before API level 24 the display orientation (the preview) was always set to 0. On newer versions of Android the clockwise rotation is set to be either 0 or 180, depending on the hardware. Since we don't want Android to apply transformation on our surface, we'll just enforce that the display orientation is always set to 0. Task-number: QTBUG-56536 Change-Id: Ie1aacda97540d5c97e6cbd8edb2afc53e7041e1e Reviewed-by: Andy Shaw <andy.shaw@qt.io>
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcamerasession.cpp6
-rw-r--r--src/plugins/android/src/wrappers/jni/androidcamera.cpp12
-rw-r--r--src/plugins/android/src/wrappers/jni/androidcamera.h1
3 files changed, 19 insertions, 0 deletions
diff --git a/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp b/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
index 8663f8c5f..b0dd7d900 100644
--- a/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
+++ b/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
@@ -52,6 +52,7 @@
#include <qvideoframe.h>
#include <private/qmemoryvideobuffer_p.h>
#include <private/qvideoframe_p.h>
+#include <QtCore/private/qjnihelpers_p.h>
QT_BEGIN_NAMESPACE
@@ -443,6 +444,11 @@ bool QAndroidCameraSession::startPreview()
AndroidMultimediaUtils::enableOrientationListener(true);
+ // Before API level 24 the orientation was always 0, which is what we're expecting, so
+ // we'll enforce that here.
+ if (QtAndroidPrivate::androidSdkVersion() > 23)
+ m_camera->setDisplayOrientation(0);
+
m_camera->startPreview();
m_previewStarted = true;
diff --git a/src/plugins/android/src/wrappers/jni/androidcamera.cpp b/src/plugins/android/src/wrappers/jni/androidcamera.cpp
index 76d3ffb44..0f2a43531 100644
--- a/src/plugins/android/src/wrappers/jni/androidcamera.cpp
+++ b/src/plugins/android/src/wrappers/jni/androidcamera.cpp
@@ -196,6 +196,7 @@ public:
Q_INVOKABLE void updatePreviewSize();
Q_INVOKABLE bool setPreviewTexture(void *surfaceTexture);
Q_INVOKABLE bool setPreviewDisplay(void *surfaceHolder);
+ Q_INVOKABLE void setDisplayOrientation(int degrees);
Q_INVOKABLE bool isZoomSupported();
Q_INVOKABLE int getMaxZoom();
@@ -481,6 +482,12 @@ bool AndroidCamera::setPreviewDisplay(AndroidSurfaceHolder *surfaceHolder)
return ok;
}
+void AndroidCamera::setDisplayOrientation(int degrees)
+{
+ Q_D(AndroidCamera);
+ QMetaObject::invokeMethod(d, "setDisplayOrientation", Qt::QueuedConnection, Q_ARG(int, degrees));
+}
+
bool AndroidCamera::isZoomSupported()
{
Q_D(AndroidCamera);
@@ -1079,6 +1086,11 @@ bool AndroidCameraPrivate::setPreviewDisplay(void *surfaceHolder)
return !exceptionCheckAndClear(env);
}
+void AndroidCameraPrivate::setDisplayOrientation(int degrees)
+{
+ m_camera.callMethod<void>("setDisplayOrientation", "(I)V", degrees);
+}
+
bool AndroidCameraPrivate::isZoomSupported()
{
QMutexLocker parametersLocker(&m_parametersMutex);
diff --git a/src/plugins/android/src/wrappers/jni/androidcamera.h b/src/plugins/android/src/wrappers/jni/androidcamera.h
index 1a59ff3c7..e58a81f8e 100644
--- a/src/plugins/android/src/wrappers/jni/androidcamera.h
+++ b/src/plugins/android/src/wrappers/jni/androidcamera.h
@@ -136,6 +136,7 @@ public:
void setPreviewSize(const QSize &size);
bool setPreviewTexture(AndroidSurfaceTexture *surfaceTexture);
bool setPreviewDisplay(AndroidSurfaceHolder *surfaceHolder);
+ void setDisplayOrientation(int degrees);
bool isZoomSupported();
int getMaxZoom();