summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-11-01 15:08:26 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-11-03 09:43:24 +0000
commitf2353ebdd0c3144e44ca86a45bddf48c36541329 (patch)
treed2a5d74e2511935b08c010565102152b9944b4b7
parent982e153153a8e2f58980d1707f686686060e551e (diff)
downloadqtmultimedia-f2353ebdd0c3144e44ca86a45bddf48c36541329.tar.gz
Update the matching formats in the audiorecorder and camera examples
The combo boxes should show a list of matching formats/codec that we can handle give the constraints from the other combo boxes. Fixes: QTBUG-97839 Change-Id: I1a3f66c27f3ede06f188b9320600dde7c561a409 Reviewed-by: André de la Rocha <andre.rocha@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit eaad981c0bd2de5f74114295d47a8893382a6a7f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/multimedia/audiorecorder/audiorecorder.cpp53
-rw-r--r--examples/multimedia/audiorecorder/audiorecorder.h4
-rw-r--r--examples/multimediawidgets/camera/videosettings.cpp78
-rw-r--r--examples/multimediawidgets/camera/videosettings.h2
4 files changed, 99 insertions, 38 deletions
diff --git a/examples/multimedia/audiorecorder/audiorecorder.cpp b/examples/multimedia/audiorecorder/audiorecorder.cpp
index 026139010..c051f082c 100644
--- a/examples/multimedia/audiorecorder/audiorecorder.cpp
+++ b/examples/multimedia/audiorecorder/audiorecorder.cpp
@@ -88,18 +88,10 @@ AudioRecorder::AudioRecorder()
ui->audioDeviceBox->addItem(name, QVariant::fromValue(device));
}
- //audio codecs
- ui->audioCodecBox->addItem(tr("Default"), QVariant(QString()));
- for (auto &codec : QMediaFormat().supportedAudioCodecs(QMediaFormat::Encode))
- ui->audioCodecBox->addItem(QMediaFormat::audioCodecDescription(codec), QVariant::fromValue(codec));
-
- //containers
- ui->containerBox->addItem(tr("Default"), QVariant(QString()));
- for (auto &container : QMediaFormat().supportedFileFormats(QMediaFormat::Encode)) {
- if (container < QMediaFormat::Mpeg4Audio) // ### Somewhat hacky, skip video formats
- continue;
- ui->containerBox->addItem(QMediaFormat::fileFormatDescription(container), QVariant::fromValue(container));
- }
+ //audio codecs and container formats
+ updateFormats();
+ connect(ui->audioCodecBox, &QComboBox::currentIndexChanged, this, &AudioRecorder::updateFormats);
+ connect(ui->containerBox, &QComboBox::currentIndexChanged, this, &AudioRecorder::updateFormats);
//sample rate
ui->sampleRateBox->setRange(m_captureSession.audioInput()->device().minimumSampleRate(),
@@ -229,6 +221,43 @@ void AudioRecorder::displayErrorMessage()
ui->statusbar->showMessage(m_audioRecorder->errorString());
}
+void AudioRecorder::updateFormats()
+{
+ if (m_updatingFormats)
+ return;
+ m_updatingFormats = true;
+
+ QMediaFormat format;
+ if (ui->containerBox->count())
+ format.setFileFormat(boxValue(ui->containerBox).value<QMediaFormat::FileFormat>());
+ if (ui->audioCodecBox->count())
+ format.setAudioCodec(boxValue(ui->audioCodecBox).value<QMediaFormat::AudioCodec>());
+
+ int currentIndex = 0;
+ ui->audioCodecBox->clear();
+ ui->audioCodecBox->addItem(tr("Default audio codec"), QVariant::fromValue(QMediaFormat::AudioCodec::Unspecified));
+ for (auto codec : format.supportedAudioCodecs(QMediaFormat::Encode)) {
+ if (codec == format.audioCodec())
+ currentIndex = ui->audioCodecBox->count();
+ ui->audioCodecBox->addItem(QMediaFormat::audioCodecDescription(codec), QVariant::fromValue(codec));
+ }
+ ui->audioCodecBox->setCurrentIndex(currentIndex);
+
+ currentIndex = 0;
+ ui->containerBox->clear();
+ ui->containerBox->addItem(tr("Default file format"), QVariant::fromValue(QMediaFormat::UnspecifiedFormat));
+ for (auto container : format.supportedFileFormats(QMediaFormat::Encode)) {
+ if (container < QMediaFormat::Mpeg4Audio) // Skip video formats
+ continue;
+ if (container == format.fileFormat())
+ currentIndex = ui->containerBox->count();
+ ui->containerBox->addItem(QMediaFormat::fileFormatDescription(container), QVariant::fromValue(container));
+ }
+ ui->containerBox->setCurrentIndex(currentIndex);
+
+ m_updatingFormats = false;
+}
+
void AudioRecorder::clearAudioLevels()
{
for (auto m_audioLevel : qAsConst(m_audioLevels))
diff --git a/examples/multimedia/audiorecorder/audiorecorder.h b/examples/multimedia/audiorecorder/audiorecorder.h
index 97bd49688..071b8510e 100644
--- a/examples/multimedia/audiorecorder/audiorecorder.h
+++ b/examples/multimedia/audiorecorder/audiorecorder.h
@@ -82,6 +82,8 @@ private slots:
void updateProgress(qint64 pos);
void displayErrorMessage();
+ void updateFormats();
+
private:
void clearAudioLevels();
@@ -91,7 +93,7 @@ private:
QMediaRecorder *m_audioRecorder = nullptr;
QList<AudioLevel*> m_audioLevels;
bool m_outputLocationSet = false;
-
+ bool m_updatingFormats = false;
};
#endif // AUDIORECORDER_H
diff --git a/examples/multimediawidgets/camera/videosettings.cpp b/examples/multimediawidgets/camera/videosettings.cpp
index e212e9dd8..f515d1bca 100644
--- a/examples/multimediawidgets/camera/videosettings.cpp
+++ b/examples/multimediawidgets/camera/videosettings.cpp
@@ -94,27 +94,11 @@ VideoSettings::VideoSettings(QMediaRecorder *mediaRecorder, QWidget *parent)
{
ui->setupUi(this);
- //audio codecs
- ui->audioCodecBox->addItem(tr("Default audio codec"), QVariant::fromValue(QMediaFormat::AudioCodec::Unspecified));
- const auto supportedAudioCodecs = QMediaFormat().supportedAudioCodecs(QMediaFormat::Encode);
- for (const auto &codec : supportedAudioCodecs) {
- QString description = QMediaFormat::audioCodecDescription(codec);
- ui->audioCodecBox->addItem(QMediaFormat::audioCodecName(codec) + ": " + description, QVariant::fromValue(codec));
- }
-
//sample rate:
auto audioDevice = mediaRecorder->captureSession()->audioInput()->device();
ui->audioSampleRateBox->setRange(audioDevice.minimumSampleRate(),
audioDevice.maximumSampleRate());
- //video codecs
- ui->videoCodecBox->addItem(tr("Default video codec"), QVariant::fromValue(QMediaFormat::VideoCodec::Unspecified));
- const auto supportedVideoCodecs = QMediaFormat().supportedVideoCodecs(QMediaFormat::Encode);
- for (const auto &codec : supportedVideoCodecs) {
- QString description = QMediaFormat::videoCodecDescription(codec);
- ui->videoCodecBox->addItem(QMediaFormat::videoCodecName(codec) + ": " + description, QVariant::fromValue(codec));
- }
-
// camera format
ui->videoFormatBox->addItem(tr("Default camera format"));
@@ -125,7 +109,7 @@ VideoSettings::VideoSettings(QMediaRecorder *mediaRecorder, QWidget *parent)
ui->videoFormatBox->addItem(toFormattedString(format), QVariant::fromValue(format));
}
- connect(ui->videoFormatBox, &QComboBox::currentIndexChanged, [this](int index) {
+ connect(ui->videoFormatBox, &QComboBox::currentIndexChanged, [this](int /*index*/) {
const auto &cameraFormat = boxValue(ui->videoFormatBox).value<QCameraFormat>();
ui->fpsSlider->setRange(cameraFormat.minFrameRate(), cameraFormat.maxFrameRate());
ui->fpsSpinBox->setRange(cameraFormat.minFrameRate(), cameraFormat.maxFrameRate());
@@ -139,14 +123,10 @@ VideoSettings::VideoSettings(QMediaRecorder *mediaRecorder, QWidget *parent)
connect(ui->fpsSlider, &QSlider::valueChanged, ui->fpsSpinBox, &QSpinBox::setValue);
connect(ui->fpsSpinBox, &QSpinBox::valueChanged, ui->fpsSlider, &QSlider::setValue);
- // containers
- ui->containerFormatBox->addItem(tr("Default video container"),
- QVariant::fromValue(QMediaFormat::UnspecifiedFormat));
- const auto formats = QMediaFormat().supportedFileFormats(QMediaFormat::Encode);
- for (auto format : formats) {
- ui->containerFormatBox->addItem(QMediaFormat::fileFormatName(format) + ": " + QMediaFormat::fileFormatDescription(format),
- QVariant::fromValue(format));
- }
+ updateFormatsAndCodecs();
+ connect(ui->audioCodecBox, &QComboBox::currentIndexChanged, this, &VideoSettings::updateFormatsAndCodecs);
+ connect(ui->videoCodecBox, &QComboBox::currentIndexChanged, this, &VideoSettings::updateFormatsAndCodecs);
+ connect(ui->containerFormatBox, &QComboBox::currentIndexChanged, this, &VideoSettings::updateFormatsAndCodecs);
ui->qualitySlider->setRange(0, int(QMediaRecorder::VeryHighQuality));
@@ -200,6 +180,54 @@ void VideoSettings::applySettings()
mediaRecorder->captureSession()->camera()->setCameraFormat(cameraFormat);
}
+void VideoSettings::updateFormatsAndCodecs()
+{
+ if (m_updatingFormats)
+ return;
+ m_updatingFormats = true;
+
+ QMediaFormat format;
+ if (ui->containerFormatBox->count())
+ format.setFileFormat(boxValue(ui->containerFormatBox).value<QMediaFormat::FileFormat>());
+ if (ui->audioCodecBox->count())
+ format.setAudioCodec(boxValue(ui->audioCodecBox).value<QMediaFormat::AudioCodec>());
+ if (ui->videoCodecBox->count())
+ format.setVideoCodec(boxValue(ui->videoCodecBox).value<QMediaFormat::VideoCodec>());
+
+ int currentIndex = 0;
+ ui->audioCodecBox->clear();
+ ui->audioCodecBox->addItem(tr("Default audio codec"), QVariant::fromValue(QMediaFormat::AudioCodec::Unspecified));
+ for (auto codec : format.supportedAudioCodecs(QMediaFormat::Encode)) {
+ if (codec == format.audioCodec())
+ currentIndex = ui->audioCodecBox->count();
+ ui->audioCodecBox->addItem(QMediaFormat::audioCodecDescription(codec), QVariant::fromValue(codec));
+ }
+ ui->audioCodecBox->setCurrentIndex(currentIndex);
+
+ currentIndex = 0;
+ ui->videoCodecBox->clear();
+ ui->videoCodecBox->addItem(tr("Default video codec"), QVariant::fromValue(QMediaFormat::VideoCodec::Unspecified));
+ for (auto codec : format.supportedVideoCodecs(QMediaFormat::Encode)) {
+ if (codec == format.videoCodec())
+ currentIndex = ui->videoCodecBox->count();
+ ui->videoCodecBox->addItem(QMediaFormat::videoCodecDescription(codec), QVariant::fromValue(codec));
+ }
+ ui->videoCodecBox->setCurrentIndex(currentIndex);
+
+ currentIndex = 0;
+ ui->containerFormatBox->clear();
+ ui->containerFormatBox->addItem(tr("Default file format"), QVariant::fromValue(QMediaFormat::UnspecifiedFormat));
+ for (auto container : format.supportedFileFormats(QMediaFormat::Encode)) {
+ if (container == format.fileFormat())
+ currentIndex = ui->containerFormatBox->count();
+ ui->containerFormatBox->addItem(QMediaFormat::fileFormatDescription(container), QVariant::fromValue(container));
+ }
+ ui->containerFormatBox->setCurrentIndex(currentIndex);
+
+ m_updatingFormats = false;
+
+}
+
QVariant VideoSettings::boxValue(const QComboBox *box) const
{
int idx = box->currentIndex();
diff --git a/examples/multimediawidgets/camera/videosettings.h b/examples/multimediawidgets/camera/videosettings.h
index 28f8ce8a7..14e00bc25 100644
--- a/examples/multimediawidgets/camera/videosettings.h
+++ b/examples/multimediawidgets/camera/videosettings.h
@@ -68,6 +68,7 @@ public:
~VideoSettings();
void applySettings();
+ void updateFormatsAndCodecs();
protected:
void changeEvent(QEvent *e) override;
@@ -78,6 +79,7 @@ private:
Ui::VideoSettingsUi *ui;
QMediaRecorder *mediaRecorder;
+ bool m_updatingFormats = false;
};
#endif // VIDEOSETTINGS_H