diff options
author | Pekka Gehör <pekka.gehor@qt.io> | 2021-09-17 12:50:25 +0300 |
---|---|---|
committer | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2021-09-23 16:49:22 +0300 |
commit | bf455a536148af767bff45ee3186740cc681d58b (patch) | |
tree | c9eb4680e6e5c9cb12ab60403a8540ea05242ae6 /examples | |
parent | 6281511f21aad48976f672a79b068d92956c450e (diff) |
Android: Fix video sizes and formats returned from Camera
After the fix, we get a list of available resolutions and frame rates of
the camera. This also fixes the code in the widgets camera example that
uses the video resolutions and frame rates.
Task-number: QTBUG-96097
Pick-to: 6.2
Change-Id: Ie5fa1e89f658f0c816015944fa5a4c1f34625c12
Reviewed-by: Samuel Mira <samuel.mira@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/multimediawidgets/camera/videosettings.cpp | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/examples/multimediawidgets/camera/videosettings.cpp b/examples/multimediawidgets/camera/videosettings.cpp index eaf7b49c9..b5b0ba384 100644 --- a/examples/multimediawidgets/camera/videosettings.cpp +++ b/examples/multimediawidgets/camera/videosettings.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -94,20 +94,47 @@ VideoSettings::VideoSettings(QMediaRecorder *mediaRecorder, QWidget *parent) ui->videoCodecBox->addItem(QMediaFormat::videoCodecName(codec) + ": " + description, QVariant::fromValue(codec)); } - ui->videoResolutionBox->addItem(tr("Default")); - auto supportedResolutions = mediaRecorder->captureSession()->camera()->cameraDevice().photoResolutions(); // ### Should use resolutions from video formats - for (const QSize &resolution : supportedResolutions) { - ui->videoResolutionBox->addItem(QString("%1x%2").arg(resolution.width()).arg(resolution.height()), + + const QList<QCameraFormat> videoFormats = + mediaRecorder->captureSession()->camera()->cameraDevice().videoFormats(); + + for (const QCameraFormat &format : videoFormats) { + const QSize resolution = format.resolution(); + ui->videoResolutionBox->addItem(QString("%1x%2") + .arg(resolution.width()) + .arg(resolution.height()), QVariant(resolution)); } ui->videoFramerateBox->addItem(tr("Default")); -// const QList<qreal> supportedFrameRates = mediaRecorder->supportedFrameRates(); -// for (qreal rate : supportedFrameRates) { -// QString rateString = QString("%1").arg(rate, 0, 'f', 2); -// ui->videoFramerateBox->addItem(rateString, QVariant(rate)); -// } + + connect(ui->videoResolutionBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, + [this, mediaRecorder](int index) { + + // Get the current list of formats + const QList<QCameraFormat> videoFormats = + mediaRecorder->captureSession()->camera()->cameraDevice().videoFormats(); + + QCameraFormat videoFormat; + const auto resolution = ui->videoResolutionBox->itemData(index).value<QSize>(); + for (const QCameraFormat &format : videoFormats) { + if (format.resolution() == resolution) { + videoFormat = format; + break; + } + } + + ui->videoFramerateBox->clear(); + + const float minFrameRate = videoFormat.minFrameRate(); + QString rateString = QString("%1").arg(minFrameRate, 0, 'f', 2); + ui->videoFramerateBox->addItem(rateString, QVariant(minFrameRate)); + + const float maxFrameRate = videoFormat.maxFrameRate(); + rateString = QString("%1").arg(maxFrameRate, 0, 'f', 2); + ui->videoFramerateBox->addItem(rateString, QVariant(maxFrameRate)); + }); //containers ui->containerFormatBox->addItem(tr("Default container"), QVariant::fromValue(QMediaFormat::UnspecifiedFormat)); |