diff options
Diffstat (limited to 'src/multimedia/doc/snippets/multimedia-snippets')
12 files changed, 224 insertions, 1100 deletions
diff --git a/src/multimedia/doc/snippets/multimedia-snippets/audio.cpp b/src/multimedia/doc/snippets/multimedia-snippets/audio.cpp index 57d3adfb4..565f7b29b 100644 --- a/src/multimedia/doc/snippets/multimedia-snippets/audio.cpp +++ b/src/multimedia/doc/snippets/multimedia-snippets/audio.cpp @@ -1,53 +1,19 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Mobility Components. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause /* Audio related snippets */ #include <QFile> #include <QTimer> #include <QDebug> +#include <qobject.h> +#include <qfile.h> -#include "qaudiodeviceinfo.h" -#include "qaudioinput.h" +#include "qaudiodevice.h" +#include "qaudiosource.h" #include "qaudiooutput.h" -#include "qaudioprobe.h" #include "qaudiodecoder.h" #include "qmediaplayer.h" +#include "qmediadevices.h" class AudioInputExample : public QObject { Q_OBJECT @@ -62,7 +28,7 @@ public Q_SLOTS: private: //! [Audio input class members] QFile destinationFile; // Class member - QAudioInput* audio; // Class member + QAudioSource* audio; // Class member //! [Audio input class members] }; @@ -77,21 +43,17 @@ void AudioInputExample::setup() // Set up the desired format, for example: format.setSampleRate(8000); format.setChannelCount(1); - format.setSampleSize(8); - format.setCodec("audio/pcm"); - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleType(QAudioFormat::UnSignedInt); + format.setSampleFormat(QAudioFormat::UInt8); - QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice(); + QAudioDevice info = QMediaDevices::defaultAudioInput(); if (!info.isFormatSupported(format)) { qWarning() << "Default format not supported, trying to use the nearest."; - format = info.nearestFormat(format); } - audio = new QAudioInput(format, this); - connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State))); + audio = new QAudioSource(format, this); + connect(audio, &QAudioSource::stateChanged, this, &AudioInputExample::handleStateChanged); - QTimer::singleShot(3000, this, SLOT(stopRecording())); + QTimer::singleShot(3000, this, &AudioInputExample::stopRecording); audio->start(&destinationFile); // Records audio for 3000ms } @@ -137,11 +99,12 @@ public: public Q_SLOTS: void handleStateChanged(QAudio::State newState); + void stopAudioOutput(); private: //! [Audio output class members] QFile sourceFile; // class member. - QAudioOutput* audio; // class member. + QAudioSink* audio; // class member. //! [Audio output class members] }; @@ -156,32 +119,36 @@ void AudioOutputExample::setup() // Set up the format, eg. format.setSampleRate(8000); format.setChannelCount(1); - format.setSampleSize(8); - format.setCodec("audio/pcm"); - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleType(QAudioFormat::UnSignedInt); + format.setSampleFormat(QAudioFormat::UInt8); - QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); + QAudioDevice info(QMediaDevices::defaultAudioOutput()); if (!info.isFormatSupported(format)) { qWarning() << "Raw audio format not supported by backend, cannot play audio."; return; } - audio = new QAudioOutput(format, this); - connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State))); + audio = new QAudioSink(format, this); + connect(audio, QAudioSink::stateChanged, this, &AudioInputExample::handleStateChanged); audio->start(&sourceFile); } //! [Audio output setup] +//! [Audio output stop] +void AudioOutputExample::stopAudioOutput() +{ + audio->stop(); + sourceFile.close(); + delete audio; +} +//! [Audio output stop] + //! [Audio output state changed] void AudioOutputExample::handleStateChanged(QAudio::State newState) { switch (newState) { case QAudio::IdleState: // Finished playing (no more data) - audio->stop(); - sourceFile.close(); - delete audio; + AudioOutputExample::stopAudioOutput(); break; case QAudio::StoppedState: @@ -204,18 +171,13 @@ void AudioDeviceInfo() QAudioFormat format; format.setSampleRate(44100); // ... other format parameters - format.setSampleType(QAudioFormat::SignedInt); - - QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); - - if (!info.isFormatSupported(format)) - format = info.nearestFormat(format); + format.setSampleFormat(QAudioFormat::Int16); //! [Setting audio format] //! [Dumping audio formats] - const auto deviceInfos = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); - for (const QAudioDeviceInfo &deviceInfo : deviceInfos) - qDebug() << "Device name: " << deviceInfo.deviceName(); + const auto devices = QMediaDevices::audioOutputs(); + for (const QAudioDevice &device : devices) + qDebug() << "Device: " << device.description(); //! [Dumping audio formats] } @@ -234,16 +196,14 @@ void AudioDecodingExample::decode() //! [Local audio decoding] QAudioFormat desiredFormat; desiredFormat.setChannelCount(2); - desiredFormat.setCodec("audio/x-raw"); - desiredFormat.setSampleType(QAudioFormat::UnSignedInt); + desiredFormat.setSampleFormat(QAudioFormat::Int16); desiredFormat.setSampleRate(48000); - desiredFormat.setSampleSize(16); QAudioDecoder *decoder = new QAudioDecoder(this); decoder->setAudioFormat(desiredFormat); - decoder->setSourceFilename("level1.mp3"); + decoder->setSource("level1.mp3"); - connect(decoder, SIGNAL(bufferReady()), this, SLOT(readBuffer())); + connect(decoder, &QAudioDecoder::bufferReady, this, &AudioDecodingExample::readBuffer); decoder->start(); // Now wait for bufferReady() signal and call decoder->read() @@ -257,9 +217,9 @@ void applyVolume(int volumeSliderValue) { // volumeSliderValue is in the range [0..100] - qreal linearVolume = QAudio::convertVolume(volumeSliderValue / qreal(100.0), - QAudio::LogarithmicVolumeScale, - QAudio::LinearVolumeScale); + qreal linearVolume = QtAudio::convertVolume(volumeSliderValue / qreal(100.0), + QtAudio::LogarithmicVolumeScale, + QtAudio::LinearVolumeScale); player.setVolume(qRound(linearVolume * 100)); } diff --git a/src/multimedia/doc/snippets/multimedia-snippets/audiorecorder.cpp b/src/multimedia/doc/snippets/multimedia-snippets/audiorecorder.cpp deleted file mode 100644 index bb9193b03..000000000 --- a/src/multimedia/doc/snippets/multimedia-snippets/audiorecorder.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Mobility Components. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtWidgets> - -#include <qaudiorecorder.h> -#include <qmediaservice.h> - -#include <QtMultimedia/qaudioformat.h> - -#include "audiorecorder.h" - -AudioRecorder::AudioRecorder() -{ -//! [create-objs-1] - capture = new QAudioRecorder(); -//! [create-objs-1] - - // set a default file - capture->setOutputLocation(QUrl("test.raw")); - - QWidget *window = new QWidget; - QGridLayout* layout = new QGridLayout; - - QLabel* deviceLabel = new QLabel; - deviceLabel->setText("Devices"); - deviceBox = new QComboBox(this); - deviceBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); - - QLabel* codecLabel = new QLabel; - codecLabel->setText("Codecs"); - codecsBox = new QComboBox(this); - codecsBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); - - QLabel* qualityLabel = new QLabel; - qualityLabel->setText("Quality"); - qualityBox = new QComboBox(this); - qualityBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); - -//! [device-list] - for(int i = 0; i < audiosource->deviceCount(); i++) - deviceBox->addItem(audiosource->name(i)); -//! [device-list] - -//! [codec-list] - QStringList codecs = capture->supportedAudioCodecs(); - for(int i = 0; i < codecs.count(); i++) - codecsBox->addItem(codecs.at(i)); -//! [codec-list] - - qualityBox->addItem("Low"); - qualityBox->addItem("Medium"); - qualityBox->addItem("High"); - - connect(capture, SIGNAL(durationChanged(qint64)), this, SLOT(updateProgress(qint64))); - connect(capture, SIGNAL(stateChanged(QMediaRecorder::State)), this, SLOT(stateChanged(QMediaRecorder::State))); - - layout->addWidget(deviceLabel,0,0,Qt::AlignHCenter); - connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int))); - layout->addWidget(deviceBox,0,1,1,3,Qt::AlignLeft); - - layout->addWidget(codecLabel,1,0,Qt::AlignHCenter); - connect(codecsBox,SIGNAL(activated(int)),SLOT(codecChanged(int))); - layout->addWidget(codecsBox,1,1,Qt::AlignLeft); - - layout->addWidget(qualityLabel,1,2,Qt::AlignHCenter); - connect(qualityBox,SIGNAL(activated(int)),SLOT(qualityChanged(int))); - layout->addWidget(qualityBox,1,3,Qt::AlignLeft); - - fileButton = new QPushButton(this); - fileButton->setText(tr("Output File")); - connect(fileButton,SIGNAL(clicked()),SLOT(selectOutputFile())); - layout->addWidget(fileButton,3,0,Qt::AlignHCenter); - - button = new QPushButton(this); - button->setText(tr("Record")); - connect(button,SIGNAL(clicked()),SLOT(toggleRecord())); - layout->addWidget(button,3,3,Qt::AlignHCenter); - - recTime = new QLabel; - recTime->setText("0 sec"); - layout->addWidget(recTime,4,0,Qt::AlignHCenter); - - window->setLayout(layout); - setCentralWidget(window); - window->show(); - - active = false; -} - -AudioRecorder::~AudioRecorder() -{ - delete capture; - delete audiosource; -} - -void AudioRecorder::updateProgress(qint64 pos) -{ - currentTime = pos; - if(currentTime == 0) currentTime = 1; - QString text = QString("%1 secs").arg(currentTime/1000); - recTime->setText(text); -} - -void AudioRecorder::stateChanged(QMediaRecorder::State state) -{ - qWarning()<<"stateChanged() "<<state; -} - -void AudioRecorder::deviceChanged(int idx) -{ -//! [get-device] - for(int i = 0; i < audiosource->deviceCount(); i++) { - if(deviceBox->itemText(idx).compare(audiosource->name(i)) == 0) - audiosource->setSelectedDevice(i); - } -//! [get-device] -} - -void AudioRecorder::codecChanged(int idx) -{ - Q_UNUSED(idx); - //capture->setAudioCodec(codecsBox->itemText(idx)); -} - -void AudioRecorder::qualityChanged(int idx) -{ - Q_UNUSED(idx); - /* - if(capture->audioCodec().compare("audio/pcm") == 0) { - if(qualityBox->itemText(idx).compare("Low") == 0) { - // 8000Hz mono is 8kbps - capture->setAudioBitrate(8); - } else if(qualityBox->itemText(idx).compare("Medium") == 0) { - // 22050Hz mono is 44.1kbps - capture->setAudioBitrate(44); - } else if(qualityBox->itemText(idx).compare("High") == 0) { - // 44100Hz mono is 88.2kbps - capture->setAudioBitrate(88); - } - } - */ -} - -//! [toggle-record] -void AudioRecorder::toggleRecord() -{ - if(!active) { - recTime->setText("0 sec"); - currentTime = 0; - capture->record(); - - button->setText(tr("Stop")); - active = true; - } else { - capture->stop(); - button->setText(tr("Record")); - active = false; - } -} -//! [toggle-record] - -void AudioRecorder::selectOutputFile() -{ - QStringList fileNames; - - QFileDialog dialog(this); - - dialog.setFileMode(QFileDialog::AnyFile); - if (dialog.exec()) - fileNames = dialog.selectedFiles(); - - if(fileNames.size() > 0) - capture->setOutputLocation(QUrl(fileNames.first())); -} diff --git a/src/multimedia/doc/snippets/multimedia-snippets/camera.cpp b/src/multimedia/doc/snippets/multimedia-snippets/camera.cpp index f851caadd..053af088f 100644 --- a/src/multimedia/doc/snippets/multimedia-snippets/camera.cpp +++ b/src/multimedia/doc/snippets/multimedia-snippets/camera.cpp @@ -1,66 +1,30 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Mobility Components. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause /* Camera snippets */ #include "qcamera.h" -#include "qcamerainfo.h" -#include "qcameraviewfinder.h" -#include "qcameraviewfindersettings.h" +#include "qcameradevice.h" #include "qmediarecorder.h" -#include "qcameraimagecapture.h" -#include "qcameraimageprocessing.h" -#include "qabstractvideosurface.h" +#include "qmediadevices.h" +#include "qmediacapturesession.h" +#include "qimagecapture.h" +#include "qvideosink.h" +#include <QtMultimediaWidgets/qvideowidget.h> #include <QtGui/qscreen.h> #include <QtGui/qguiapplication.h> #include <QtGui/qimage.h> /* Globals so that everything is consistent. */ QCamera *camera = 0; -QCameraViewfinder *viewfinder = 0; QMediaRecorder *recorder = 0; -QCameraImageCapture *imageCapture = 0; +QImageCapture *imageCapture = 0; +QVideoWidget *viewfinder = 0; //! [Camera overview check] bool checkCameraAvailability() { - if (QCameraInfo::availableCameras().count() > 0) + if (QMediaDevices::videoInputs().count() > 0) return true; else return false; @@ -70,47 +34,37 @@ bool checkCameraAvailability() void overview_viewfinder() { //! [Camera overview viewfinder] + QMediaCaptureSession captureSession; camera = new QCamera; - viewfinder = new QCameraViewfinder; - camera->setViewfinder(viewfinder); + captureSession.setCamera(camera); + viewfinder = new QVideoWidget; + captureSession.setVideoOutput(viewfinder); viewfinder->show(); - camera->start(); // to start the viewfinder + camera->start(); // to start the camera //! [Camera overview viewfinder] } void overview_camera_by_position() { //! [Camera overview position] - camera = new QCamera(QCamera::FrontFace); + camera = new QCamera(QCameraDevice::FrontFace); //! [Camera overview position] } // -.- -class MyVideoSurface : public QAbstractVideoSurface -{ - QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const - { - Q_UNUSED(handleType); - return QList<QVideoFrame::PixelFormat>(); - } - bool present(const QVideoFrame &frame) - { - Q_UNUSED(frame); - return true; - } -}; - void overview_surface() { - MyVideoSurface *mySurface; + QVideoSink *mySink; //! [Camera overview surface] + QMediaCaptureSession captureSession; camera = new QCamera; - mySurface = new MyVideoSurface; - camera->setViewfinder(mySurface); + captureSession.setCamera(camera); + mySink = new QVideoSink; + captureSession.setVideoOutput(mySink); camera->start(); - // MyVideoSurface::present(..) will be called with viewfinder frames + // MyVideoSink::setVideoFrame(..) will be called with video frames //! [Camera overview surface] } @@ -121,18 +75,18 @@ void overview_viewfinder_orientation() //! [Camera overview viewfinder orientation] // Assuming a QImage has been created from the QVideoFrame that needs to be presented QImage videoFrame; - QCameraInfo cameraInfo(camera); // needed to get the camera sensor position and orientation + QCameraDevice cameraDevice(camera); // needed to get the camera sensor position and orientation // Get the current display orientation const QScreen *screen = QGuiApplication::primaryScreen(); const int screenAngle = screen->angleBetween(screen->nativeOrientation(), screen->orientation()); int rotation; - if (cameraInfo.position() == QCamera::BackFace) { - rotation = (cameraInfo.orientation() - screenAngle) % 360; + if (cameraDevice.position() == QCameraDevice::BackFace) { + rotation = (cameraDevice.orientation() - screenAngle) % 360; } else { // Front position, compensate the mirror - rotation = (360 - cameraInfo.orientation() + screenAngle) % 360; + rotation = (360 - cameraDevice.orientation() + screenAngle) % 360; } // Rotate the frame so it always shows in the correct orientation @@ -143,31 +97,36 @@ void overview_viewfinder_orientation() void overview_still() { //! [Camera overview capture] - imageCapture = new QCameraImageCapture(camera); + QMediaCaptureSession captureSession; + camera = new QCamera; + captureSession.setCamera(camera); + imageCapture = new QImageCapture; + captureSession.setImageCapture(imageCapture); - camera->setCaptureMode(QCamera::CaptureStillImage); camera->start(); // Viewfinder frames start flowing - //on half pressed shutter button - camera->searchAndLock(); - //on shutter button pressed imageCapture->capture(); - - //on shutter button released - camera->unlock(); //! [Camera overview capture] } void overview_movie() { //! [Camera overview movie] + QMediaCaptureSession captureSession; camera = new QCamera; + captureSession.setCamera(camera); recorder = new QMediaRecorder(camera); + captureSession.setRecorder(recorder); - camera->setCaptureMode(QCamera::CaptureVideo); camera->start(); + // setup output format for the recorder + QMediaFormat format(QMediaFormat::MPEG4); + format.setVideoCodec(QMediaRecorder::VideoCodec::H264); + format.setAudioCodec(QMediaRecorder::AudioCodec::MP3); + recorder->setMediaFormat(settings); + //on shutter button pressed recorder->record(); @@ -179,19 +138,19 @@ void overview_movie() void camera_listing() { //! [Camera listing] - const QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); - for (const QCameraInfo &cameraInfo : cameras) - qDebug() << cameraInfo.deviceName(); + const QList<QCameraDevice> cameras = QMediaDevices::videoInputs(); + for (const QCameraDevice &cameraDevice : cameras) + qDebug() << cameraDevice.description(); //! [Camera listing] } void camera_selection() { //! [Camera selection] - const QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); - for (const QCameraInfo &cameraInfo : cameras) { - if (cameraInfo.deviceName() == "mycamera") - camera = new QCamera(cameraInfo); + const QList<QCameraDevice> cameras = QMediaDevices::videoInputs(); + for (const QCameraDevice &cameraDevice : cameras) { + if (cameraDevice.description() == "mycamera") + camera = new QCamera(cameraDevice); } //! [Camera selection] } @@ -200,95 +159,54 @@ void camera_info() { //! [Camera info] QCamera myCamera; - QCameraInfo cameraInfo(myCamera); + QCameraDevice cameraDevice = camera->cameraDevice(); - if (cameraInfo.position() == QCamera::FrontFace) + if (cameraDevice.position() == QCameraDevice::FrontFace) qDebug() << "The camera is on the front face of the hardware system."; - else if (cameraInfo.position() == QCamera::BackFace) + else if (cameraDevice.position() == QCameraDevice::BackFace) qDebug() << "The camera is on the back face of the hardware system."; - - qDebug() << "The camera sensor orientation is " << cameraInfo.orientation() << " degrees."; //! [Camera info] } void camera_blah() { //! [Camera] + QMediaCaptureSession captureSession; camera = new QCamera; + captureSession.setCamera(camera); - viewfinder = new QCameraViewfinder(); + viewfinder = new QVideoWidget(); viewfinder->show(); + captureSession.setVideoOutput(viewfinder); - camera->setViewfinder(viewfinder); - - imageCapture = new QCameraImageCapture(camera); + imageCapture = new QImageCapture(camera); + captureSession.setImageCapture(imageCapture); - camera->setCaptureMode(QCamera::CaptureStillImage); camera->start(); //! [Camera] //! [Camera keys] - //on half pressed shutter button - camera->searchAndLock(); - //on shutter button pressed imageCapture->capture(); - - //on shutter button released - camera->unlock(); //! [Camera keys] } void cameraimageprocessing() { - //! [Camera image whitebalance] camera = new QCamera; - QCameraImageProcessing *imageProcessing = camera->imageProcessing(); - - if (imageProcessing->isAvailable()) { - imageProcessing->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceFluorescent); - } //! [Camera image whitebalance] - - //! [Camera image denoising] - imageProcessing->setDenoisingLevel(-0.3); //reduce the amount of denoising applied - //! [Camera image denoising] + camera->setWhiteBalanceMode(QCamera::WhiteBalanceFluorescent); + //! [Camera image whitebalance] } void camerafocus() { - //! [Camera custom zoom] - QCameraFocus *focus = camera->focus(); - focus->setFocusPointMode(QCameraFocus::FocusPointCustom); - focus->setCustomFocusPoint(QPointF(0.25f, 0.75f)); // A point near the bottom left, 25% away from the corner, near that shiny vase - //! [Camera custom zoom] - - //! [Camera combined zoom] - focus->zoomTo(3.0, 4.0); // Super zoom! - //! [Camera combined zoom] - - //! [Camera focus zones] - focus->setFocusPointMode(QCameraFocus::FocusPointAuto); - const QList<QCameraFocusZone> zones = focus->focusZones(); - for (const QCameraFocusZone &zone : zones) { - if (zone.status() == QCameraFocusZone::Focused) { - // Draw a green box at zone.area() - } else if (zone.status() == QCameraFocusZone::Selected) { - // This area is selected for autofocusing, but is not in focus - // Draw a yellow box at zone.area() - } - } - //! [Camera focus zones] -} - -void camera_viewfindersettings() -{ - //! [Camera viewfinder settings] - QCameraViewfinderSettings viewfinderSettings; - viewfinderSettings.setResolution(640, 480); - viewfinderSettings.setMinimumFrameRate(15.0); - viewfinderSettings.setMaximumFrameRate(30.0); - - camera->setViewfinderSettings(viewfinderSettings); - //! [Camera viewfinder settings] + //! [Camera custom focus] + camera->setFocusPointMode(QCamera::FocusModeManual); + camera->setCustomFocusPoint(QPointF(0.25f, 0.75f)); // A point near the bottom left, 25% away from the corner, near that shiny vase + //! [Camera custom focus] + + //! [Camera zoom] + camera->setZoomFactor(3.0); + //! [Camera zoom] } diff --git a/src/multimedia/doc/snippets/multimedia-snippets/devices.cpp b/src/multimedia/doc/snippets/multimedia-snippets/devices.cpp new file mode 100644 index 000000000..652400364 --- /dev/null +++ b/src/multimedia/doc/snippets/multimedia-snippets/devices.cpp @@ -0,0 +1,38 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include <QAudioDevice> +#include <QCameraDevice> +#include <QMediaDevices> +#include <QString> +#include <QTextStream> + +int main(int argc, char *argv[]) +{ + Q_UNUSED(argc); + Q_UNUSED(argv); + + QTextStream out(stdout); + + //! [Media Audio Input Device Enumeration] + const QList<QAudioDevice> audioDevices = QMediaDevices::audioInputs(); + for (const QAudioDevice &device : audioDevices) + { + out << "ID: " << device.id() << Qt::endl; + out << "Description: " << device.description() << Qt::endl; + out << "Is default: " << (device.isDefault() ? "Yes" : "No") << Qt::endl; + } + //! [Media Audio Input Device Enumeration] + + //! [Media Video Input Device Enumeration] + const QList<QCameraDevice> videoDevices = QMediaDevices::videoInputs(); + for (const QCameraDevice &device : videoDevices) + { + out << "ID: " << device.id() << Qt::endl; + out << "Description: " << device.description() << Qt::endl; + out << "Is default: " << (device.isDefault() ? "Yes" : "No") << Qt::endl; + } + //! [Media Video Input Device Enumeration] + + return 0; +} diff --git a/src/multimedia/doc/snippets/multimedia-snippets/media.cpp b/src/multimedia/doc/snippets/multimedia-snippets/media.cpp index 5ba7fcc25..a4b9a9fb5 100644 --- a/src/multimedia/doc/snippets/multimedia-snippets/media.cpp +++ b/src/multimedia/doc/snippets/multimedia-snippets/media.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Mobility Components. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause /* Media related snippets */ #include <QFile> @@ -44,17 +8,15 @@ #include "qmediaplaylist.h" #include "qmediarecorder.h" -#include "qmediaservice.h" -#include "qmediaplayercontrol.h" +#include "qplatformmediaplayer_p.h" #include "qmediaplayer.h" #include "qvideowidget.h" -#include "qcameraimagecapture.h" +#include "qimagecapture.h" #include "qcamera.h" #include "qcameraviewfinder.h" -#include "qaudioprobe.h" #include "qaudiorecorder.h" -#include "qvideoprobe.h" -#include <QAbstractVideoSurface> +#include "qurl.h" +#include <QVideoSink> class MediaExample : public QObject { Q_OBJECT @@ -62,28 +24,22 @@ class MediaExample : public QObject { void MediaControl(); void MediaPlayer(); void MediaRecorder(); - void AudioRecorder(); - void EncoderSettings(); - void ImageEncoderSettings(); - void AudioProbe(); - void VideoProbe(); + void recorderSettings(); + void imageSettings(); private: // Common naming - QMediaService *mediaService; QVideoWidget *videoWidget; QWidget *widget; QMediaPlayer *player; + QAudioOutput *audioOutput; QMediaPlaylist *playlist; QMediaContent video; QMediaRecorder *recorder; QCamera *camera; QCameraViewfinder *viewfinder; - QCameraImageCapture *imageCapture; + QImageCapture *imageCapture; QString fileName; - QAudioRecorder *audioRecorder; - QAudioProbe *audioProbe; - QVideoProbe *videoProbe; QMediaContent image1; QMediaContent image2; @@ -92,258 +48,62 @@ private: void MediaExample::MediaControl() { - { - //! [Request control] - QMediaPlayerControl *control = qobject_cast<QMediaPlayerControl *>( - mediaService->requestControl("org.qt-project.qt.mediaplayercontrol/5.0")); - //! [Request control] - Q_UNUSED(control); - } - - { - //! [Request control templated] - QMediaPlayerControl *control = mediaService->requestControl<QMediaPlayerControl *>(); - //! [Request control templated] - Q_UNUSED(control); - } } -void MediaExample::EncoderSettings() +void MediaExample::recorderSettings() { - //! [Audio encoder settings] - QAudioEncoderSettings audioSettings; - audioSettings.setCodec("audio/mpeg"); - audioSettings.setChannelCount(2); - - recorder->setAudioSettings(audioSettings); - //! [Audio encoder settings] + //! [Media recorder settings] + QMediaFormat format(QMediaFormat::MPEG4); + format.setVideoCodec(QMediaRecorder::VideoCodec::H264); + format.setAudioCodec(QMediaRecorder::AudioCodec::MP3); - //! [Video encoder settings] - QVideoEncoderSettings videoSettings; - videoSettings.setCodec("video/mpeg2"); - videoSettings.setResolution(640, 480); - - recorder->setVideoSettings(videoSettings); - //! [Video encoder settings] + recorder->setMediaFormat(settings); + //! [Media recorder settings] } -void MediaExample::ImageEncoderSettings() +void MediaExample::imageSettings() { - //! [Image encoder settings] - QImageEncoderSettings imageSettings; - imageSettings.setCodec("image/jpeg"); - imageSettings.setResolution(1600, 1200); - - imageCapture->setEncodingSettings(imageSettings); - //! [Image encoder settings] + //! [Image recorder settings] + imageCapture->setFileFormat(QImageCapture::JPEG); + imageCapture->setResolution(1600, 1200); + //! [Image recorder settings] } void MediaExample::MediaPlayer() { //! [Player] player = new QMediaPlayer; - connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64))); - player->setMedia(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3")); - player->setVolume(50); + audioOutput = new QAudioOutput; + player->setAudioOutput(audioOutput); + connect(player, &QMediaPlayer::positionChanged, this, &MediaExample::positionChanged); + player->setSource(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3")); + audioOutput->setVolume(50); player->play(); //! [Player] //! [Local playback] player = new QMediaPlayer; + audioOutput = new QAudioOutput; + player->setAudioOutput(audioOutput); // ... - player->setMedia(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3")); - player->setVolume(50); + player->setSource(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3")); + audioOutput->setVolume(50); player->play(); //! [Local playback] - - //! [Audio playlist] - player = new QMediaPlayer; - - playlist = new QMediaPlaylist(player); - playlist->addMedia(QUrl("http://example.com/myfile1.mp3")); - playlist->addMedia(QUrl("http://example.com/myfile2.mp3")); - // ... - playlist->setCurrentIndex(1); - player->play(); - //! [Audio playlist] - - //! [Movie playlist] - playlist = new QMediaPlaylist; - playlist->addMedia(QUrl("http://example.com/movie1.mp4")); - playlist->addMedia(QUrl("http://example.com/movie2.mp4")); - playlist->addMedia(QUrl("http://example.com/movie3.mp4")); - playlist->setCurrentIndex(1); - - player = new QMediaPlayer; - player->setPlaylist(playlist); - - videoWidget = new QVideoWidget; - player->setVideoOutput(videoWidget); - videoWidget->show(); - - player->play(); - //! [Movie playlist] - - //! [Pipeline] - player = new QMediaPlayer; - player->setMedia(QUrl("gst-pipeline: videotestsrc ! autovideosink")); - player->play(); - //! [Pipeline] - - //! [Pipeline Surface] - class Surface : public QAbstractVideoSurface - { - public: - Surface(QObject *p) : QAbstractVideoSurface(p) { } - QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType) const override - { - // Make sure that the driver supports this pixel format. - return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_YUYV; - } - - // Video frames are handled here. - bool present(const QVideoFrame &) override { return true; } - }; - - player = new QMediaPlayer; - player->setVideoOutput(new Surface(player)); - player->setMedia(QUrl("gst-pipeline: videotestsrc ! qtvideosink")); - player->play(); - //! [Pipeline Surface] - - //! [Pipeline Widget] - player = new QMediaPlayer; - videoWidget = new QVideoWidget; - videoWidget->show(); - player->setVideoOutput(videoWidget); - player->setMedia(QUrl("gst-pipeline: videotestsrc ! xvimagesink name=\"qtvideosink\"")); - player->play(); - //! [Pipeline Widget] - - //! [Pipeline appsrc] - QImage img("images/qt-logo.png"); - img = img.convertToFormat(QImage::Format_ARGB32); - QByteArray ba(reinterpret_cast<const char *>(img.bits()), img.sizeInBytes()); - QBuffer buffer(&ba); - buffer.open(QIODevice::ReadOnly); - player = new QMediaPlayer; - player->setMedia(QUrl("gst-pipeline: appsrc blocksize=4294967295 ! \ - video/x-raw,format=BGRx,framerate=30/1,width=200,height=147 ! \ - coloreffects preset=heat ! videoconvert ! video/x-raw,format=I420 ! jpegenc ! rtpjpegpay ! \ - udpsink host=127.0.0.1 port=5000"), &buffer); - player->play(); - - QMediaPlayer *receiver = new QMediaPlayer; - videoWidget = new QVideoWidget; - receiver->setVideoOutput(videoWidget); - receiver->setMedia(QUrl("gst-pipeline: udpsrc port=5000 ! \ - application/x-rtp,encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegdec ! \ - xvimagesink name=qtvideosink")); - receiver->play(); - // Content will be shown in this widget. - videoWidget->show(); - //! [Pipeline appsrc] } void MediaExample::MediaRecorder() { //! [Media recorder] - recorder = new QMediaRecorder(camera); - - QAudioEncoderSettings audioSettings; - audioSettings.setCodec("audio/amr"); - audioSettings.setQuality(QMultimedia::HighQuality); - - recorder->setAudioSettings(audioSettings); - - recorder->setOutputLocation(QUrl::fromLocalFile(fileName)); - recorder->record(); + QMediaCaptureSession session; + QAudioInput audioInput; + session.setAudioInput(&input); + QMediaRecorder recorder; + session.setRecorder(&recorder); + recorder.setQuality(QMediaRecorder::HighQuality); + recorder.setOutputLocation(QUrl::fromLocalFile("test.mp3")); + recorder.record(); //! [Media recorder] } -void MediaExample::AudioRecorder() -{ - //! [Audio recorder] - audioRecorder = new QAudioRecorder; - - QAudioEncoderSettings audioSettings; - audioSettings.setCodec("audio/amr"); - audioSettings.setQuality(QMultimedia::HighQuality); - - audioRecorder->setEncodingSettings(audioSettings); - - audioRecorder->setOutputLocation(QUrl::fromLocalFile("test.amr")); - audioRecorder->record(); - //! [Audio recorder] - - //! [Audio recorder inputs] - const QStringList inputs = audioRecorder->audioInputs(); - QString selectedInput = audioRecorder->defaultAudioInput(); - - for (const QString &input : inputs) { - QString description = audioRecorder->audioInputDescription(input); - // show descriptions to user and allow selection - selectedInput = input; - } - - audioRecorder->setAudioInput(selectedInput); - //! [Audio recorder inputs] -} - -void MediaExample::AudioProbe() -{ - //! [Audio probe] - audioRecorder = new QAudioRecorder; - - QAudioEncoderSettings audioSettings; - audioSettings.setCodec("audio/amr"); - audioSettings.setQuality(QMultimedia::HighQuality); - - audioRecorder->setEncodingSettings(audioSettings); - - audioRecorder->setOutputLocation(QUrl::fromLocalFile("test.amr")); - - audioProbe = new QAudioProbe(this); - if (audioProbe->setSource(audioRecorder)) { - // Probing succeeded, audioProbe->isValid() should be true. - connect(audioProbe, SIGNAL(audioBufferProbed(QAudioBuffer)), - this, SLOT(calculateLevel(QAudioBuffer))); - } - - audioRecorder->record(); - // Now audio buffers being recorded should be signaled - // by the probe, so we can do things like calculating the - // audio power level, or performing a frequency transform - //! [Audio probe] -} - -void MediaExample::VideoProbe() -{ - //! [Video probe] - camera = new QCamera; - viewfinder = new QCameraViewfinder(); - camera->setViewfinder(viewfinder); - - camera->setCaptureMode(QCamera::CaptureVideo); - - videoProbe = new QVideoProbe(this); - - if (videoProbe->setSource(camera)) { - // Probing succeeded, videoProbe->isValid() should be true. - connect(videoProbe, SIGNAL(videoFrameProbed(QVideoFrame)), - this, SLOT(detectBarcodes(QVideoFrame))); - } - - camera->start(); - // Viewfinder frames should now also be emitted by - // the video probe, even in still image capture mode. - // Another alternative is to install the probe on a - // QMediaRecorder connected to the camera to get the - // recorded frames, if they are different from the - // viewfinder frames. - - //! [Video probe] -} - - diff --git a/src/multimedia/doc/snippets/multimedia-snippets/multimedia-snippets.pro b/src/multimedia/doc/snippets/multimedia-snippets/multimedia-snippets.pro deleted file mode 100644 index a46b20bd0..000000000 --- a/src/multimedia/doc/snippets/multimedia-snippets/multimedia-snippets.pro +++ /dev/null @@ -1,26 +0,0 @@ -# Doc snippets - compiled for truthiness - -TEMPLATE = lib -TARGET = qtmmksnippets - -INCLUDEPATH += ../../../../src/global \ - ../../../../src/multimedia \ - ../../../../src/multimedia/audio \ - ../../../../src/multimedia/video \ - ../../../../src/multimedia/camera - -CONFIG += console - -QT += multimedia multimediawidgets widgets multimedia-private - -SOURCES += \ - audio.cpp \ - video.cpp \ - camera.cpp \ - media.cpp \ - qsound.cpp - -OTHER_FILES += \ - soundeffect.qml \ - qtvideosink.qml \ - multiple-videooutputs.qml diff --git a/src/multimedia/doc/snippets/multimedia-snippets/multiple-videooutputs.qml b/src/multimedia/doc/snippets/multimedia-snippets/multiple-videooutputs.qml index e3c1587f6..0c673cc42 100644 --- a/src/multimedia/doc/snippets/multimedia-snippets/multiple-videooutputs.qml +++ b/src/multimedia/doc/snippets/multimedia-snippets/multiple-videooutputs.qml @@ -1,53 +1,19 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import QtQuick 2.0 -import QtQuick.Window 2.2 -import QtMultimedia 5.15 +import QtQuick +import QtQuick.Window +import QtMultimedia //! [complete] Item { MediaPlayer { id: mediaplayer - autoPlay: true source: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" videoOutput: [v1, v2] + audioOutput: AudioOutput { + + } } VideoOutput { diff --git a/src/multimedia/doc/snippets/multimedia-snippets/qaudioprobe.cpp b/src/multimedia/doc/snippets/multimedia-snippets/qaudioprobe.cpp deleted file mode 100644 index 8543395f3..000000000 --- a/src/multimedia/doc/snippets/multimedia-snippets/qaudioprobe.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//! [desc] -QAudioRecorder *recorder = new QAudioRecorder(); -QAudioProbe *probe = new QAudioProbe; - -// ... configure the audio recorder (skipped) - -connect(probe, SIGNAL(audioBufferProbed(QAudioBuffer)), this, SLOT(processBuffer(QAudioBuffer))); - -probe->setSource(recorder); // Returns true, hopefully. - -recorder->record(); // Now we can do things like calculating levels or performing an FFT -//! [desc] diff --git a/src/multimedia/doc/snippets/multimedia-snippets/qsound.cpp b/src/multimedia/doc/snippets/multimedia-snippets/qsound.cpp index fbc849c2e..644dcb228 100644 --- a/src/multimedia/doc/snippets/multimedia-snippets/qsound.cpp +++ b/src/multimedia/doc/snippets/multimedia-snippets/qsound.cpp @@ -1,69 +1,9 @@ - /**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "qpushbutton.h" -#include "qsound.h" #include "qsoundeffect.h" -void qsoundsnippet() { - //! [0] - QSound::play("mysounds/bells.wav"); - //! [0] - - - //! [1] - QSound bells("mysounds/bells.wav"); - bells.play(); - //! [1] -} - void qsoundeffectsnippet() { //! [2] QSoundEffect effect; diff --git a/src/multimedia/doc/snippets/multimedia-snippets/qtvideosink.qml b/src/multimedia/doc/snippets/multimedia-snippets/qtvideosink.qml index a4ae07f30..eeac9c28e 100644 --- a/src/multimedia/doc/snippets/multimedia-snippets/qtvideosink.qml +++ b/src/multimedia/doc/snippets/multimedia-snippets/qtvideosink.qml @@ -1,55 +1,23 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import QtQuick 2.0 -import QtMultimedia 5.12 +import QtQuick +import QtMultimedia //! [complete] Item { MediaPlayer { id: mediaplayer - source: "gst-pipeline: videotestsrc ! qtvideosink" + source: "file:///test.mp4" + videoOutput: videoOutput + audioOutput: AudioOutput { + + } } VideoOutput { + id: videoOutput anchors.fill: parent - source: mediaplayer } MouseArea { diff --git a/src/multimedia/doc/snippets/multimedia-snippets/soundeffect.qml b/src/multimedia/doc/snippets/multimedia-snippets/soundeffect.qml index c414aca56..e91e54e3c 100644 --- a/src/multimedia/doc/snippets/multimedia-snippets/soundeffect.qml +++ b/src/multimedia/doc/snippets/multimedia-snippets/soundeffect.qml @@ -1,44 +1,8 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import QtQuick 2.0 -import QtMultimedia 5.5 +import QtQuick +import QtMultimedia //! [complete snippet] Text { diff --git a/src/multimedia/doc/snippets/multimedia-snippets/video.cpp b/src/multimedia/doc/snippets/multimedia-snippets/video.cpp index 46327e3d6..8cc3b41b3 100644 --- a/src/multimedia/doc/snippets/multimedia-snippets/video.cpp +++ b/src/multimedia/doc/snippets/multimedia-snippets/video.cpp @@ -1,95 +1,29 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Mobility Components. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause /* Video related snippets */ #include "qvideorenderercontrol.h" -#include "qmediaservice.h" #include "qmediaplayer.h" -#include "qabstractvideosurface.h" -#include "qvideowidgetcontrol.h" +#include "qvideosink.h" #include "qvideowindowcontrol.h" #include "qgraphicsvideoitem.h" -#include "qmediaplaylist.h" -#include "qvideosurfaceformat.h" +#include "qvideoframeformat.h" #include <QFormLayout> #include <QGraphicsView> -//! [Derived Surface] -class MyVideoSurface : public QAbstractVideoSurface -{ - QList<QVideoFrame::PixelFormat> supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const - { - Q_UNUSED(handleType); - - // Return the formats you will support - return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_RGB565; - } - - bool present(const QVideoFrame &frame) - { - Q_UNUSED(frame); - // Handle the frame and do your processing - - return true; - } -}; -//! [Derived Surface] - //! [Video producer] class MyVideoProducer : public QObject { Q_OBJECT - Q_PROPERTY(QAbstractVideoSurface *videoSurface READ videoSurface WRITE setVideoSurface) + Q_PROPERTY(QVideoSink *videoSink READ videoSink WRITE setVideoSink) public: - QAbstractVideoSurface* videoSurface() const { return m_surface; } + QVideoSink* videoSink() const { return m_sink; } - void setVideoSurface(QAbstractVideoSurface *surface) + void setVideoSink(QVideoSink *sink) { - if (m_surface != surface && m_surface && m_surface->isActive()) { - m_surface->stop(); - } - m_surface = surface; - if (m_surface) - m_surface->start(m_format); + m_sink = sink; } // ... @@ -97,13 +31,12 @@ public: public slots: void onNewVideoContentReceived(const QVideoFrame &frame) { - if (m_surface) - m_surface->present(frame); + if (m_sink) + m_sink->setVideoFrame(frame); } private: - QAbstractVideoSurface *m_surface; - QVideoSurfaceFormat m_format; + QVideoSink *m_sink; }; //! [Video producer] @@ -113,7 +46,6 @@ class VideoExample : public QObject { Q_OBJECT public: void VideoGraphicsItem(); - void VideoRendererControl(); void VideoWidget(); void VideoWindowControl(); void VideoWidgetControl(); @@ -121,46 +53,32 @@ public: private: // Common naming - QMediaService *mediaService; - QMediaPlaylist *playlist; QVideoWidget *videoWidget; QWidget *widget; QFormLayout *layout; - QAbstractVideoSurface *myVideoSurface; + QVideoSink *myVideoSink; QMediaPlayer *player; QMediaContent video; QGraphicsView *graphicsView; }; -void VideoExample::VideoRendererControl() -{ - //! [Video renderer control] - QVideoRendererControl *rendererControl = mediaService->requestControl<QVideoRendererControl *>(); - rendererControl->setSurface(myVideoSurface); - //! [Video renderer control] -} - void VideoExample::VideoWidget() { //! [Video widget] player = new QMediaPlayer; - - playlist = new QMediaPlaylist(player); - playlist->addMedia(QUrl("http://example.com/myclip1.mp4")); - playlist->addMedia(QUrl("http://example.com/myclip2.mp4")); + player->setSource(QUrl("http://example.com/myclip1.mp4")); videoWidget = new QVideoWidget; player->setVideoOutput(videoWidget); videoWidget->show(); - playlist->setCurrentIndex(1); player->play(); //! [Video widget] player->stop(); //! [Setting surface in player] - player->setVideoOutput(myVideoSurface); + player->setVideoOutput(myVideoSink); //! [Setting surface in player] } @@ -168,7 +86,7 @@ void VideoExample::VideoSurface() { //! [Widget Surface] QImage img = QImage("images/qt-logo.png").convertToFormat(QImage::Format_ARGB32); - QVideoSurfaceFormat format(img.size(), QVideoFrame::Format_ARGB32); + QVideoFrameFormat format(img.size(), QVideoFrameFormat::Format_ARGB8888); videoWidget = new QVideoWidget; videoWidget->videoSurface()->start(format); videoWidget->videoSurface()->present(img); @@ -180,30 +98,10 @@ void VideoExample::VideoSurface() graphicsView->scene()->addItem(item); graphicsView->show(); QImage img = QImage("images/qt-logo.png").convertToFormat(QImage::Format_ARGB32); - QVideoSurfaceFormat format(img.size(), QVideoFrame::Format_ARGB32); - item->videoSurface()->start(format); - item->videoSurface()->present(img); + item->videoSink()->setVideoFrame(QVideoFrame(img)); //! [GraphicsVideoItem Surface] } -void VideoExample::VideoWidgetControl() -{ - //! [Video widget control] - QVideoWidgetControl *widgetControl = mediaService->requestControl<QVideoWidgetControl *>(); - layout->addWidget(widgetControl->videoWidget()); - //! [Video widget control] -} - -void VideoExample::VideoWindowControl() -{ - //! [Video window control] - QVideoWindowControl *windowControl = mediaService->requestControl<QVideoWindowControl *>(); - windowControl->setWinId(widget->winId()); - windowControl->setDisplayRect(widget->rect()); - windowControl->setAspectRatioMode(Qt::KeepAspectRatio); - //! [Video window control] -} - void VideoExample::VideoGraphicsItem() { //! [Video graphics item] @@ -214,7 +112,7 @@ void VideoExample::VideoGraphicsItem() graphicsView->scene()->addItem(item); graphicsView->show(); - player->setMedia(QUrl("http://example.com/myclip4.ogv")); + player->setSource(QUrl("http://example.com/myclip4.ogv")); player->play(); //! [Video graphics item] } |