From f783c48a170c8ec86e4904b786a46dae5f07dfa7 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Mon, 3 Feb 2014 21:38:56 +0100 Subject: 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 --- .../qdeclarativevideooutput.cpp | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/qtmultimediaquicktools') 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(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); } /*! -- cgit v1.2.3