summaryrefslogtreecommitdiffstats
path: root/src/multimedia
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-09-02 16:00:21 +0200
committerLars Knoll <lars.knoll@qt.io>2021-09-07 09:15:15 +0200
commitd8ede46f1fcaf2322bb64daf48ad4565f7e0adfd (patch)
tree9a7ab465e01bbf70a320e6f75826d3f658a24db2 /src/multimedia
parent2c0b2b11a5c3d2972bacf5d4d1de34ab16126f79 (diff)
Add subtitle support to VideoOutput
Implement generic subtitle support for the QML VideoOuput element by rendering subtitles through a QQuickTextNode. Pick-to: 6.2 Change-Id: Ib6cd2763769891758fb1bb96964f30a38bdadefe Reviewed-by: Samuel Mira <samuel.mira@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'src/multimedia')
-rw-r--r--src/multimedia/video/qvideotexturehelper.cpp7
-rw-r--r--src/multimedia/video/qvideotexturehelper_p.h2
2 files changed, 5 insertions, 4 deletions
diff --git a/src/multimedia/video/qvideotexturehelper.cpp b/src/multimedia/video/qvideotexturehelper.cpp
index 27129c770..0f46c4805 100644
--- a/src/multimedia/video/qvideotexturehelper.cpp
+++ b/src/multimedia/video/qvideotexturehelper.cpp
@@ -505,12 +505,12 @@ int updateRhiTextures(QVideoFrame frame, QRhi *rhi, QRhiResourceUpdateBatch *res
return description->nplanes;
}
-void SubtitleLayout::updateFromVideoFrame(const QVideoFrame &frame)
+bool SubtitleLayout::updateFromVideoFrame(const QVideoFrame &frame)
{
auto text = frame.subtitleText();
text.replace(QLatin1Char('\n'), QChar::LineSeparator);
if (layout.text() == text && videoSize == frame.size())
- return;
+ return false;
videoSize = frame.size();
QFont font;
@@ -521,7 +521,7 @@ void SubtitleLayout::updateFromVideoFrame(const QVideoFrame &frame)
layout.setText(text);
if (text.isEmpty()) {
bounds = {};
- return;
+ return true;
}
layout.setFont(font);
QTextOption option;
@@ -557,6 +557,7 @@ void SubtitleLayout::updateFromVideoFrame(const QVideoFrame &frame)
textWidth += fontSize/4.;
bounds = QRectF((videoSize.width() - textWidth)/2., y, textWidth, height);
+ return true;
}
void SubtitleLayout::draw(QPainter *painter, const QRectF &videoRect) const
diff --git a/src/multimedia/video/qvideotexturehelper_p.h b/src/multimedia/video/qvideotexturehelper_p.h
index 261d55cf0..168ce8a86 100644
--- a/src/multimedia/video/qvideotexturehelper_p.h
+++ b/src/multimedia/video/qvideotexturehelper_p.h
@@ -107,7 +107,7 @@ struct Q_MULTIMEDIA_EXPORT SubtitleLayout
QRectF bounds;
QTextLayout layout;
- void updateFromVideoFrame(const QVideoFrame &frame);
+ bool updateFromVideoFrame(const QVideoFrame &frame);
void draw(QPainter *painter, const QRectF &videoRect) const;
QImage toImage() const;
};