summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Dyomin <artem.dyomin@qt.io>2024-05-08 14:41:33 +0200
committerArtem Dyomin <artem.dyomin@qt.io>2024-05-10 20:29:28 +0000
commit49d1fb36a3d81aa871611e53931bfa23bc3bcaf0 (patch)
treed20a0ccbb774fb2600b0542326962aa7af667358
parent075da34d998790c5a0ba5a312837382db9bdc963 (diff)
Add methods QVideoFrame::streamFrameRate and setStreamFrameRateHEADdev
Users need to be able to modify underlying QVideoFrameFormat::streamFrameRate, it's needed for working custom video input, when the user gets QVideoFrame from QVideoSink and wants to set a new stream frame rate for the format and send it to custom video input. [ChangeLog][QVideoFrame] Added the property 'streamFrameRate' to QVideoFrame. Change-Id: I061eac1f1ecdb0828ef079cee14e0871181fdd08 Reviewed-by: Tim Blechmann <tim@klingt.org> Reviewed-by: Jøger Hansegård <joger.hansegard@qt.io>
-rw-r--r--src/multimedia/video/qvideoframe.cpp17
-rw-r--r--src/multimedia/video/qvideoframe.h3
-rw-r--r--tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp15
3 files changed, 35 insertions, 0 deletions
diff --git a/src/multimedia/video/qvideoframe.cpp b/src/multimedia/video/qvideoframe.cpp
index d30017dab..6198ebcf4 100644
--- a/src/multimedia/video/qvideoframe.cpp
+++ b/src/multimedia/video/qvideoframe.cpp
@@ -713,6 +713,23 @@ bool QVideoFrame::mirrored() const
}
/*!
+ Sets the frame \a rate of a video stream in frames per second.
+*/
+void QVideoFrame::setStreamFrameRate(qreal rate)
+{
+ if (d)
+ d->format.setStreamFrameRate(rate);
+}
+
+/*!
+ Returns the frame rate of a video stream in frames per second.
+*/
+qreal QVideoFrame::streamFrameRate() const
+{
+ return d ? d->format.streamFrameRate() : 0.;
+}
+
+/*!
Based on the pixel format converts current video frame to image.
\since 5.15
*/
diff --git a/src/multimedia/video/qvideoframe.h b/src/multimedia/video/qvideoframe.h
index a306162e8..5a2cf177d 100644
--- a/src/multimedia/video/qvideoframe.h
+++ b/src/multimedia/video/qvideoframe.h
@@ -114,6 +114,9 @@ public:
void setMirrored(bool);
bool mirrored() const;
+ void setStreamFrameRate(qreal rate);
+ qreal streamFrameRate() const;
+
QImage toImage() const;
struct PaintOptions {
diff --git a/tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp b/tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp
index 76d62dba3..bc73eeb44 100644
--- a/tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp
+++ b/tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp
@@ -170,6 +170,7 @@ private slots:
void mirrored_takesValue_fromVideoFrameFormat();
void rotation_takesValue_fromVideoFrameFormat();
+ void streamFrameRate_takesValue_fromVideoFrameFormat();
void constructor_createsInvalidFrame_whenCalledWithNullImage();
void constructor_createsInvalidFrame_whenCalledWithEmptyImage();
@@ -1139,6 +1140,20 @@ void tst_QVideoFrame::rotation_takesValue_fromVideoFrameFormat()
QCOMPARE(frame.surfaceFormat().rotation(), QtVideo::Rotation::Clockwise180);
}
+void tst_QVideoFrame::streamFrameRate_takesValue_fromVideoFrameFormat()
+{
+ QVideoFrameFormat format(QSize(10, 20), QVideoFrameFormat::Format_ARGB8888);
+ format.setStreamFrameRate(20.);
+
+ QVideoFrame frame(format);
+ QCOMPARE(frame.streamFrameRate(), 20.);
+
+ frame.setStreamFrameRate(25.);
+
+ QCOMPARE(frame.streamFrameRate(), 25.);
+ QCOMPARE(frame.surfaceFormat().streamFrameRate(), 25.);
+}
+
void tst_QVideoFrame::constructor_createsInvalidFrame_whenCalledWithNullImage()
{
const QVideoFrame frame{ QImage{} };