summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Srebrny <piotr.srebrny@qt.io>2022-02-09 15:28:56 +0100
committerPiotr Srebrny <piotr.srebrny@qt.io>2022-02-15 21:26:55 +0100
commitcf7edd31860068760ff8525c0e5590c2f4480dcf (patch)
tree0c8287666030f33c244ad4ff25b4fec258728aa0
parent55eb4ad8200ab98d8073436a7152df4fceb69de9 (diff)
Use clockwise rotation for the QVideoFrame::rotationAngle()
The counterclockwise rotation of rotationAngle() does not play well with the multmedia backends. The WMF MFVideoRotationFormat that describes the counterclockwise rotation of the picture, must be applied as clockwise rotation to render frame the correct way. This patch changes the interpretation of the rotationAngle() to be clockwise rotation. This fixes the rendering for WMF and gstreamer. AVFoundation is updated to account for the direction change. Fixes: QTBUG-100337 Change-Id: I284367629dad27fea95da52af4ca2d71d9412b09 Reviewed-by: Doris Verria <doris.verria@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit 099e9a697b92e02666f308c1789c685990e45206) Reviewed-by: André de la Rocha <andre.rocha@qt.io>
-rw-r--r--src/multimedia/platform/darwin/common/avfmetadata.mm18
-rw-r--r--src/multimedia/platform/darwin/mediaplayer/avfmediaplayer.mm4
-rw-r--r--src/multimedia/video/qvideoframe.cpp19
-rw-r--r--src/multimedia/video/qvideowindow.cpp19
-rw-r--r--src/multimediaquick/qsgvideonode_p.cpp20
5 files changed, 38 insertions, 42 deletions
diff --git a/src/multimedia/platform/darwin/common/avfmetadata.mm b/src/multimedia/platform/darwin/common/avfmetadata.mm
index 834b5ec1f..6c0e50147 100644
--- a/src/multimedia/platform/darwin/common/avfmetadata.mm
+++ b/src/multimedia/platform/darwin/common/avfmetadata.mm
@@ -297,27 +297,11 @@ QMediaMetaData AVFMetaData::fromAssetTrack(AVAssetTrack *asset)
if ([asset.mediaType isEqualToString:AVMediaTypeVideo]) {
// add orientation
if (metadata.value(QMediaMetaData::Orientation).isNull()) {
- int rotation = 0;
QVideoFrame::RotationAngle angle = QVideoFrame::Rotation0;
bool mirrored;
AVFMediaPlayer::videoOrientationForAssetTrack(asset, angle, mirrored);
Q_UNUSED(mirrored);
- switch (angle) {
- // metadata orientation angle is in clockwise direction
- case QVideoFrame::Rotation90:
- rotation = 270;
- break;
- case QVideoFrame::Rotation180:
- rotation = 180;
- break;
- case QVideoFrame::Rotation270:
- rotation = 90;
- break;
- default:
- rotation = 0;
- break;
- }
- metadata.insert(QMediaMetaData::Orientation, rotation);
+ metadata.insert(QMediaMetaData::Orientation, int(angle));
}
}
return metadata;
diff --git a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayer.mm b/src/multimedia/platform/darwin/mediaplayer/avfmediaplayer.mm
index 311a87a31..c4c661464 100644
--- a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayer.mm
+++ b/src/multimedia/platform/darwin/mediaplayer/avfmediaplayer.mm
@@ -1246,9 +1246,9 @@ void AVFMediaPlayer::videoOrientationForAssetTrack(AVAssetTrack *videoTrack,
}
if (qFuzzyCompare(degrees, qreal(90)) || qFuzzyCompare(degrees, qreal(-270))) {
- angle = QVideoFrame::Rotation270;
- } else if (qFuzzyCompare(degrees, qreal(-90)) || qFuzzyCompare(degrees, qreal(270))) {
angle = QVideoFrame::Rotation90;
+ } else if (qFuzzyCompare(degrees, qreal(-90)) || qFuzzyCompare(degrees, qreal(270))) {
+ angle = QVideoFrame::Rotation270;
} else if (qFuzzyCompare(degrees, qreal(180)) || qFuzzyCompare(degrees, qreal(-180))) {
angle = QVideoFrame::Rotation180;
}
diff --git a/src/multimedia/video/qvideoframe.cpp b/src/multimedia/video/qvideoframe.cpp
index ea48afc7e..acf549c55 100644
--- a/src/multimedia/video/qvideoframe.cpp
+++ b/src/multimedia/video/qvideoframe.cpp
@@ -702,7 +702,19 @@ void QVideoFrame::setEndTime(qint64 time)
}
/*!
- Sets the counterclockwise rotation \a angle for the frame.
+ \enum QVideoFrame::RotationAngle
+
+ The angle of the clockwise rotation that should be applied to a video
+ frame before displaying.
+
+ \value Rotation0 No rotation required, the frame has correct orientation
+ \value Rotation90 The frame should be rotated by 90 degrees
+ \value Rotation180 The frame should be rotated by 180 degrees
+ \value Rotation270 The frame should be rotated by 270 degrees
+*/
+
+/*!
+ Sets the \a angle the frame should be rotated clockwise before displaying.
*/
void QVideoFrame::setRotationAngle(QVideoFrame::RotationAngle angle)
{
@@ -711,8 +723,7 @@ void QVideoFrame::setRotationAngle(QVideoFrame::RotationAngle angle)
}
/*!
- Returns the angle the frame should be rotated counterclockwise before
- displaying.
+ Returns the angle the frame should be rotated clockwise before displaying.
*/
QVideoFrame::RotationAngle QVideoFrame::rotationAngle() const
{
@@ -771,7 +782,7 @@ QImage QVideoFrame::toImage() const
if (mirrored())
t.scale(-1.f, 1.f);
if (rotationAngle() != Rotation0)
- t.rotate(-1.f * float(rotationAngle()));
+ t.rotate(float(rotationAngle()));
if (surfaceFormat().scanLineDirection() != QVideoFrameFormat::TopToBottom)
t.scale(1.f, -1.f);
diff --git a/src/multimedia/video/qvideowindow.cpp b/src/multimedia/video/qvideowindow.cpp
index f2a6d7037..9055b4167 100644
--- a/src/multimedia/video/qvideowindow.cpp
+++ b/src/multimedia/video/qvideowindow.cpp
@@ -103,27 +103,28 @@ QVideoWindowPrivate::~QVideoWindowPrivate()
}
static const float g_quad[] = {
- // 4 counterclockwise rotation of texture vertexes (the second pair)
+ // 4 clockwise rotation of texture vertexes (the second pair)
// Rotation 0
-1.f, -1.f, 0.f, 0.f,
-1.f, 1.f, 0.f, 1.f,
1.f, -1.f, 1.f, 0.f,
1.f, 1.f, 1.f, 1.f,
// Rotation 90
- -1.f, -1.f, 1.f, 0.f,
- -1.f, 1.f, 0.f, 0.f,
- 1.f, -1.f, 1.f, 1.f,
- 1.f, 1.f, 0.f, 1.f,
+ -1.f, -1.f, 0.f, 1.f,
+ -1.f, 1.f, 1.f, 1.f,
+ 1.f, -1.f, 0.f, 0.f,
+ 1.f, 1.f, 1.f, 0.f,
+
// Rotation 180
-1.f, -1.f, 1.f, 1.f,
-1.f, 1.f, 1.f, 0.f,
1.f, -1.f, 0.f, 1.f,
1.f, 1.f, 0.f, 0.f,
// Rotation 270
- -1.f, -1.f, 0.f, 1.f,
- -1.f, 1.f, 1.f, 1.f,
- 1.f, -1.f, 0.f, 0.f,
- 1.f, 1.f, 1.f, 0.f
+ -1.f, -1.f, 1.f, 0.f,
+ -1.f, 1.f, 0.f, 0.f,
+ 1.f, -1.f, 1.f, 1.f,
+ 1.f, 1.f, 0.f, 1.f
};
static QShader getShader(const QString &name)
diff --git a/src/multimediaquick/qsgvideonode_p.cpp b/src/multimediaquick/qsgvideonode_p.cpp
index 2327bcc54..000bda7b9 100644
--- a/src/multimediaquick/qsgvideonode_p.cpp
+++ b/src/multimediaquick/qsgvideonode_p.cpp
@@ -337,11 +337,11 @@ void QSGVideoNode::setTexturedRectGeometry(const QRectF &rect, const QRectF &tex
break;
case 90:
- // tr, tl, br, bl
- qSetTex(v + 0, textureRect.topRight());
- qSetTex(v + 1, textureRect.topLeft());
- qSetTex(v + 2, textureRect.bottomRight());
- qSetTex(v + 3, textureRect.bottomLeft());
+ // bl, br, tl, tr
+ qSetTex(v + 0, textureRect.bottomLeft());
+ qSetTex(v + 1, textureRect.bottomRight());
+ qSetTex(v + 2, textureRect.topLeft());
+ qSetTex(v + 3, textureRect.topRight());
break;
case 180:
@@ -353,11 +353,11 @@ void QSGVideoNode::setTexturedRectGeometry(const QRectF &rect, const QRectF &tex
break;
case 270:
- // bl, br, tl, tr
- qSetTex(v + 0, textureRect.bottomLeft());
- qSetTex(v + 1, textureRect.bottomRight());
- qSetTex(v + 2, textureRect.topLeft());
- qSetTex(v + 3, textureRect.topRight());
+ // tr, tl, br, bl
+ qSetTex(v + 0, textureRect.topRight());
+ qSetTex(v + 1, textureRect.topLeft());
+ qSetTex(v + 2, textureRect.bottomRight());
+ qSetTex(v + 3, textureRect.bottomLeft());
break;
}