summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@digia.com>2014-02-03 21:38:56 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-28 14:10:14 +0100
commitf783c48a170c8ec86e4904b786a46dae5f07dfa7 (patch)
tree36933b75321164c3b0cb8bb8361299cdb4668a36
parentb28ee24628f77fced393cacc45500be6761e4497 (diff)
downloadqtmultimedia-f783c48a170c8ec86e4904b786a46dae5f07dfa7.tar.gz
VideoOutput: fix autoOrientation with a camera source.
Don't assume the camera frames are always in the same orientation as the display in its primary orientation. We now take into account the camera sensor position and orientation to calculate the viewport orientation. Change-Id: Ib333c87f1804d1010ada42cb757e4fab78d75a04 Reviewed-by: Christian Stromme <christian.stromme@digia.com>
-rw-r--r--src/multimedia/qtmultimediaquicktools_headers/qdeclarativevideooutput_p.h2
-rw-r--r--src/multimedia/video/qvideooutputorientationhandler.cpp2
-rw-r--r--src/qtmultimediaquicktools/qdeclarativevideooutput.cpp26
3 files changed, 28 insertions, 2 deletions
diff --git a/src/multimedia/qtmultimediaquicktools_headers/qdeclarativevideooutput_p.h b/src/multimedia/qtmultimediaquicktools_headers/qdeclarativevideooutput_p.h
index 2ca7c2933..cc939b230 100644
--- a/src/multimedia/qtmultimediaquicktools_headers/qdeclarativevideooutput_p.h
+++ b/src/multimedia/qtmultimediaquicktools_headers/qdeclarativevideooutput_p.h
@@ -47,6 +47,7 @@
#include <QtCore/qsharedpointer.h>
#include <QtQuick/qquickitem.h>
#include <QtCore/qpointer.h>
+#include <QtMultimedia/qcamerainfo.h>
#include <private/qtmultimediaquickdefs_p.h>
@@ -138,6 +139,7 @@ private:
QPointer<QObject> m_source;
QPointer<QMediaObject> m_mediaObject;
QPointer<QMediaService> m_service;
+ QCameraInfo m_cameraInfo;
FillMode m_fillMode;
QSize m_nativeSize;
diff --git a/src/multimedia/video/qvideooutputorientationhandler.cpp b/src/multimedia/video/qvideooutputorientationhandler.cpp
index 4c966c02d..06fcb0c6f 100644
--- a/src/multimedia/video/qvideooutputorientationhandler.cpp
+++ b/src/multimedia/video/qvideooutputorientationhandler.cpp
@@ -73,7 +73,7 @@ void QVideoOutputOrientationHandler::screenOrientationChanged(Qt::ScreenOrientat
const QScreen *screen = QGuiApplication::primaryScreen();
const QPlatformScreen *platformScreen = screen->handle();
- const int angle = (360 - screen->angleBetween(platformScreen->nativeOrientation(), orientation));
+ const int angle = (360 - screen->angleBetween(platformScreen->nativeOrientation(), orientation)) % 360;
if (angle == m_currentOrientation)
return;
diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput.cpp b/src/qtmultimediaquicktools/qdeclarativevideooutput.cpp
index a04b38ceb..5d2c57dbf 100644
--- a/src/qtmultimediaquicktools/qdeclarativevideooutput.cpp
+++ b/src/qtmultimediaquicktools/qdeclarativevideooutput.cpp
@@ -273,12 +273,22 @@ void QDeclarativeVideoOutput::_q_updateMediaObject()
m_mediaObject.clear();
m_service.clear();
+ m_cameraInfo = QCameraInfo();
if (mediaObject) {
if (QMediaService *service = mediaObject->service()) {
if (createBackend(service)) {
m_service = service;
m_mediaObject = mediaObject;
+ const QCamera *camera = qobject_cast<const QCamera *>(mediaObject);
+ if (camera) {
+ m_cameraInfo = QCameraInfo(*camera);
+
+ // The camera position and orientation need to be taken into account for
+ // the viewport auto orientation
+ if (m_autoOrientation)
+ _q_screenOrientationChanged(m_screenOrientationHandler->currentOrientation());
+ }
}
}
}
@@ -375,7 +385,21 @@ void QDeclarativeVideoOutput::_q_updateGeometry()
void QDeclarativeVideoOutput::_q_screenOrientationChanged(int orientation)
{
- setOrientation(orientation);
+ // If the source is a camera, take into account its sensor position and orientation
+ if (!m_cameraInfo.isNull()) {
+ switch (m_cameraInfo.position()) {
+ case QCamera::FrontFace:
+ // Front facing cameras are flipped horizontally, compensate the mirror
+ orientation += (360 - m_cameraInfo.orientation());
+ break;
+ case QCamera::BackFace:
+ default:
+ orientation += m_cameraInfo.orientation();
+ break;
+ }
+ }
+
+ setOrientation(orientation % 360);
}
/*!