summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Blechmann <tim@klingt.org>2024-04-02 11:41:58 +0800
committerTim Blechmann <tim@klingt.org>2024-04-05 07:01:38 +0800
commit8a2c66e78c8cfc0bb1b4a9deaa8158f17c414082 (patch)
treec74956ec53fe4c05f4e255fa61918165d64adfcc
parent40410efc3df4d5ab8b47c8121313a74231dd7061 (diff)
GStreamer: MediaEncoder - fix resolution
The resolution was ignored when recording media. Setting the video resolution on the encoding profile to make the unit tests pass. Fixes: QTBUG-123899 Pick-to: 6.5 6.6 6.7 Change-Id: I162a9d547ba7445c9fa1435726ca6bb0ef7cbda4 Reviewed-by: Jøger Hansegård <joger.hansegard@qt.io> Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgst.cpp14
-rw-r--r--src/plugins/multimedia/gstreamer/common/qgst_p.h1
-rw-r--r--src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediaencoder.cpp6
3 files changed, 20 insertions, 1 deletions
diff --git a/src/plugins/multimedia/gstreamer/common/qgst.cpp b/src/plugins/multimedia/gstreamer/common/qgst.cpp
index 71ce37bcc..1451e4855 100644
--- a/src/plugins/multimedia/gstreamer/common/qgst.cpp
+++ b/src/plugins/multimedia/gstreamer/common/qgst.cpp
@@ -447,6 +447,20 @@ void QGstCaps::addPixelFormats(const QList<QVideoFrameFormat::PixelFormat> &form
gst_caps_set_features(get(), size() - 1, gst_caps_features_from_string(modifier));
}
+void QGstCaps::setResolution(QSize resolution)
+{
+ Q_ASSERT(resolution.isValid());
+ GValue width{};
+ g_value_init(&width, G_TYPE_INT);
+ g_value_set_int(&width, resolution.width());
+ GValue height{};
+ g_value_init(&height, G_TYPE_INT);
+ g_value_set_int(&height, resolution.height());
+
+ gst_caps_set_value(caps(), "width", &width);
+ gst_caps_set_value(caps(), "height", &height);
+}
+
QGstCaps QGstCaps::fromCameraFormat(const QCameraFormat &format)
{
QSize size = format.resolution();
diff --git a/src/plugins/multimedia/gstreamer/common/qgst_p.h b/src/plugins/multimedia/gstreamer/common/qgst_p.h
index 64b836276..0b44d1e2d 100644
--- a/src/plugins/multimedia/gstreamer/common/qgst_p.h
+++ b/src/plugins/multimedia/gstreamer/common/qgst_p.h
@@ -316,6 +316,7 @@ public:
std::optional<std::pair<QVideoFrameFormat, GstVideoInfo>> formatAndVideoInfo() const;
void addPixelFormats(const QList<QVideoFrameFormat::PixelFormat> &formats, const char *modifier = nullptr);
+ void setResolution(QSize);
static QGstCaps create();
diff --git a/src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediaencoder.cpp b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediaencoder.cpp
index d2761f41d..29c1bdbe9 100644
--- a/src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediaencoder.cpp
+++ b/src/plugins/multimedia/gstreamer/mediacapture/qgstreamermediaencoder.cpp
@@ -138,10 +138,14 @@ static GstEncodingProfile *createVideoProfile(const QMediaEncoderSettings &setti
{
auto *formatInfo = QGstreamerIntegration::instance()->gstFormatsInfo();
- auto caps = formatInfo->videoCaps(settings.mediaFormat());
+ QGstCaps caps = formatInfo->videoCaps(settings.mediaFormat());
if (caps.isNull())
return nullptr;
+ QSize videoResolution = settings.videoResolution();
+ if (videoResolution.isValid())
+ caps.setResolution(videoResolution);
+
GstEncodingVideoProfile *profile =
gst_encoding_video_profile_new(const_cast<GstCaps *>(caps.caps()), nullptr,
nullptr, // restriction