From 077f9711f0b9174ef9e9ffa7022aa06a9b3fc867 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Thu, 15 Oct 2009 14:40:33 +1000 Subject: Move audio and video examples into the common multimedia directory. Brings the video examples into multimedia directory, and removes the audio sub-directory so the directory structure is in line with the other example categories. Task-number: QT-667 Reviewed-by: Kurt Korbatits --- demos/qtdemo/xml/examples.xml | 2 +- doc/src/examples/audiodevices.qdoc | 2 +- doc/src/examples/audioinput.qdoc | 2 +- doc/src/examples/audiooutput.qdoc | 2 +- doc/src/examples/videographicsitem.qdoc | 2 +- doc/src/examples/videowidget.qdoc | 30 +-- doc/src/getting-started/examples.qdoc | 10 +- examples/examples.pro | 3 +- examples/multimedia/audio/audio.pro | 10 - .../multimedia/audio/audiodevices/audiodevices.cpp | 274 ------------------- .../multimedia/audio/audiodevices/audiodevices.h | 78 ------ .../multimedia/audio/audiodevices/audiodevices.pro | 17 -- .../audio/audiodevices/audiodevicesbase.ui | 233 ---------------- examples/multimedia/audio/audiodevices/main.cpp | 55 ---- .../multimedia/audio/audioinput/audioinput.cpp | 296 --------------------- examples/multimedia/audio/audioinput/audioinput.h | 124 --------- .../multimedia/audio/audioinput/audioinput.pro | 16 -- examples/multimedia/audio/audioinput/main.cpp | 55 ---- .../multimedia/audio/audiooutput/audiooutput.cpp | 270 ------------------- .../multimedia/audio/audiooutput/audiooutput.h | 110 -------- .../multimedia/audio/audiooutput/audiooutput.pro | 16 -- examples/multimedia/audio/audiooutput/main.cpp | 56 ---- examples/multimedia/audiodevices/audiodevices.cpp | 274 +++++++++++++++++++ examples/multimedia/audiodevices/audiodevices.h | 78 ++++++ examples/multimedia/audiodevices/audiodevices.pro | 17 ++ .../multimedia/audiodevices/audiodevicesbase.ui | 233 ++++++++++++++++ examples/multimedia/audiodevices/main.cpp | 55 ++++ examples/multimedia/audioinput/audioinput.cpp | 296 +++++++++++++++++++++ examples/multimedia/audioinput/audioinput.h | 124 +++++++++ examples/multimedia/audioinput/audioinput.pro | 16 ++ examples/multimedia/audioinput/main.cpp | 55 ++++ examples/multimedia/audiooutput/audiooutput.cpp | 270 +++++++++++++++++++ examples/multimedia/audiooutput/audiooutput.h | 110 ++++++++ examples/multimedia/audiooutput/audiooutput.pro | 16 ++ examples/multimedia/audiooutput/main.cpp | 56 ++++ examples/multimedia/multimedia.pro | 14 +- examples/multimedia/videographicsitem/main.cpp | 55 ++++ .../videographicsitem/videographicsitem.pro | 21 ++ .../multimedia/videographicsitem/videoitem.cpp | 144 ++++++++++ examples/multimedia/videographicsitem/videoitem.h | 79 ++++++ .../multimedia/videographicsitem/videoplayer.cpp | 210 +++++++++++++++ .../multimedia/videographicsitem/videoplayer.h | 86 ++++++ examples/multimedia/videowidget/main.cpp | 54 ++++ examples/multimedia/videowidget/videoplayer.cpp | 183 +++++++++++++ examples/multimedia/videowidget/videoplayer.h | 79 ++++++ examples/multimedia/videowidget/videowidget.cpp | 114 ++++++++ examples/multimedia/videowidget/videowidget.h | 76 ++++++ examples/multimedia/videowidget/videowidget.pro | 25 ++ .../multimedia/videowidget/videowidgetsurface.cpp | 175 ++++++++++++ .../multimedia/videowidget/videowidgetsurface.h | 81 ++++++ examples/video/video.pro | 6 - examples/video/videographicsitem/main.cpp | 55 ---- .../video/videographicsitem/videographicsitem.pro | 21 -- examples/video/videographicsitem/videoitem.cpp | 144 ---------- examples/video/videographicsitem/videoitem.h | 79 ------ examples/video/videographicsitem/videoplayer.cpp | 210 --------------- examples/video/videographicsitem/videoplayer.h | 86 ------ examples/video/videowidget/main.cpp | 54 ---- examples/video/videowidget/videoplayer.cpp | 183 ------------- examples/video/videowidget/videoplayer.h | 79 ------ examples/video/videowidget/videowidget.cpp | 114 -------- examples/video/videowidget/videowidget.h | 76 ------ examples/video/videowidget/videowidget.pro | 19 -- examples/video/videowidget/videowidgetsurface.cpp | 175 ------------ examples/video/videowidget/videowidgetsurface.h | 81 ------ 65 files changed, 3020 insertions(+), 3021 deletions(-) delete mode 100644 examples/multimedia/audio/audio.pro delete mode 100644 examples/multimedia/audio/audiodevices/audiodevices.cpp delete mode 100644 examples/multimedia/audio/audiodevices/audiodevices.h delete mode 100644 examples/multimedia/audio/audiodevices/audiodevices.pro delete mode 100644 examples/multimedia/audio/audiodevices/audiodevicesbase.ui delete mode 100644 examples/multimedia/audio/audiodevices/main.cpp delete mode 100644 examples/multimedia/audio/audioinput/audioinput.cpp delete mode 100644 examples/multimedia/audio/audioinput/audioinput.h delete mode 100644 examples/multimedia/audio/audioinput/audioinput.pro delete mode 100644 examples/multimedia/audio/audioinput/main.cpp delete mode 100644 examples/multimedia/audio/audiooutput/audiooutput.cpp delete mode 100644 examples/multimedia/audio/audiooutput/audiooutput.h delete mode 100644 examples/multimedia/audio/audiooutput/audiooutput.pro delete mode 100644 examples/multimedia/audio/audiooutput/main.cpp create mode 100644 examples/multimedia/audiodevices/audiodevices.cpp create mode 100644 examples/multimedia/audiodevices/audiodevices.h create mode 100644 examples/multimedia/audiodevices/audiodevices.pro create mode 100644 examples/multimedia/audiodevices/audiodevicesbase.ui create mode 100644 examples/multimedia/audiodevices/main.cpp create mode 100644 examples/multimedia/audioinput/audioinput.cpp create mode 100644 examples/multimedia/audioinput/audioinput.h create mode 100644 examples/multimedia/audioinput/audioinput.pro create mode 100644 examples/multimedia/audioinput/main.cpp create mode 100644 examples/multimedia/audiooutput/audiooutput.cpp create mode 100644 examples/multimedia/audiooutput/audiooutput.h create mode 100644 examples/multimedia/audiooutput/audiooutput.pro create mode 100644 examples/multimedia/audiooutput/main.cpp create mode 100644 examples/multimedia/videographicsitem/main.cpp create mode 100644 examples/multimedia/videographicsitem/videographicsitem.pro create mode 100644 examples/multimedia/videographicsitem/videoitem.cpp create mode 100644 examples/multimedia/videographicsitem/videoitem.h create mode 100644 examples/multimedia/videographicsitem/videoplayer.cpp create mode 100644 examples/multimedia/videographicsitem/videoplayer.h create mode 100644 examples/multimedia/videowidget/main.cpp create mode 100644 examples/multimedia/videowidget/videoplayer.cpp create mode 100644 examples/multimedia/videowidget/videoplayer.h create mode 100644 examples/multimedia/videowidget/videowidget.cpp create mode 100644 examples/multimedia/videowidget/videowidget.h create mode 100644 examples/multimedia/videowidget/videowidget.pro create mode 100644 examples/multimedia/videowidget/videowidgetsurface.cpp create mode 100644 examples/multimedia/videowidget/videowidgetsurface.h delete mode 100644 examples/video/video.pro delete mode 100644 examples/video/videographicsitem/main.cpp delete mode 100644 examples/video/videographicsitem/videographicsitem.pro delete mode 100644 examples/video/videographicsitem/videoitem.cpp delete mode 100644 examples/video/videographicsitem/videoitem.h delete mode 100644 examples/video/videographicsitem/videoplayer.cpp delete mode 100644 examples/video/videographicsitem/videoplayer.h delete mode 100644 examples/video/videowidget/main.cpp delete mode 100644 examples/video/videowidget/videoplayer.cpp delete mode 100644 examples/video/videowidget/videoplayer.h delete mode 100644 examples/video/videowidget/videowidget.cpp delete mode 100644 examples/video/videowidget/videowidget.h delete mode 100644 examples/video/videowidget/videowidget.pro delete mode 100644 examples/video/videowidget/videowidgetsurface.cpp delete mode 100644 examples/video/videowidget/videowidgetsurface.h diff --git a/demos/qtdemo/xml/examples.xml b/demos/qtdemo/xml/examples.xml index 2c31484..83bd200 100644 --- a/demos/qtdemo/xml/examples.xml +++ b/demos/qtdemo/xml/examples.xml @@ -154,7 +154,7 @@ - + diff --git a/doc/src/examples/audiodevices.qdoc b/doc/src/examples/audiodevices.qdoc index 0d0932e..1505846 100644 --- a/doc/src/examples/audiodevices.qdoc +++ b/doc/src/examples/audiodevices.qdoc @@ -40,7 +40,7 @@ ****************************************************************************/ /*! - \example multimedia/audio/audiodevices + \example multimedia/audiodevices \title Audio Devices Example The Audio Devices example demonstrates the basic use of QAudioDeviceInfo class diff --git a/doc/src/examples/audioinput.qdoc b/doc/src/examples/audioinput.qdoc index ac44d75..8553e92 100644 --- a/doc/src/examples/audioinput.qdoc +++ b/doc/src/examples/audioinput.qdoc @@ -40,7 +40,7 @@ ****************************************************************************/ /*! - \example multimedia/audio/audioinput + \example multimedia/audioinput \title AudioInput Example The Audio Input example demonstrates the basic use of QAudioInput class diff --git a/doc/src/examples/audiooutput.qdoc b/doc/src/examples/audiooutput.qdoc index 2ed6ce4..58b8ea9 100644 --- a/doc/src/examples/audiooutput.qdoc +++ b/doc/src/examples/audiooutput.qdoc @@ -40,7 +40,7 @@ ****************************************************************************/ /*! - \example multimedia/audio/audiooutput + \example multimedia/audiooutput \title Audio Output Example The Audio Output example demonstrates the basic use of the QAudioOutput class diff --git a/doc/src/examples/videographicsitem.qdoc b/doc/src/examples/videographicsitem.qdoc index ce24f09..e1cb6ed 100644 --- a/doc/src/examples/videographicsitem.qdoc +++ b/doc/src/examples/videographicsitem.qdoc @@ -40,7 +40,7 @@ ****************************************************************************/ /*! - \example video/videographicsitem + \example multimedia/videographicsitem \title Video Graphics Item Example The Video Graphics Item example shows how to implement a QGraphicsItem that displays video on a diff --git a/doc/src/examples/videowidget.qdoc b/doc/src/examples/videowidget.qdoc index 1b214d2..4223c1f 100644 --- a/doc/src/examples/videowidget.qdoc +++ b/doc/src/examples/videowidget.qdoc @@ -40,7 +40,7 @@ ****************************************************************************/ /*! - \example video/videowidget + \example multimedia/videowidget \title Video Widget Example The Video Widget example shows how to implement a video widget using @@ -50,7 +50,7 @@ \section1 VideoWidgetSurface Class Definition - \snippet examples/video/videowidget/videowidgetsurface.h 0 + \snippet examples/multimedia/videowidget/videowidgetsurface.h 0 The VideoWidgetSurface class inherits QAbstractVideoSurface and paints video frames on a QWidget. This is a separate class to VideoWidget as both @@ -62,7 +62,7 @@ \section1 VideoWidgetSurface Class Implementation - \snippet examples/video/videowidget/videowidgetsurface.cpp 0 + \snippet examples/multimedia/videowidget/videowidgetsurface.cpp 0 From the supportedPixelFormats() function we return a list of pixel formats the surface can paint. The order of the list hints at which formats are @@ -74,7 +74,7 @@ return any pixel formats if handleType is not QAbstractVideoBuffer::NoHandle. - \snippet examples/video/videowidget/videowidgetsurface.cpp 1 + \snippet examples/multimedia/videowidget/videowidgetsurface.cpp 1 In isFormatSupported() we test if the frame type of a surface format maps to a valid QImage format, that the frame size is not empty, and the handle @@ -85,7 +85,7 @@ that the size is not empty so a reimplementation wasn't strictly necessary in this case. - \snippet examples/video/videowidget/videowidgetsurface.cpp 2 + \snippet examples/multimedia/videowidget/videowidgetsurface.cpp 2 To start our surface we'll extract the image format and size from the selected video format and save it for use in the paint() function. If the @@ -94,7 +94,7 @@ by calling QAbstractVideoSurface::start(). Finally since the video size may have changed we'll trigger an update of the widget, and video geometry. - \snippet examples/video/videowidget/videowidgetsurface.cpp 5 + \snippet examples/multimedia/videowidget/videowidgetsurface.cpp 5 The updateVideoRect() function calculates the region within the widget the video occupies. The \l {QVideoSurfaceFormat::sizeHint()}{size hint} of the @@ -105,7 +105,7 @@ size in the center of the widget. Otherwise we shrink the size maintaining the aspect ratio so that it does fit. - \snippet examples/video/videowidget/videowidgetsurface.cpp 4 + \snippet examples/multimedia/videowidget/videowidgetsurface.cpp 4 We can't paint from outside a paint event, so when a new frame is received in present() we save a reference to it and force an immediate repaint of @@ -118,7 +118,7 @@ \l {QAbstractVideoSurface::UnsupportedFormatError}{UnsupportedFormatError} on our surface and stop it immediately. - \snippet examples/video/videowidget/videowidgetsurface.cpp 6 + \snippet examples/multimedia/videowidget/videowidgetsurface.cpp 6 The paint() function is called by the video widget to paint the current video frame. Before we draw the frame first we'll check the format for @@ -128,7 +128,7 @@ construct a new QImage from the current video frame, and draw it to the the widget. - \snippet examples/video/videowidget/videowidgetsurface.cpp 3 + \snippet examples/multimedia/videowidget/videowidgetsurface.cpp 3 When the surface is stopped we need to release the current frame and invalidate the video region. Then we confirm the surface has been @@ -141,7 +141,7 @@ The VideoWidget class uses the VideoWidgetSurface class to implement a video widget. - \snippet examples/video/videowidget/videowidget.h 0 + \snippet examples/multimedia/videowidget/videowidget.h 0 The VideoWidget QWidget implementation is minimal with just the sizeHint(), paintEvent(), and resizeEvent() functions in addition to the constructor, @@ -149,7 +149,7 @@ \section1 VideoWidget Class Implementation - \snippet examples/video/videowidget/videowidget.cpp 0 + \snippet examples/multimedia/videowidget/videowidget.cpp 0 In the VideoWidget constructor we set some flags to speed up re-paints a little. Setting the Qt::WA_NoSystemBackground flag and disabling automatic @@ -162,17 +162,17 @@ Finally we construct an instance of the VideoWidgetSurface class. - \snippet examples/video/videowidget/videowidget.cpp 1 + \snippet examples/multimedia/videowidget/videowidget.cpp 1 In the destructor we simply delete the VideoWidgetSurface instance. - \snippet examples/video/videowidget/videowidget.cpp 2 + \snippet examples/multimedia/videowidget/videowidget.cpp 2 We get the size hint for the widget from the video format of the surface which is calculated from viewport and pixel aspect ratio of the video format. - \snippet examples/video/videowidget/videowidget.cpp 3 + \snippet examples/multimedia/videowidget/videowidget.cpp 3 When the video widget receives a paint event we first check if the surface is started, if not then we simply fill the widget with the background @@ -180,7 +180,7 @@ by the paint region, before calling paint on the video surface to draw the current frame. - \snippet examples/video/videowidget/videowidget.cpp 4 + \snippet examples/multimedia/videowidget/videowidget.cpp 4 The resizeEvent() function is reimplemented to trigger an update of the video region when the widget is resized. diff --git a/doc/src/getting-started/examples.qdoc b/doc/src/getting-started/examples.qdoc index d72f816..d6ade22 100644 --- a/doc/src/getting-started/examples.qdoc +++ b/doc/src/getting-started/examples.qdoc @@ -806,16 +806,16 @@ Audio API in Qt applications. \list - \o \l{multimedia/audio/audiodevices}{Audio Devices} - \o \l{multimedia/audio/audiooutput}{Audio Output} - \o \l{multimedia/audio/audioinput}{Audio Input} + \o \l{multimedia/audiodevices}{Audio Devices} + \o \l{multimedia/audiooutput}{Audio Output} + \o \l{multimedia/audioinput}{Audio Input} \endlist \section1 Video Output \list - \o \l{video/videowidget}{Video Widget}\raisedaster - \o \l{video/videographicsitem}{Video Graphics Item} + \o \l{multimedia/videowidget}{Video Widget}\raisedaster + \o \l{multimedia/videographicsitem}{Video Graphics Item} \endlist \section1 Phonon diff --git a/examples/examples.pro b/examples/examples.pro index 7acd67b..d11e36b 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -39,8 +39,7 @@ symbian: SUBDIRS = \ xml contains(QT_CONFIG, multimedia) { - SUBDIRS += video - !static: SUBDIRS += multimedia + SUBDIRS += multimedia } contains(QT_CONFIG, script): SUBDIRS += script diff --git a/examples/multimedia/audio/audio.pro b/examples/multimedia/audio/audio.pro deleted file mode 100644 index c64bb34..0000000 --- a/examples/multimedia/audio/audio.pro +++ /dev/null @@ -1,10 +0,0 @@ -TEMPLATE = subdirs -SUBDIRS = audioinput \ - audiooutput \ - audiodevices - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio -sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS audio.pro README -sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio -INSTALLS += target sources diff --git a/examples/multimedia/audio/audiodevices/audiodevices.cpp b/examples/multimedia/audio/audiodevices/audiodevices.cpp deleted file mode 100644 index 4198605..0000000 --- a/examples/multimedia/audio/audiodevices/audiodevices.cpp +++ /dev/null @@ -1,274 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include -#include - -#include "audiodevices.h" - -AudioDevicesBase::AudioDevicesBase( QMainWindow *parent, Qt::WFlags f ) -{ - Q_UNUSED(parent) - Q_UNUSED(f) - setupUi( this ); -} - -AudioDevicesBase::~AudioDevicesBase() {} - - -AudioTest::AudioTest( QMainWindow *parent, Qt::WFlags f ) - : AudioDevicesBase( parent, f ) -{ - nearestFreq->setDisabled(true); - nearestChannel->setDisabled(true); - nearestCodec->setDisabled(true); - nearestSampleSize->setDisabled(true); - nearestSampleType->setDisabled(true); - nearestEndian->setDisabled(true); - logOutput->setDisabled(true); - - mode = QAudio::AudioOutput; - modeBox->addItem("Input"); - modeBox->addItem("Output"); - - connect(testButton,SIGNAL(clicked()),SLOT(test())); - connect(modeBox,SIGNAL(activated(int)),SLOT(modeChanged(int))); - connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int))); - connect(frequencyBox,SIGNAL(activated(int)),SLOT(freqChanged(int))); - connect(channelsBox,SIGNAL(activated(int)),SLOT(channelChanged(int))); - connect(codecsBox,SIGNAL(activated(int)),SLOT(codecChanged(int))); - connect(sampleSizesBox,SIGNAL(activated(int)),SLOT(sampleSizeChanged(int))); - connect(sampleTypesBox,SIGNAL(activated(int)),SLOT(sampleTypeChanged(int))); - connect(endianBox,SIGNAL(activated(int)),SLOT(endianChanged(int))); - - modeBox->setCurrentIndex(0); - modeChanged(0); - deviceBox->setCurrentIndex(0); - deviceChanged(0); -} - -AudioTest::~AudioTest() -{ -} - -void AudioTest::test() -{ - // tries to set all the settings picked. - logOutput->clear(); - logOutput->append("NOTE: an invalid codec audio/test exists for testing, to get a fail condition."); - - if (!deviceInfo.isNull()) { - if (deviceInfo.isFormatSupported(settings)) { - logOutput->append("Success"); - nearestFreq->setText(""); - nearestChannel->setText(""); - nearestCodec->setText(""); - nearestSampleSize->setText(""); - nearestSampleType->setText(""); - nearestEndian->setText(""); - } else { - QAudioFormat nearest = deviceInfo.nearestFormat(settings); - logOutput->append(tr("Failed")); - nearestFreq->setText(QString("%1").arg(nearest.frequency())); - nearestChannel->setText(QString("%1").arg(nearest.channels())); - nearestCodec->setText(nearest.codec()); - nearestSampleSize->setText(QString("%1").arg(nearest.sampleSize())); - - switch(nearest.sampleType()) { - case QAudioFormat::SignedInt: - nearestSampleType->setText("SignedInt"); - break; - case QAudioFormat::UnSignedInt: - nearestSampleType->setText("UnSignedInt"); - break; - case QAudioFormat::Float: - nearestSampleType->setText("Float"); - break; - case QAudioFormat::Unknown: - nearestSampleType->setText("Unknown"); - } - switch(nearest.byteOrder()) { - case QAudioFormat::LittleEndian: - nearestEndian->setText("LittleEndian"); - break; - case QAudioFormat::BigEndian: - nearestEndian->setText("BigEndian"); - } - } - } - else - logOutput->append("No Device"); -} - -void AudioTest::modeChanged(int idx) -{ - // mode has changed - if(idx == 0) - mode=QAudio::AudioInput; - else - mode=QAudio::AudioOutput; - - deviceBox->clear(); - foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::deviceList(mode)) - deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo)); -} - -void AudioTest::deviceChanged(int idx) -{ - if (deviceBox->count() == 0) - return; - - // device has changed - deviceInfo = deviceBox->itemData(idx).value(); - - frequencyBox->clear(); - QList freqz = deviceInfo.supportedFrequencies(); - for(int i = 0; i < freqz.size(); ++i) - frequencyBox->addItem(QString("%1").arg(freqz.at(i))); - if(freqz.size()) - settings.setFrequency(freqz.at(0)); - - channelsBox->clear(); - QList chz = deviceInfo.supportedChannels(); - for(int i = 0; i < chz.size(); ++i) - channelsBox->addItem(QString("%1").arg(chz.at(i))); - if(chz.size()) - settings.setChannels(chz.at(0)); - - codecsBox->clear(); - QStringList codecz = deviceInfo.supportedCodecs(); - for(int i = 0; i < codecz.size(); ++i) - codecsBox->addItem(QString("%1").arg(codecz.at(i))); - if(codecz.size()) - settings.setCodec(codecz.at(0)); - // Add false to create failed condition! - codecsBox->addItem("audio/test"); - - sampleSizesBox->clear(); - QList sampleSizez = deviceInfo.supportedSampleSizes(); - for(int i = 0; i < sampleSizez.size(); ++i) - sampleSizesBox->addItem(QString("%1").arg(sampleSizez.at(i))); - if(sampleSizez.size()) - settings.setSampleSize(sampleSizez.at(0)); - - sampleTypesBox->clear(); - QList sampleTypez = deviceInfo.supportedSampleTypes(); - for(int i = 0; i < sampleTypez.size(); ++i) { - switch(sampleTypez.at(i)) { - case QAudioFormat::SignedInt: - sampleTypesBox->addItem("SignedInt"); - break; - case QAudioFormat::UnSignedInt: - sampleTypesBox->addItem("UnSignedInt"); - break; - case QAudioFormat::Float: - sampleTypesBox->addItem("Float"); - break; - case QAudioFormat::Unknown: - sampleTypesBox->addItem("Unknown"); - } - if(sampleTypez.size()) - settings.setSampleType(sampleTypez.at(0)); - } - - endianBox->clear(); - QList endianz = deviceInfo.supportedByteOrders(); - for(int i = 0; i < endianz.size(); ++i) { - switch(endianz.at(i)) { - case QAudioFormat::LittleEndian: - endianBox->addItem("Little Endian"); - break; - case QAudioFormat::BigEndian: - endianBox->addItem("Big Endian"); - break; - } - } - if(endianz.size()) - settings.setByteOrder(endianz.at(0)); -} - -void AudioTest::freqChanged(int idx) -{ - // freq has changed - settings.setFrequency(frequencyBox->itemText(idx).toInt()); -} - -void AudioTest::channelChanged(int idx) -{ - settings.setChannels(channelsBox->itemText(idx).toInt()); -} - -void AudioTest::codecChanged(int idx) -{ - settings.setCodec(codecsBox->itemText(idx)); -} - -void AudioTest::sampleSizeChanged(int idx) -{ - settings.setSampleSize(sampleSizesBox->itemText(idx).toInt()); -} - -void AudioTest::sampleTypeChanged(int idx) -{ - switch(sampleTypesBox->itemText(idx).toInt()) { - case QAudioFormat::SignedInt: - settings.setSampleType(QAudioFormat::SignedInt); - break; - case QAudioFormat::UnSignedInt: - settings.setSampleType(QAudioFormat::UnSignedInt); - break; - case QAudioFormat::Float: - settings.setSampleType(QAudioFormat::Float); - } -} - -void AudioTest::endianChanged(int idx) -{ - switch(endianBox->itemText(idx).toInt()) { - case QAudioFormat::LittleEndian: - settings.setByteOrder(QAudioFormat::LittleEndian); - break; - case QAudioFormat::BigEndian: - settings.setByteOrder(QAudioFormat::BigEndian); - } -} - diff --git a/examples/multimedia/audio/audiodevices/audiodevices.h b/examples/multimedia/audio/audiodevices/audiodevices.h deleted file mode 100644 index 5fe5547..0000000 --- a/examples/multimedia/audio/audiodevices/audiodevices.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include -#include -#include - -#include "ui_audiodevicesbase.h" - -class AudioDevicesBase : public QMainWindow, public Ui::AudioDevicesBase -{ -public: - AudioDevicesBase( QMainWindow *parent = 0, Qt::WFlags f = 0 ); - virtual ~AudioDevicesBase(); -}; - -class AudioTest : public AudioDevicesBase -{ - Q_OBJECT -public: - AudioTest( QMainWindow *parent = 0, Qt::WFlags f = 0 ); - virtual ~AudioTest(); - - QAudioDeviceInfo deviceInfo; - QAudioFormat settings; - QAudio::Mode mode; - -private slots: - void modeChanged(int idx); - void deviceChanged(int idx); - void freqChanged(int idx); - void channelChanged(int idx); - void codecChanged(int idx); - void sampleSizeChanged(int idx); - void sampleTypeChanged(int idx); - void endianChanged(int idx); - void test(); -}; - diff --git a/examples/multimedia/audio/audiodevices/audiodevices.pro b/examples/multimedia/audio/audiodevices/audiodevices.pro deleted file mode 100644 index 173aa8f..0000000 --- a/examples/multimedia/audio/audiodevices/audiodevices.pro +++ /dev/null @@ -1,17 +0,0 @@ -HEADERS = audiodevices.h -SOURCES = audiodevices.cpp \ - main.cpp -FORMS += audiodevicesbase.ui - -QT += multimedia - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audiodevices -sources.files = $$SOURCES *.h $$RESOURCES $$FORMS audiodevices.pro -sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audiodevices -INSTALLS += target sources - -symbian { - TARGET.UID3 = 0xA000D7BE - include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) -} diff --git a/examples/multimedia/audio/audiodevices/audiodevicesbase.ui b/examples/multimedia/audio/audiodevices/audiodevicesbase.ui deleted file mode 100644 index 5207338..0000000 --- a/examples/multimedia/audio/audiodevices/audiodevicesbase.ui +++ /dev/null @@ -1,233 +0,0 @@ - - - AudioDevicesBase - - - - 0 - 0 - 504 - 702 - - - - AudioDevicesBase - - - - - - - - - - 1 - 0 - - - - Device - - - - - - - Mode - - - - - - - - - - - - - QFrame::Panel - - - QFrame::Raised - - - Actual Settings - - - Qt::AlignCenter - - - - - - - QFrame::Panel - - - QFrame::Raised - - - Nearest Settings - - - Qt::AlignCenter - - - - - - - Frequency - - - - - - - Frequency - - - - - - - - - - - - - Channels - - - - - - - Channel - - - - - - - - - - - - - Codecs - - - - - - - Codec - - - - - - - - - - - - - SampleSize - - - - - - - SampleSize - - - - - - - - - - - - - SampleType - - - - - - - SampleType - - - - - - - - - - - - - Endianess - - - - - - - Endianess - - - - - - - - - - - - - - 0 - 40 - - - - - - - - Test - - - - - - - - - - - 0 - 0 - 504 - 19 - - - - - - - - diff --git a/examples/multimedia/audio/audiodevices/main.cpp b/examples/multimedia/audio/audiodevices/main.cpp deleted file mode 100644 index d5ddd4f..0000000 --- a/examples/multimedia/audio/audiodevices/main.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include "audiodevices.h" - -int main(int argv, char **args) -{ - QApplication app(argv, args); - app.setApplicationName("Audio Device Test"); - - AudioTest audio; - audio.show(); - - return app.exec(); -} diff --git a/examples/multimedia/audio/audioinput/audioinput.cpp b/examples/multimedia/audio/audioinput/audioinput.cpp deleted file mode 100644 index 05723ae..0000000 --- a/examples/multimedia/audio/audioinput/audioinput.cpp +++ /dev/null @@ -1,296 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -#include -#include -#include - -#include -#include -#include "audioinput.h" - -#define BUFFER_SIZE 4096 - -AudioInfo::AudioInfo(QObject* parent, QAudioInput* device) - :QIODevice( parent ) -{ - input = device; - - m_maxValue = 0; -} - -AudioInfo::~AudioInfo() -{ -} - -void AudioInfo::start() -{ - open(QIODevice::WriteOnly); -} - -void AudioInfo::stop() -{ - close(); -} - -qint64 AudioInfo::readData(char *data, qint64 maxlen) -{ - Q_UNUSED(data) - Q_UNUSED(maxlen) - - return 0; -} - -qint64 AudioInfo::writeData(const char *data, qint64 len) -{ - int samples = len/2; // 2 bytes per sample - int maxAmp = 32768; // max for S16 samples - bool clipping = false; - - m_maxValue = 0; - - qint16* s = (qint16*)data; - - // sample format is S16LE, only! - - for(int i=0;i m_maxValue) m_maxValue = abs(sample); - } - // check for clipping - if(m_maxValue>=(maxAmp-1)) clipping = true; - - float value = ((float)m_maxValue/(float)maxAmp); - if(clipping) m_maxValue = 100; - else m_maxValue = (int)(value*100); - - emit update(); - - return len; -} - -int AudioInfo::LinearMax() -{ - return m_maxValue; -} - -RenderArea::RenderArea(QWidget *parent) - : QWidget(parent) -{ - setBackgroundRole(QPalette::Base); - setAutoFillBackground(true); - - level = 0; - setMinimumHeight(30); - setMinimumWidth(200); -} - -void RenderArea::paintEvent(QPaintEvent * /* event */) -{ - QPainter painter(this); - - painter.setPen(Qt::black); - painter.drawRect(QRect(painter.viewport().left()+10, painter.viewport().top()+10, - painter.viewport().right()-20, painter.viewport().bottom()-20)); - - if(level == 0) - return; - - painter.setPen(Qt::red); - - int pos = ((painter.viewport().right()-20)-(painter.viewport().left()+11))*level/100; - int x1,y1,x2,y2; - for(int i=0;i<10;i++) { - x1 = painter.viewport().left()+11; - y1 = painter.viewport().top()+10+i; - x2 = painter.viewport().left()+20+pos; - y2 = painter.viewport().top()+10+i; - if(x2 < painter.viewport().left()+10) - x2 = painter.viewport().left()+10; - - painter.drawLine(QPoint(x1,y1),QPoint(x2,y2)); - } -} - -void RenderArea::setLevel(int value) -{ - level = value; - repaint(); -} - - -InputTest::InputTest() -{ - QWidget *window = new QWidget; - QVBoxLayout* layout = new QVBoxLayout; - - canvas = new RenderArea; - layout->addWidget(canvas); - - deviceBox = new QComboBox(this); - QList devices = QAudioDeviceInfo::deviceList(QAudio::AudioInput); - for(int i = 0; i < devices.size(); ++i) { - deviceBox->addItem(devices.at(i).deviceName(), qVariantFromValue(devices.at(i))); - } - connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int))); - layout->addWidget(deviceBox); - - button = new QPushButton(this); - button->setText(tr("Click for Push Mode")); - connect(button,SIGNAL(clicked()),SLOT(toggleMode())); - layout->addWidget(button); - - button2 = new QPushButton(this); - button2->setText(tr("Click To Suspend")); - connect(button2,SIGNAL(clicked()),SLOT(toggleSuspend())); - layout->addWidget(button2); - - window->setLayout(layout); - setCentralWidget(window); - window->show(); - - buffer = new char[BUFFER_SIZE]; - - pullMode = true; - - // AudioInfo class only supports mono S16LE samples! - format.setFrequency(8000); - format.setChannels(1); - format.setSampleSize(16); - format.setSampleType(QAudioFormat::SignedInt); - format.setByteOrder(QAudioFormat::LittleEndian); - format.setCodec("audio/pcm"); - - audioInput = new QAudioInput(format,this); - connect(audioInput,SIGNAL(notify()),SLOT(status())); - connect(audioInput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); - audioinfo = new AudioInfo(this,audioInput); - connect(audioinfo,SIGNAL(update()),SLOT(refreshDisplay())); - audioinfo->start(); - audioInput->start(audioinfo); -} - -InputTest::~InputTest() {} - -void InputTest::status() -{ - qWarning()<<"bytesReady = "<bytesReady()<<" bytes, clock = "<clock()<<"ms, totalTime = "<totalTime()/1000<<"ms"; -} - -void InputTest::readMore() -{ - if(!audioInput) - return; - qint64 len = audioInput->bytesReady(); - if(len > 4096) - len = 4096; - qint64 l = input->read(buffer,len); - if(l > 0) { - audioinfo->write(buffer,l); - } -} - -void InputTest::toggleMode() -{ - // Change bewteen pull and push modes - audioInput->stop(); - - if (pullMode) { - button->setText(tr("Click for Pull Mode")); - input = audioInput->start(0); - connect(input,SIGNAL(readyRead()),SLOT(readMore())); - pullMode = false; - } else { - button->setText(tr("Click for Push Mode")); - pullMode = true; - audioInput->start(audioinfo); - } -} - -void InputTest::toggleSuspend() -{ - // toggle suspend/resume - if(audioInput->state() == QAudio::SuspendState) { - qWarning()<<"status: Suspended, resume()"; - audioInput->resume(); - button2->setText("Click To Suspend"); - } else if (audioInput->state() == QAudio::ActiveState) { - qWarning()<<"status: Active, suspend()"; - audioInput->suspend(); - button2->setText("Click To Resume"); - } else if (audioInput->state() == QAudio::StopState) { - qWarning()<<"status: Stopped, resume()"; - audioInput->resume(); - button2->setText("Click To Suspend"); - } else if (audioInput->state() == QAudio::IdleState) { - qWarning()<<"status: IdleState"; - } -} - -void InputTest::state(QAudio::State state) -{ - qWarning()<<" state="<setLevel(audioinfo->LinearMax()); - canvas->repaint(); -} - -void InputTest::deviceChanged(int idx) -{ - audioinfo->stop(); - audioInput->stop(); - audioInput->disconnect(this); - delete audioInput; - - device = deviceBox->itemData(idx).value(); - audioInput = new QAudioInput(device, format, this); - connect(audioInput,SIGNAL(notify()),SLOT(status())); - connect(audioInput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); - audioinfo->start(); - audioInput->start(audioinfo); -} diff --git a/examples/multimedia/audio/audioinput/audioinput.h b/examples/multimedia/audio/audioinput/audioinput.h deleted file mode 100644 index 14e1bac..0000000 --- a/examples/multimedia/audio/audioinput/audioinput.h +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include -#include - -#include - -class AudioInfo : public QIODevice -{ - Q_OBJECT -public: - AudioInfo(QObject* parent, QAudioInput* device); - ~AudioInfo(); - - void start(); - void stop(); - - int LinearMax(); - - qint64 readData(char *data, qint64 maxlen); - qint64 writeData(const char *data, qint64 len); - - QAudioInput* input; - -private: - int m_maxValue; - -signals: - void update(); -}; - - -class RenderArea : public QWidget -{ - Q_OBJECT - -public: - RenderArea(QWidget *parent = 0); - - void setLevel(int value); - -protected: - void paintEvent(QPaintEvent *event); - -private: - int level; - QPixmap pixmap; -}; - -class InputTest : public QMainWindow -{ - Q_OBJECT -public: - InputTest(); - ~InputTest(); - - QAudioDeviceInfo device; - QAudioFormat format; - QAudioInput* audioInput; - AudioInfo* audioinfo; - QIODevice* input; - RenderArea* canvas; - - bool pullMode; - - QPushButton* button; - QPushButton* button2; - QComboBox* deviceBox; - - char* buffer; - -private slots: - void refreshDisplay(); - void status(); - void readMore(); - void toggleMode(); - void toggleSuspend(); - void state(QAudio::State s); - void deviceChanged(int idx); -}; - diff --git a/examples/multimedia/audio/audioinput/audioinput.pro b/examples/multimedia/audio/audioinput/audioinput.pro deleted file mode 100644 index 0d6198d..0000000 --- a/examples/multimedia/audio/audioinput/audioinput.pro +++ /dev/null @@ -1,16 +0,0 @@ -HEADERS = audioinput.h -SOURCES = audioinput.cpp \ - main.cpp - -QT += multimedia - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audioinput -sources.files = $$SOURCES *.h $$RESOURCES $$FORMS audioinput.pro -sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audioinput -INSTALLS += target sources - -symbian { - TARGET.UID3 = 0xA000D7BF - include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) -} diff --git a/examples/multimedia/audio/audioinput/main.cpp b/examples/multimedia/audio/audioinput/main.cpp deleted file mode 100644 index d7e9c6c..0000000 --- a/examples/multimedia/audio/audioinput/main.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include "audioinput.h" - -int main(int argv, char **args) -{ - QApplication app(argv, args); - app.setApplicationName("Audio Input Test"); - - InputTest input; - input.show(); - - return app.exec(); -} diff --git a/examples/multimedia/audio/audiooutput/audiooutput.cpp b/examples/multimedia/audio/audiooutput/audiooutput.cpp deleted file mode 100644 index 9e532cd..0000000 --- a/examples/multimedia/audio/audiooutput/audiooutput.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -#include -#include -#include "audiooutput.h" - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -#define SECONDS 1 -#define FREQ 600 -#define SYSTEM_FREQ 44100 - -Generator::Generator(QObject *parent) - :QIODevice( parent ) -{ - finished = false; - buffer = new char[SECONDS*SYSTEM_FREQ*4+1000]; - t=buffer; - len=fillData(t,FREQ,SECONDS); /* mono FREQHz sine */ - pos = 0; - total = len; -} - -Generator::~Generator() -{ - delete [] buffer; -} - -void Generator::start() -{ - open(QIODevice::ReadOnly); -} - -void Generator::stop() -{ - close(); -} - -int Generator::putShort(char *t, unsigned int value) -{ - *(unsigned char *)(t++)=value&255; - *(unsigned char *)(t)=(value/256)&255; - return 2; -} - -int Generator::fillData(char *start, int frequency, int seconds) -{ - int i, len=0; - int value; - for(i=0; i 16384) - len = 16384; - - if(len < (SECONDS*SYSTEM_FREQ*2)-pos) { - // Normal - memcpy(data,t+pos,len); - pos+=len; - return len; - } else { - // Whats left and reset to start - qint64 left = (SECONDS*SYSTEM_FREQ*2)-pos; - memcpy(data,t+pos,left); - pos=0; - return left; - } -} - -qint64 Generator::writeData(const char *data, qint64 len) -{ - Q_UNUSED(data); - Q_UNUSED(len); - - return 0; -} - -AudioTest::AudioTest() -{ - QWidget *window = new QWidget; - QVBoxLayout* layout = new QVBoxLayout; - - deviceBox = new QComboBox(this); - foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::deviceList(QAudio::AudioOutput)) - deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo)); - connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int))); - layout->addWidget(deviceBox); - - button = new QPushButton(this); - button->setText(tr("Click for Push Mode")); - connect(button,SIGNAL(clicked()),SLOT(toggle())); - layout->addWidget(button); - - button2 = new QPushButton(this); - button2->setText(tr("Click To Suspend")); - connect(button2,SIGNAL(clicked()),SLOT(togglePlay())); - layout->addWidget(button2); - - window->setLayout(layout); - setCentralWidget(window); - window->show(); - - buffer = new char[BUFFER_SIZE]; - - gen = new Generator(this); - - pullMode = true; - - timer = new QTimer(this); - connect(timer,SIGNAL(timeout()),SLOT(writeMore())); - - gen->start(); - - settings.setFrequency(SYSTEM_FREQ); - settings.setChannels(1); - settings.setSampleSize(16); - settings.setCodec("audio/pcm"); - settings.setByteOrder(QAudioFormat::LittleEndian); - settings.setSampleType(QAudioFormat::SignedInt); - audioOutput = new QAudioOutput(settings,this); - connect(audioOutput,SIGNAL(notify()),SLOT(status())); - connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); - - audioOutput->start(gen); -} - -AudioTest::~AudioTest() -{ - delete [] buffer; -} - -void AudioTest::deviceChanged(int idx) -{ - timer->stop(); - gen->stop(); - audioOutput->stop(); - audioOutput->disconnect(this); - delete audioOutput; - - device = deviceBox->itemData(idx).value(); - audioOutput = new QAudioOutput(device,settings,this); - connect(audioOutput,SIGNAL(notify()),SLOT(status())); - connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); - gen->start(); - audioOutput->start(gen); -} - -void AudioTest::status() -{ - qWarning()<<"byteFree = "<bytesFree()<<" bytes, clock = "<clock()<<"ms, totalTime = "<totalTime()/1000<<"ms"; -} - -void AudioTest::writeMore() -{ - if(!audioOutput) - return; - - if(audioOutput->state() == QAudio::StopState) - return; - - int l; - int out; - - int chunks = audioOutput->bytesFree()/audioOutput->periodSize(); - while(chunks) { - l = gen->read(buffer,audioOutput->periodSize()); - if(l > 0) - out = output->write(buffer,l); - if(l != audioOutput->periodSize()) - break; - chunks--; - } -} - -void AudioTest::toggle() -{ - // Change between pull and push modes - - timer->stop(); - audioOutput->stop(); - - if (pullMode) { - button->setText("Click for Pull Mode"); - output = audioOutput->start(0); - pullMode = false; - timer->start(20); - } else { - button->setText("Click for Push Mode"); - pullMode = true; - audioOutput->start(gen); - } -} - -void AudioTest::togglePlay() -{ - // toggle suspend/resume - if(audioOutput->state() == QAudio::SuspendState) { - qWarning()<<"status: Suspended, resume()"; - audioOutput->resume(); - button2->setText("Click To Suspend"); - } else if (audioOutput->state() == QAudio::ActiveState) { - qWarning()<<"status: Active, suspend()"; - audioOutput->suspend(); - button2->setText("Click To Resume"); - } else if (audioOutput->state() == QAudio::StopState) { - qWarning()<<"status: Stopped, resume()"; - audioOutput->resume(); - button2->setText("Click To Suspend"); - } else if (audioOutput->state() == QAudio::IdleState) { - qWarning()<<"status: IdleState"; - } -} - -void AudioTest::state(QAudio::State state) -{ - qWarning()<<" state="< - -#define BUFFER_SIZE 32768 - -#include -#include -#include -#include -#include -#include - -#include - -class Generator : public QIODevice -{ - Q_OBJECT -public: - Generator(QObject *parent); - ~Generator(); - - void start(); - void stop(); - - char *t; - int len; - int pos; - int total; - char *buffer; - bool finished; - int chunk_size; - - qint64 readData(char *data, qint64 maxlen); - qint64 writeData(const char *data, qint64 len); - -private: - int putShort(char *t, unsigned int value); - int fillData(char *start, int frequency, int seconds); -}; - -class AudioTest : public QMainWindow -{ - Q_OBJECT -public: - AudioTest(); - ~AudioTest(); - - QAudioDeviceInfo device; - Generator* gen; - QAudioOutput* audioOutput; - QIODevice* output; - QTimer* timer; - QAudioFormat settings; - - bool pullMode; - char* buffer; - - QPushButton* button; - QPushButton* button2; - QComboBox* deviceBox; - -private slots: - void status(); - void writeMore(); - void toggle(); - void togglePlay(); - void state(QAudio::State s); - void deviceChanged(int idx); -}; - diff --git a/examples/multimedia/audio/audiooutput/audiooutput.pro b/examples/multimedia/audio/audiooutput/audiooutput.pro deleted file mode 100644 index b43763c..0000000 --- a/examples/multimedia/audio/audiooutput/audiooutput.pro +++ /dev/null @@ -1,16 +0,0 @@ -HEADERS = audiooutput.h -SOURCES = audiooutput.cpp \ - main.cpp - -QT += multimedia - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audiooutput -sources.files = $$SOURCES *.h $$RESOURCES $$FORMS audiooutput.pro -sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audiooutput -INSTALLS += target sources - -symbian { - TARGET.UID3 = 0xA000D7C0 - include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) -} diff --git a/examples/multimedia/audio/audiooutput/main.cpp b/examples/multimedia/audio/audiooutput/main.cpp deleted file mode 100644 index 79ec99e..0000000 --- a/examples/multimedia/audio/audiooutput/main.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include - -#include "audiooutput.h" - -int main(int argv, char **args) -{ - QApplication app(argv, args); - app.setApplicationName("Audio Output Test"); - - AudioTest audio; - audio.show(); - - return app.exec(); -} diff --git a/examples/multimedia/audiodevices/audiodevices.cpp b/examples/multimedia/audiodevices/audiodevices.cpp new file mode 100644 index 0000000..4198605 --- /dev/null +++ b/examples/multimedia/audiodevices/audiodevices.cpp @@ -0,0 +1,274 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include + +#include "audiodevices.h" + +AudioDevicesBase::AudioDevicesBase( QMainWindow *parent, Qt::WFlags f ) +{ + Q_UNUSED(parent) + Q_UNUSED(f) + setupUi( this ); +} + +AudioDevicesBase::~AudioDevicesBase() {} + + +AudioTest::AudioTest( QMainWindow *parent, Qt::WFlags f ) + : AudioDevicesBase( parent, f ) +{ + nearestFreq->setDisabled(true); + nearestChannel->setDisabled(true); + nearestCodec->setDisabled(true); + nearestSampleSize->setDisabled(true); + nearestSampleType->setDisabled(true); + nearestEndian->setDisabled(true); + logOutput->setDisabled(true); + + mode = QAudio::AudioOutput; + modeBox->addItem("Input"); + modeBox->addItem("Output"); + + connect(testButton,SIGNAL(clicked()),SLOT(test())); + connect(modeBox,SIGNAL(activated(int)),SLOT(modeChanged(int))); + connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int))); + connect(frequencyBox,SIGNAL(activated(int)),SLOT(freqChanged(int))); + connect(channelsBox,SIGNAL(activated(int)),SLOT(channelChanged(int))); + connect(codecsBox,SIGNAL(activated(int)),SLOT(codecChanged(int))); + connect(sampleSizesBox,SIGNAL(activated(int)),SLOT(sampleSizeChanged(int))); + connect(sampleTypesBox,SIGNAL(activated(int)),SLOT(sampleTypeChanged(int))); + connect(endianBox,SIGNAL(activated(int)),SLOT(endianChanged(int))); + + modeBox->setCurrentIndex(0); + modeChanged(0); + deviceBox->setCurrentIndex(0); + deviceChanged(0); +} + +AudioTest::~AudioTest() +{ +} + +void AudioTest::test() +{ + // tries to set all the settings picked. + logOutput->clear(); + logOutput->append("NOTE: an invalid codec audio/test exists for testing, to get a fail condition."); + + if (!deviceInfo.isNull()) { + if (deviceInfo.isFormatSupported(settings)) { + logOutput->append("Success"); + nearestFreq->setText(""); + nearestChannel->setText(""); + nearestCodec->setText(""); + nearestSampleSize->setText(""); + nearestSampleType->setText(""); + nearestEndian->setText(""); + } else { + QAudioFormat nearest = deviceInfo.nearestFormat(settings); + logOutput->append(tr("Failed")); + nearestFreq->setText(QString("%1").arg(nearest.frequency())); + nearestChannel->setText(QString("%1").arg(nearest.channels())); + nearestCodec->setText(nearest.codec()); + nearestSampleSize->setText(QString("%1").arg(nearest.sampleSize())); + + switch(nearest.sampleType()) { + case QAudioFormat::SignedInt: + nearestSampleType->setText("SignedInt"); + break; + case QAudioFormat::UnSignedInt: + nearestSampleType->setText("UnSignedInt"); + break; + case QAudioFormat::Float: + nearestSampleType->setText("Float"); + break; + case QAudioFormat::Unknown: + nearestSampleType->setText("Unknown"); + } + switch(nearest.byteOrder()) { + case QAudioFormat::LittleEndian: + nearestEndian->setText("LittleEndian"); + break; + case QAudioFormat::BigEndian: + nearestEndian->setText("BigEndian"); + } + } + } + else + logOutput->append("No Device"); +} + +void AudioTest::modeChanged(int idx) +{ + // mode has changed + if(idx == 0) + mode=QAudio::AudioInput; + else + mode=QAudio::AudioOutput; + + deviceBox->clear(); + foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::deviceList(mode)) + deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo)); +} + +void AudioTest::deviceChanged(int idx) +{ + if (deviceBox->count() == 0) + return; + + // device has changed + deviceInfo = deviceBox->itemData(idx).value(); + + frequencyBox->clear(); + QList freqz = deviceInfo.supportedFrequencies(); + for(int i = 0; i < freqz.size(); ++i) + frequencyBox->addItem(QString("%1").arg(freqz.at(i))); + if(freqz.size()) + settings.setFrequency(freqz.at(0)); + + channelsBox->clear(); + QList chz = deviceInfo.supportedChannels(); + for(int i = 0; i < chz.size(); ++i) + channelsBox->addItem(QString("%1").arg(chz.at(i))); + if(chz.size()) + settings.setChannels(chz.at(0)); + + codecsBox->clear(); + QStringList codecz = deviceInfo.supportedCodecs(); + for(int i = 0; i < codecz.size(); ++i) + codecsBox->addItem(QString("%1").arg(codecz.at(i))); + if(codecz.size()) + settings.setCodec(codecz.at(0)); + // Add false to create failed condition! + codecsBox->addItem("audio/test"); + + sampleSizesBox->clear(); + QList sampleSizez = deviceInfo.supportedSampleSizes(); + for(int i = 0; i < sampleSizez.size(); ++i) + sampleSizesBox->addItem(QString("%1").arg(sampleSizez.at(i))); + if(sampleSizez.size()) + settings.setSampleSize(sampleSizez.at(0)); + + sampleTypesBox->clear(); + QList sampleTypez = deviceInfo.supportedSampleTypes(); + for(int i = 0; i < sampleTypez.size(); ++i) { + switch(sampleTypez.at(i)) { + case QAudioFormat::SignedInt: + sampleTypesBox->addItem("SignedInt"); + break; + case QAudioFormat::UnSignedInt: + sampleTypesBox->addItem("UnSignedInt"); + break; + case QAudioFormat::Float: + sampleTypesBox->addItem("Float"); + break; + case QAudioFormat::Unknown: + sampleTypesBox->addItem("Unknown"); + } + if(sampleTypez.size()) + settings.setSampleType(sampleTypez.at(0)); + } + + endianBox->clear(); + QList endianz = deviceInfo.supportedByteOrders(); + for(int i = 0; i < endianz.size(); ++i) { + switch(endianz.at(i)) { + case QAudioFormat::LittleEndian: + endianBox->addItem("Little Endian"); + break; + case QAudioFormat::BigEndian: + endianBox->addItem("Big Endian"); + break; + } + } + if(endianz.size()) + settings.setByteOrder(endianz.at(0)); +} + +void AudioTest::freqChanged(int idx) +{ + // freq has changed + settings.setFrequency(frequencyBox->itemText(idx).toInt()); +} + +void AudioTest::channelChanged(int idx) +{ + settings.setChannels(channelsBox->itemText(idx).toInt()); +} + +void AudioTest::codecChanged(int idx) +{ + settings.setCodec(codecsBox->itemText(idx)); +} + +void AudioTest::sampleSizeChanged(int idx) +{ + settings.setSampleSize(sampleSizesBox->itemText(idx).toInt()); +} + +void AudioTest::sampleTypeChanged(int idx) +{ + switch(sampleTypesBox->itemText(idx).toInt()) { + case QAudioFormat::SignedInt: + settings.setSampleType(QAudioFormat::SignedInt); + break; + case QAudioFormat::UnSignedInt: + settings.setSampleType(QAudioFormat::UnSignedInt); + break; + case QAudioFormat::Float: + settings.setSampleType(QAudioFormat::Float); + } +} + +void AudioTest::endianChanged(int idx) +{ + switch(endianBox->itemText(idx).toInt()) { + case QAudioFormat::LittleEndian: + settings.setByteOrder(QAudioFormat::LittleEndian); + break; + case QAudioFormat::BigEndian: + settings.setByteOrder(QAudioFormat::BigEndian); + } +} + diff --git a/examples/multimedia/audiodevices/audiodevices.h b/examples/multimedia/audiodevices/audiodevices.h new file mode 100644 index 0000000..5fe5547 --- /dev/null +++ b/examples/multimedia/audiodevices/audiodevices.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include +#include + +#include "ui_audiodevicesbase.h" + +class AudioDevicesBase : public QMainWindow, public Ui::AudioDevicesBase +{ +public: + AudioDevicesBase( QMainWindow *parent = 0, Qt::WFlags f = 0 ); + virtual ~AudioDevicesBase(); +}; + +class AudioTest : public AudioDevicesBase +{ + Q_OBJECT +public: + AudioTest( QMainWindow *parent = 0, Qt::WFlags f = 0 ); + virtual ~AudioTest(); + + QAudioDeviceInfo deviceInfo; + QAudioFormat settings; + QAudio::Mode mode; + +private slots: + void modeChanged(int idx); + void deviceChanged(int idx); + void freqChanged(int idx); + void channelChanged(int idx); + void codecChanged(int idx); + void sampleSizeChanged(int idx); + void sampleTypeChanged(int idx); + void endianChanged(int idx); + void test(); +}; + diff --git a/examples/multimedia/audiodevices/audiodevices.pro b/examples/multimedia/audiodevices/audiodevices.pro new file mode 100644 index 0000000..232da09 --- /dev/null +++ b/examples/multimedia/audiodevices/audiodevices.pro @@ -0,0 +1,17 @@ +HEADERS = audiodevices.h +SOURCES = audiodevices.cpp \ + main.cpp +FORMS += audiodevicesbase.ui + +QT += multimedia + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audiodevices +sources.files = $$SOURCES *.h $$RESOURCES $$FORMS audiodevices.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audiodevices +INSTALLS += target sources + +symbian { + TARGET.UID3 = 0xA000D7BE + include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +} diff --git a/examples/multimedia/audiodevices/audiodevicesbase.ui b/examples/multimedia/audiodevices/audiodevicesbase.ui new file mode 100644 index 0000000..5207338 --- /dev/null +++ b/examples/multimedia/audiodevices/audiodevicesbase.ui @@ -0,0 +1,233 @@ + + + AudioDevicesBase + + + + 0 + 0 + 504 + 702 + + + + AudioDevicesBase + + + + + + + + + + 1 + 0 + + + + Device + + + + + + + Mode + + + + + + + + + + + + + QFrame::Panel + + + QFrame::Raised + + + Actual Settings + + + Qt::AlignCenter + + + + + + + QFrame::Panel + + + QFrame::Raised + + + Nearest Settings + + + Qt::AlignCenter + + + + + + + Frequency + + + + + + + Frequency + + + + + + + + + + + + + Channels + + + + + + + Channel + + + + + + + + + + + + + Codecs + + + + + + + Codec + + + + + + + + + + + + + SampleSize + + + + + + + SampleSize + + + + + + + + + + + + + SampleType + + + + + + + SampleType + + + + + + + + + + + + + Endianess + + + + + + + Endianess + + + + + + + + + + + + + + 0 + 40 + + + + + + + + Test + + + + + + + + + + + 0 + 0 + 504 + 19 + + + + + + + + diff --git a/examples/multimedia/audiodevices/main.cpp b/examples/multimedia/audiodevices/main.cpp new file mode 100644 index 0000000..d5ddd4f --- /dev/null +++ b/examples/multimedia/audiodevices/main.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "audiodevices.h" + +int main(int argv, char **args) +{ + QApplication app(argv, args); + app.setApplicationName("Audio Device Test"); + + AudioTest audio; + audio.show(); + + return app.exec(); +} diff --git a/examples/multimedia/audioinput/audioinput.cpp b/examples/multimedia/audioinput/audioinput.cpp new file mode 100644 index 0000000..05723ae --- /dev/null +++ b/examples/multimedia/audioinput/audioinput.cpp @@ -0,0 +1,296 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include +#include +#include + +#include +#include +#include "audioinput.h" + +#define BUFFER_SIZE 4096 + +AudioInfo::AudioInfo(QObject* parent, QAudioInput* device) + :QIODevice( parent ) +{ + input = device; + + m_maxValue = 0; +} + +AudioInfo::~AudioInfo() +{ +} + +void AudioInfo::start() +{ + open(QIODevice::WriteOnly); +} + +void AudioInfo::stop() +{ + close(); +} + +qint64 AudioInfo::readData(char *data, qint64 maxlen) +{ + Q_UNUSED(data) + Q_UNUSED(maxlen) + + return 0; +} + +qint64 AudioInfo::writeData(const char *data, qint64 len) +{ + int samples = len/2; // 2 bytes per sample + int maxAmp = 32768; // max for S16 samples + bool clipping = false; + + m_maxValue = 0; + + qint16* s = (qint16*)data; + + // sample format is S16LE, only! + + for(int i=0;i m_maxValue) m_maxValue = abs(sample); + } + // check for clipping + if(m_maxValue>=(maxAmp-1)) clipping = true; + + float value = ((float)m_maxValue/(float)maxAmp); + if(clipping) m_maxValue = 100; + else m_maxValue = (int)(value*100); + + emit update(); + + return len; +} + +int AudioInfo::LinearMax() +{ + return m_maxValue; +} + +RenderArea::RenderArea(QWidget *parent) + : QWidget(parent) +{ + setBackgroundRole(QPalette::Base); + setAutoFillBackground(true); + + level = 0; + setMinimumHeight(30); + setMinimumWidth(200); +} + +void RenderArea::paintEvent(QPaintEvent * /* event */) +{ + QPainter painter(this); + + painter.setPen(Qt::black); + painter.drawRect(QRect(painter.viewport().left()+10, painter.viewport().top()+10, + painter.viewport().right()-20, painter.viewport().bottom()-20)); + + if(level == 0) + return; + + painter.setPen(Qt::red); + + int pos = ((painter.viewport().right()-20)-(painter.viewport().left()+11))*level/100; + int x1,y1,x2,y2; + for(int i=0;i<10;i++) { + x1 = painter.viewport().left()+11; + y1 = painter.viewport().top()+10+i; + x2 = painter.viewport().left()+20+pos; + y2 = painter.viewport().top()+10+i; + if(x2 < painter.viewport().left()+10) + x2 = painter.viewport().left()+10; + + painter.drawLine(QPoint(x1,y1),QPoint(x2,y2)); + } +} + +void RenderArea::setLevel(int value) +{ + level = value; + repaint(); +} + + +InputTest::InputTest() +{ + QWidget *window = new QWidget; + QVBoxLayout* layout = new QVBoxLayout; + + canvas = new RenderArea; + layout->addWidget(canvas); + + deviceBox = new QComboBox(this); + QList devices = QAudioDeviceInfo::deviceList(QAudio::AudioInput); + for(int i = 0; i < devices.size(); ++i) { + deviceBox->addItem(devices.at(i).deviceName(), qVariantFromValue(devices.at(i))); + } + connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int))); + layout->addWidget(deviceBox); + + button = new QPushButton(this); + button->setText(tr("Click for Push Mode")); + connect(button,SIGNAL(clicked()),SLOT(toggleMode())); + layout->addWidget(button); + + button2 = new QPushButton(this); + button2->setText(tr("Click To Suspend")); + connect(button2,SIGNAL(clicked()),SLOT(toggleSuspend())); + layout->addWidget(button2); + + window->setLayout(layout); + setCentralWidget(window); + window->show(); + + buffer = new char[BUFFER_SIZE]; + + pullMode = true; + + // AudioInfo class only supports mono S16LE samples! + format.setFrequency(8000); + format.setChannels(1); + format.setSampleSize(16); + format.setSampleType(QAudioFormat::SignedInt); + format.setByteOrder(QAudioFormat::LittleEndian); + format.setCodec("audio/pcm"); + + audioInput = new QAudioInput(format,this); + connect(audioInput,SIGNAL(notify()),SLOT(status())); + connect(audioInput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); + audioinfo = new AudioInfo(this,audioInput); + connect(audioinfo,SIGNAL(update()),SLOT(refreshDisplay())); + audioinfo->start(); + audioInput->start(audioinfo); +} + +InputTest::~InputTest() {} + +void InputTest::status() +{ + qWarning()<<"bytesReady = "<bytesReady()<<" bytes, clock = "<clock()<<"ms, totalTime = "<totalTime()/1000<<"ms"; +} + +void InputTest::readMore() +{ + if(!audioInput) + return; + qint64 len = audioInput->bytesReady(); + if(len > 4096) + len = 4096; + qint64 l = input->read(buffer,len); + if(l > 0) { + audioinfo->write(buffer,l); + } +} + +void InputTest::toggleMode() +{ + // Change bewteen pull and push modes + audioInput->stop(); + + if (pullMode) { + button->setText(tr("Click for Pull Mode")); + input = audioInput->start(0); + connect(input,SIGNAL(readyRead()),SLOT(readMore())); + pullMode = false; + } else { + button->setText(tr("Click for Push Mode")); + pullMode = true; + audioInput->start(audioinfo); + } +} + +void InputTest::toggleSuspend() +{ + // toggle suspend/resume + if(audioInput->state() == QAudio::SuspendState) { + qWarning()<<"status: Suspended, resume()"; + audioInput->resume(); + button2->setText("Click To Suspend"); + } else if (audioInput->state() == QAudio::ActiveState) { + qWarning()<<"status: Active, suspend()"; + audioInput->suspend(); + button2->setText("Click To Resume"); + } else if (audioInput->state() == QAudio::StopState) { + qWarning()<<"status: Stopped, resume()"; + audioInput->resume(); + button2->setText("Click To Suspend"); + } else if (audioInput->state() == QAudio::IdleState) { + qWarning()<<"status: IdleState"; + } +} + +void InputTest::state(QAudio::State state) +{ + qWarning()<<" state="<setLevel(audioinfo->LinearMax()); + canvas->repaint(); +} + +void InputTest::deviceChanged(int idx) +{ + audioinfo->stop(); + audioInput->stop(); + audioInput->disconnect(this); + delete audioInput; + + device = deviceBox->itemData(idx).value(); + audioInput = new QAudioInput(device, format, this); + connect(audioInput,SIGNAL(notify()),SLOT(status())); + connect(audioInput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); + audioinfo->start(); + audioInput->start(audioinfo); +} diff --git a/examples/multimedia/audioinput/audioinput.h b/examples/multimedia/audioinput/audioinput.h new file mode 100644 index 0000000..14e1bac --- /dev/null +++ b/examples/multimedia/audioinput/audioinput.h @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include + +class AudioInfo : public QIODevice +{ + Q_OBJECT +public: + AudioInfo(QObject* parent, QAudioInput* device); + ~AudioInfo(); + + void start(); + void stop(); + + int LinearMax(); + + qint64 readData(char *data, qint64 maxlen); + qint64 writeData(const char *data, qint64 len); + + QAudioInput* input; + +private: + int m_maxValue; + +signals: + void update(); +}; + + +class RenderArea : public QWidget +{ + Q_OBJECT + +public: + RenderArea(QWidget *parent = 0); + + void setLevel(int value); + +protected: + void paintEvent(QPaintEvent *event); + +private: + int level; + QPixmap pixmap; +}; + +class InputTest : public QMainWindow +{ + Q_OBJECT +public: + InputTest(); + ~InputTest(); + + QAudioDeviceInfo device; + QAudioFormat format; + QAudioInput* audioInput; + AudioInfo* audioinfo; + QIODevice* input; + RenderArea* canvas; + + bool pullMode; + + QPushButton* button; + QPushButton* button2; + QComboBox* deviceBox; + + char* buffer; + +private slots: + void refreshDisplay(); + void status(); + void readMore(); + void toggleMode(); + void toggleSuspend(); + void state(QAudio::State s); + void deviceChanged(int idx); +}; + diff --git a/examples/multimedia/audioinput/audioinput.pro b/examples/multimedia/audioinput/audioinput.pro new file mode 100644 index 0000000..a54d452 --- /dev/null +++ b/examples/multimedia/audioinput/audioinput.pro @@ -0,0 +1,16 @@ +HEADERS = audioinput.h +SOURCES = audioinput.cpp \ + main.cpp + +QT += multimedia + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audioinput +sources.files = $$SOURCES *.h $$RESOURCES $$FORMS audioinput.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audioinput +INSTALLS += target sources + +symbian { + TARGET.UID3 = 0xA000D7BF + include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +} diff --git a/examples/multimedia/audioinput/main.cpp b/examples/multimedia/audioinput/main.cpp new file mode 100644 index 0000000..d7e9c6c --- /dev/null +++ b/examples/multimedia/audioinput/main.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "audioinput.h" + +int main(int argv, char **args) +{ + QApplication app(argv, args); + app.setApplicationName("Audio Input Test"); + + InputTest input; + input.show(); + + return app.exec(); +} diff --git a/examples/multimedia/audiooutput/audiooutput.cpp b/examples/multimedia/audiooutput/audiooutput.cpp new file mode 100644 index 0000000..9e532cd --- /dev/null +++ b/examples/multimedia/audiooutput/audiooutput.cpp @@ -0,0 +1,270 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include +#include +#include "audiooutput.h" + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#define SECONDS 1 +#define FREQ 600 +#define SYSTEM_FREQ 44100 + +Generator::Generator(QObject *parent) + :QIODevice( parent ) +{ + finished = false; + buffer = new char[SECONDS*SYSTEM_FREQ*4+1000]; + t=buffer; + len=fillData(t,FREQ,SECONDS); /* mono FREQHz sine */ + pos = 0; + total = len; +} + +Generator::~Generator() +{ + delete [] buffer; +} + +void Generator::start() +{ + open(QIODevice::ReadOnly); +} + +void Generator::stop() +{ + close(); +} + +int Generator::putShort(char *t, unsigned int value) +{ + *(unsigned char *)(t++)=value&255; + *(unsigned char *)(t)=(value/256)&255; + return 2; +} + +int Generator::fillData(char *start, int frequency, int seconds) +{ + int i, len=0; + int value; + for(i=0; i 16384) + len = 16384; + + if(len < (SECONDS*SYSTEM_FREQ*2)-pos) { + // Normal + memcpy(data,t+pos,len); + pos+=len; + return len; + } else { + // Whats left and reset to start + qint64 left = (SECONDS*SYSTEM_FREQ*2)-pos; + memcpy(data,t+pos,left); + pos=0; + return left; + } +} + +qint64 Generator::writeData(const char *data, qint64 len) +{ + Q_UNUSED(data); + Q_UNUSED(len); + + return 0; +} + +AudioTest::AudioTest() +{ + QWidget *window = new QWidget; + QVBoxLayout* layout = new QVBoxLayout; + + deviceBox = new QComboBox(this); + foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::deviceList(QAudio::AudioOutput)) + deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo)); + connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int))); + layout->addWidget(deviceBox); + + button = new QPushButton(this); + button->setText(tr("Click for Push Mode")); + connect(button,SIGNAL(clicked()),SLOT(toggle())); + layout->addWidget(button); + + button2 = new QPushButton(this); + button2->setText(tr("Click To Suspend")); + connect(button2,SIGNAL(clicked()),SLOT(togglePlay())); + layout->addWidget(button2); + + window->setLayout(layout); + setCentralWidget(window); + window->show(); + + buffer = new char[BUFFER_SIZE]; + + gen = new Generator(this); + + pullMode = true; + + timer = new QTimer(this); + connect(timer,SIGNAL(timeout()),SLOT(writeMore())); + + gen->start(); + + settings.setFrequency(SYSTEM_FREQ); + settings.setChannels(1); + settings.setSampleSize(16); + settings.setCodec("audio/pcm"); + settings.setByteOrder(QAudioFormat::LittleEndian); + settings.setSampleType(QAudioFormat::SignedInt); + audioOutput = new QAudioOutput(settings,this); + connect(audioOutput,SIGNAL(notify()),SLOT(status())); + connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); + + audioOutput->start(gen); +} + +AudioTest::~AudioTest() +{ + delete [] buffer; +} + +void AudioTest::deviceChanged(int idx) +{ + timer->stop(); + gen->stop(); + audioOutput->stop(); + audioOutput->disconnect(this); + delete audioOutput; + + device = deviceBox->itemData(idx).value(); + audioOutput = new QAudioOutput(device,settings,this); + connect(audioOutput,SIGNAL(notify()),SLOT(status())); + connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); + gen->start(); + audioOutput->start(gen); +} + +void AudioTest::status() +{ + qWarning()<<"byteFree = "<bytesFree()<<" bytes, clock = "<clock()<<"ms, totalTime = "<totalTime()/1000<<"ms"; +} + +void AudioTest::writeMore() +{ + if(!audioOutput) + return; + + if(audioOutput->state() == QAudio::StopState) + return; + + int l; + int out; + + int chunks = audioOutput->bytesFree()/audioOutput->periodSize(); + while(chunks) { + l = gen->read(buffer,audioOutput->periodSize()); + if(l > 0) + out = output->write(buffer,l); + if(l != audioOutput->periodSize()) + break; + chunks--; + } +} + +void AudioTest::toggle() +{ + // Change between pull and push modes + + timer->stop(); + audioOutput->stop(); + + if (pullMode) { + button->setText("Click for Pull Mode"); + output = audioOutput->start(0); + pullMode = false; + timer->start(20); + } else { + button->setText("Click for Push Mode"); + pullMode = true; + audioOutput->start(gen); + } +} + +void AudioTest::togglePlay() +{ + // toggle suspend/resume + if(audioOutput->state() == QAudio::SuspendState) { + qWarning()<<"status: Suspended, resume()"; + audioOutput->resume(); + button2->setText("Click To Suspend"); + } else if (audioOutput->state() == QAudio::ActiveState) { + qWarning()<<"status: Active, suspend()"; + audioOutput->suspend(); + button2->setText("Click To Resume"); + } else if (audioOutput->state() == QAudio::StopState) { + qWarning()<<"status: Stopped, resume()"; + audioOutput->resume(); + button2->setText("Click To Suspend"); + } else if (audioOutput->state() == QAudio::IdleState) { + qWarning()<<"status: IdleState"; + } +} + +void AudioTest::state(QAudio::State state) +{ + qWarning()<<" state="< + +#define BUFFER_SIZE 32768 + +#include +#include +#include +#include +#include +#include + +#include + +class Generator : public QIODevice +{ + Q_OBJECT +public: + Generator(QObject *parent); + ~Generator(); + + void start(); + void stop(); + + char *t; + int len; + int pos; + int total; + char *buffer; + bool finished; + int chunk_size; + + qint64 readData(char *data, qint64 maxlen); + qint64 writeData(const char *data, qint64 len); + +private: + int putShort(char *t, unsigned int value); + int fillData(char *start, int frequency, int seconds); +}; + +class AudioTest : public QMainWindow +{ + Q_OBJECT +public: + AudioTest(); + ~AudioTest(); + + QAudioDeviceInfo device; + Generator* gen; + QAudioOutput* audioOutput; + QIODevice* output; + QTimer* timer; + QAudioFormat settings; + + bool pullMode; + char* buffer; + + QPushButton* button; + QPushButton* button2; + QComboBox* deviceBox; + +private slots: + void status(); + void writeMore(); + void toggle(); + void togglePlay(); + void state(QAudio::State s); + void deviceChanged(int idx); +}; + diff --git a/examples/multimedia/audiooutput/audiooutput.pro b/examples/multimedia/audiooutput/audiooutput.pro new file mode 100644 index 0000000..26f68fe --- /dev/null +++ b/examples/multimedia/audiooutput/audiooutput.pro @@ -0,0 +1,16 @@ +HEADERS = audiooutput.h +SOURCES = audiooutput.cpp \ + main.cpp + +QT += multimedia + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audiooutput +sources.files = $$SOURCES *.h $$RESOURCES $$FORMS audiooutput.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audiooutput +INSTALLS += target sources + +symbian { + TARGET.UID3 = 0xA000D7C0 + include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +} diff --git a/examples/multimedia/audiooutput/main.cpp b/examples/multimedia/audiooutput/main.cpp new file mode 100644 index 0000000..79ec99e --- /dev/null +++ b/examples/multimedia/audiooutput/main.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include + +#include "audiooutput.h" + +int main(int argv, char **args) +{ + QApplication app(argv, args); + app.setApplicationName("Audio Output Test"); + + AudioTest audio; + audio.show(); + + return app.exec(); +} diff --git a/examples/multimedia/multimedia.pro b/examples/multimedia/multimedia.pro index ac78b15..4a764f2 100644 --- a/examples/multimedia/multimedia.pro +++ b/examples/multimedia/multimedia.pro @@ -1,5 +1,15 @@ -TEMPLATE = subdirs -SUBDIRS = audio +TEMPLATE = subdirs + +!static { + SUBDIRS += \ + audiodevices \ + audioinput \ + audiooutput +} + +SUBDIRS += \ + videographicsitem \ + videowidget # install target.path = $$[QT_INSTALL_EXAMPLES]/multimedia diff --git a/examples/multimedia/videographicsitem/main.cpp b/examples/multimedia/videographicsitem/main.cpp new file mode 100644 index 0000000..3bf4c6d --- /dev/null +++ b/examples/multimedia/videographicsitem/main.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "videoplayer.h" + +#include + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + VideoPlayer player; + player.show(); + + return app.exec(); +} + diff --git a/examples/multimedia/videographicsitem/videographicsitem.pro b/examples/multimedia/videographicsitem/videographicsitem.pro new file mode 100644 index 0000000..7c118cc --- /dev/null +++ b/examples/multimedia/videographicsitem/videographicsitem.pro @@ -0,0 +1,21 @@ +QT += multimedia + +contains(QT_CONFIG, opengl): QT += opengl + +HEADERS += videoplayer.h \ + videoitem.h + +SOURCES += main.cpp \ + videoplayer.cpp \ + videoitem.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/videographicsitem +sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png images +sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/videographicsitem +INSTALLS += target sources + +symbian { + TARGET.UID3 = 0xA000D7C2 + include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +} diff --git a/examples/multimedia/videographicsitem/videoitem.cpp b/examples/multimedia/videographicsitem/videoitem.cpp new file mode 100644 index 0000000..c95e335 --- /dev/null +++ b/examples/multimedia/videographicsitem/videoitem.cpp @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "videoitem.h" + +#include + +VideoItem::VideoItem(QGraphicsItem *parent) + : QGraphicsItem(parent) + , imageFormat(QImage::Format_Invalid) + , framePainted(false) +{ +} + +VideoItem::~VideoItem() +{ +} + +QRectF VideoItem::boundingRect() const +{ + return QRectF(QPointF(0,0), surfaceFormat().sizeHint()); +} + +void VideoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option); + Q_UNUSED(widget); + + if (currentFrame.map(QAbstractVideoBuffer::ReadOnly)) { + const QTransform oldTransform = painter->transform(); + + if (surfaceFormat().scanLineDirection() == QVideoSurfaceFormat::BottomToTop) { + painter->scale(1, -1); + painter->translate(0, -boundingRect().height()); + } + + painter->drawImage(boundingRect(), QImage( + currentFrame.bits(), + imageSize.width(), + imageSize.height(), + imageFormat)); + + painter->setTransform(oldTransform); + + framePainted = true; + + currentFrame.unmap(); + } +} + +QList VideoItem::supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType) const +{ + if (handleType == QAbstractVideoBuffer::NoHandle) { + return QList() + << QVideoFrame::Format_RGB32 + << QVideoFrame::Format_ARGB32 + << QVideoFrame::Format_ARGB32_Premultiplied + << QVideoFrame::Format_RGB565 + << QVideoFrame::Format_RGB555; + } else { + return QList(); + } +} + +bool VideoItem::start(const QVideoSurfaceFormat &format) +{ + if (isFormatSupported(format)) { + imageFormat = QVideoFrame::equivalentImageFormat(format.pixelFormat()); + imageSize = format.frameSize(); + framePainted = true; + + QAbstractVideoSurface::start(format); + + prepareGeometryChange(); + + return true; + } else { + return false; + } +} + +void VideoItem::stop() +{ + currentFrame = QVideoFrame(); + framePainted = false; + + QAbstractVideoSurface::stop(); +} + +bool VideoItem::present(const QVideoFrame &frame) +{ + if (!framePainted) { + if (!isStarted()) + setError(StoppedError); + + return false; + } else { + currentFrame = frame; + framePainted = false; + + update(); + + return true; + } +} diff --git a/examples/multimedia/videographicsitem/videoitem.h b/examples/multimedia/videographicsitem/videoitem.h new file mode 100644 index 0000000..96f578a --- /dev/null +++ b/examples/multimedia/videographicsitem/videoitem.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef VIDEOITEM_H +#define VIDEOITEM_H + +#include +#include + +class VideoItem + : public QAbstractVideoSurface, + public QGraphicsItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsItem) +public: + explicit VideoItem(QGraphicsItem *parentItem = 0); + ~VideoItem(); + + QRectF boundingRect() const; + void paint( + QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + + //video surface + QList supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const; + + bool start(const QVideoSurfaceFormat &format); + void stop(); + bool present(const QVideoFrame &frame); + +private: + QImage::Format imageFormat; + QSize imageSize; + + QVideoFrame currentFrame; + bool framePainted; +}; + +#endif + diff --git a/examples/multimedia/videographicsitem/videoplayer.cpp b/examples/multimedia/videographicsitem/videoplayer.cpp new file mode 100644 index 0000000..83644db --- /dev/null +++ b/examples/multimedia/videographicsitem/videoplayer.cpp @@ -0,0 +1,210 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "videoplayer.h" +#include "videoitem.h" + +#include + +#ifndef QT_NO_OPENGL +# include +#endif + +VideoPlayer::VideoPlayer(QWidget *parent, Qt::WindowFlags flags) + : QWidget(parent, flags) + , videoItem(0) + , playButton(0) + , positionSlider(0) +{ + connect(&movie, SIGNAL(stateChanged(QMovie::MovieState)), + this, SLOT(movieStateChanged(QMovie::MovieState))); + connect(&movie, SIGNAL(frameChanged(int)), + this, SLOT(frameChanged(int))); + + videoItem = new VideoItem; + + QGraphicsScene *scene = new QGraphicsScene(this); + QGraphicsView *graphicsView = new QGraphicsView(scene); + +#ifndef QT_NO_OPENGL + graphicsView->setViewport(new QGLWidget); +#endif + + scene->addItem(videoItem); + + QSlider *rotateSlider = new QSlider(Qt::Horizontal); + rotateSlider->setRange(-180, 180); + rotateSlider->setValue(0); + + connect(rotateSlider, SIGNAL(valueChanged(int)), + this, SLOT(rotateVideo(int))); + + QAbstractButton *openButton = new QPushButton(tr("Open...")); + connect(openButton, SIGNAL(clicked()), this, SLOT(openFile())); + + playButton = new QPushButton; + playButton->setEnabled(false); + playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); + + connect(playButton, SIGNAL(clicked()), + this, SLOT(play())); + + positionSlider = new QSlider(Qt::Horizontal); + positionSlider->setRange(0, 0); + + connect(positionSlider, SIGNAL(sliderMoved(int)), + this, SLOT(setPosition(int))); + + connect(&movie, SIGNAL(frameChanged(int)), + positionSlider, SLOT(setValue(int))); + + QBoxLayout *controlLayout = new QHBoxLayout; + controlLayout->setMargin(0); + controlLayout->addWidget(openButton); + controlLayout->addWidget(playButton); + controlLayout->addWidget(positionSlider); + + QBoxLayout *layout = new QVBoxLayout; + layout->addWidget(graphicsView); + layout->addWidget(rotateSlider); + layout->addLayout(controlLayout); + + setLayout(layout); +} + +VideoPlayer::~VideoPlayer() +{ +} + +void VideoPlayer::openFile() +{ + QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie")); + + if (!fileName.isEmpty()) { + if (videoItem->isStarted()) + videoItem->stop(); + + movie.setFileName(fileName); + + playButton->setEnabled(true); + positionSlider->setMaximum(movie.frameCount()); + + movie.jumpToFrame(0); + } +} + +void VideoPlayer::play() +{ + switch(movie.state()) { + case QMovie::NotRunning: + movie.start(); + break; + case QMovie::Paused: + movie.setPaused(false); + break; + case QMovie::Running: + movie.setPaused(true); + break; + } +} + +void VideoPlayer::movieStateChanged(QMovie::MovieState state) +{ + switch(state) { + case QMovie::NotRunning: + case QMovie::Paused: + playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); + break; + case QMovie::Running: + playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); + break; + } +} + +void VideoPlayer::frameChanged(int frame) +{ + if (!presentImage(movie.currentImage())) { + movie.stop(); + playButton->setEnabled(false); + positionSlider->setMaximum(0); + } else { + positionSlider->setValue(frame); + } +} + +void VideoPlayer::setPosition(int frame) +{ + movie.jumpToFrame(frame); +} + +void VideoPlayer::rotateVideo(int angle) +{ + //rotate around the center of video element + qreal x = videoItem->boundingRect().width() / 2.0; + qreal y = videoItem->boundingRect().height() / 2.0; + videoItem->setTransform(QTransform().translate(x, y).rotate(angle).translate(-x, -y)); +} + +bool VideoPlayer::presentImage(const QImage &image) +{ + QVideoFrame frame(image); + + if (!frame.isValid()) + return false; + + QVideoSurfaceFormat currentFormat = videoItem->surfaceFormat(); + + if (frame.pixelFormat() != currentFormat.pixelFormat() + || frame.size() != currentFormat.frameSize()) { + QVideoSurfaceFormat format(frame.size(), frame.pixelFormat()); + + if (!videoItem->start(format)) + return false; + } + + if (!videoItem->present(frame)) { + videoItem->stop(); + + return false; + } else { + return true; + } +} diff --git a/examples/multimedia/videographicsitem/videoplayer.h b/examples/multimedia/videographicsitem/videoplayer.h new file mode 100644 index 0000000..8e73e4c --- /dev/null +++ b/examples/multimedia/videographicsitem/videoplayer.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef VIDEOPLAYER_H +#define VIDEOPLAYER_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QAbstractButton; +class QAbstractVideoSurface; +class QSlider; +QT_END_NAMESPACE + + +class VideoItem; + +class VideoPlayer : public QWidget +{ + Q_OBJECT +public: + VideoPlayer(QWidget *parent = 0, Qt::WindowFlags flags = 0); + ~VideoPlayer(); + + QSize sizeHint() const { return QSize(800, 600); } + +public slots: + void openFile(); + void play(); + +private slots: + void movieStateChanged(QMovie::MovieState state); + void frameChanged(int frame); + void setPosition(int frame); + void rotateVideo(int angle); + +private: + bool presentImage(const QImage &image); + + QMovie movie; + VideoItem *videoItem; + QAbstractButton *playButton; + QSlider *positionSlider; +}; + +#endif + diff --git a/examples/multimedia/videowidget/main.cpp b/examples/multimedia/videowidget/main.cpp new file mode 100644 index 0000000..f5edf73 --- /dev/null +++ b/examples/multimedia/videowidget/main.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "videoplayer.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + VideoPlayer player; + player.show(); + + return app.exec(); +} diff --git a/examples/multimedia/videowidget/videoplayer.cpp b/examples/multimedia/videowidget/videoplayer.cpp new file mode 100644 index 0000000..ed24714 --- /dev/null +++ b/examples/multimedia/videowidget/videoplayer.cpp @@ -0,0 +1,183 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "videoplayer.h" + +#include "videowidget.h" + +#include + +VideoPlayer::VideoPlayer(QWidget *parent) + : QWidget(parent) + , surface(0) + , playButton(0) + , positionSlider(0) +{ + connect(&movie, SIGNAL(stateChanged(QMovie::MovieState)), + this, SLOT(movieStateChanged(QMovie::MovieState))); + connect(&movie, SIGNAL(frameChanged(int)), + this, SLOT(frameChanged(int))); + + VideoWidget *videoWidget = new VideoWidget; + surface = videoWidget->videoSurface(); + + QAbstractButton *openButton = new QPushButton(tr("Open...")); + connect(openButton, SIGNAL(clicked()), this, SLOT(openFile())); + + playButton = new QPushButton; + playButton->setEnabled(false); + playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); + + connect(playButton, SIGNAL(clicked()), + this, SLOT(play())); + + positionSlider = new QSlider(Qt::Horizontal); + positionSlider->setRange(0, 0); + + connect(positionSlider, SIGNAL(sliderMoved(int)), + this, SLOT(setPosition(int))); + + connect(&movie, SIGNAL(frameChanged(int)), + positionSlider, SLOT(setValue(int))); + + QBoxLayout *controlLayout = new QHBoxLayout; + controlLayout->setMargin(0); + controlLayout->addWidget(openButton); + controlLayout->addWidget(playButton); + controlLayout->addWidget(positionSlider); + + QBoxLayout *layout = new QVBoxLayout; + layout->addWidget(videoWidget); + layout->addLayout(controlLayout); + + setLayout(layout); +} + +VideoPlayer::~VideoPlayer() +{ +} + +void VideoPlayer::openFile() +{ + QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie")); + + if (!fileName.isEmpty()) { + if (surface->isStarted()) + surface->stop(); + + movie.setFileName(fileName); + + playButton->setEnabled(true); + positionSlider->setMaximum(movie.frameCount()); + + movie.jumpToFrame(0); + } +} + +void VideoPlayer::play() +{ + switch(movie.state()) { + case QMovie::NotRunning: + movie.start(); + break; + case QMovie::Paused: + movie.setPaused(false); + break; + case QMovie::Running: + movie.setPaused(true); + break; + } +} + +void VideoPlayer::movieStateChanged(QMovie::MovieState state) +{ + switch(state) { + case QMovie::NotRunning: + case QMovie::Paused: + playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); + break; + case QMovie::Running: + playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); + break; + } +} + +void VideoPlayer::frameChanged(int frame) +{ + if (!presentImage(movie.currentImage())) { + movie.stop(); + playButton->setEnabled(false); + positionSlider->setMaximum(0); + } else { + positionSlider->setValue(frame); + } +} + +void VideoPlayer::setPosition(int frame) +{ + movie.jumpToFrame(frame); +} + +bool VideoPlayer::presentImage(const QImage &image) +{ + QVideoFrame frame(image); + + if (!frame.isValid()) + return false; + + QVideoSurfaceFormat currentFormat = surface->surfaceFormat(); + + if (frame.pixelFormat() != currentFormat.pixelFormat() + || frame.size() != currentFormat.frameSize()) { + QVideoSurfaceFormat format(frame.size(), frame.pixelFormat()); + + if (!surface->start(format)) + return false; + } + + if (!surface->present(frame)) { + surface->stop(); + + return false; + } else { + return true; + } +} diff --git a/examples/multimedia/videowidget/videoplayer.h b/examples/multimedia/videowidget/videoplayer.h new file mode 100644 index 0000000..6547415 --- /dev/null +++ b/examples/multimedia/videowidget/videoplayer.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef VIDEOPLAYER_H +#define VIDEOPLAYER_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QAbstractButton; +class QAbstractVideoSurface; +class QSlider; +QT_END_NAMESPACE + +class VideoPlayer : public QWidget +{ + Q_OBJECT +public: + VideoPlayer(QWidget *parent = 0); + ~VideoPlayer(); + +public slots: + void openFile(); + void play(); + +private slots: + void movieStateChanged(QMovie::MovieState state); + void frameChanged(int frame); + void setPosition(int frame); + +private: + bool presentImage(const QImage &image); + + QMovie movie; + QAbstractVideoSurface *surface; + QAbstractButton *playButton; + QSlider *positionSlider; +}; + +#endif diff --git a/examples/multimedia/videowidget/videowidget.cpp b/examples/multimedia/videowidget/videowidget.cpp new file mode 100644 index 0000000..80688e1 --- /dev/null +++ b/examples/multimedia/videowidget/videowidget.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "videowidget.h" + +#include "videowidgetsurface.h" + +#include + +//! [0] +VideoWidget::VideoWidget(QWidget *parent) + : QWidget(parent) + , surface(0) +{ + setAutoFillBackground(false); + setAttribute(Qt::WA_NoSystemBackground, true); + setAttribute(Qt::WA_PaintOnScreen, true); + + QPalette palette = this->palette(); + palette.setColor(QPalette::Background, Qt::black); + setPalette(palette); + + setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + + surface = new VideoWidgetSurface(this); +} +//! [0] + +//! [1] +VideoWidget::~VideoWidget() +{ + delete surface; +} +//! [1] + +//! [2] +QSize VideoWidget::sizeHint() const +{ + return surface->surfaceFormat().sizeHint(); +} +//! [2] + + +//! [3] +void VideoWidget::paintEvent(QPaintEvent *event) +{ + QPainter painter(this); + + if (surface->isStarted()) { + const QRect videoRect = surface->videoRect(); + + if (!videoRect.contains(event->rect())) { + QRegion region = event->region(); + region.subtract(videoRect); + + QBrush brush = palette().background(); + + foreach (const QRect &rect, region.rects()) + painter.fillRect(rect, brush); + } + + surface->paint(&painter); + } else { + painter.fillRect(event->rect(), palette().background()); + } +} +//! [3] + +//! [4] +void VideoWidget::resizeEvent(QResizeEvent *event) +{ + QWidget::resizeEvent(event); + + surface->updateVideoRect(); +} +//! [4] diff --git a/examples/multimedia/videowidget/videowidget.h b/examples/multimedia/videowidget/videowidget.h new file mode 100644 index 0000000..8c343bf --- /dev/null +++ b/examples/multimedia/videowidget/videowidget.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef VIDEOWIDGET_H +#define VIDEOWIDGET_H + +#include "videowidgetsurface.h" + +#include + +QT_BEGIN_NAMESPACE +class QAbstractVideoSurface; +QT_END_NAMESPACE + +class VideoWidgetSurface; + +//! [0] +class VideoWidget : public QWidget +{ + Q_OBJECT +public: + VideoWidget(QWidget *parent = 0); + ~VideoWidget(); + + QAbstractVideoSurface *videoSurface() const { return surface; } + + QSize sizeHint() const; + +protected: + void paintEvent(QPaintEvent *event); + void resizeEvent(QResizeEvent *event); + +private: + VideoWidgetSurface *surface; +}; +//! [0] + +#endif diff --git a/examples/multimedia/videowidget/videowidget.pro b/examples/multimedia/videowidget/videowidget.pro new file mode 100644 index 0000000..3f93745 --- /dev/null +++ b/examples/multimedia/videowidget/videowidget.pro @@ -0,0 +1,25 @@ +TEMPLATE = app + +QT += multimedia + +HEADERS = \ + videoplayer.h \ + videowidget.h \ + videowidgetsurface.h + +SOURCES = \ + main.cpp \ + videoplayer.cpp \ + videowidget.cpp \ + videowidgetsurface.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/videowidget +sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png images +sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/videowidget +INSTALLS += target sources + +symbian { + TARGET.UID3 = 0xA000D7C3 + include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +} diff --git a/examples/multimedia/videowidget/videowidgetsurface.cpp b/examples/multimedia/videowidget/videowidgetsurface.cpp new file mode 100644 index 0000000..ec9b8b5 --- /dev/null +++ b/examples/multimedia/videowidget/videowidgetsurface.cpp @@ -0,0 +1,175 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "videowidgetsurface.h" + +#include + +VideoWidgetSurface::VideoWidgetSurface(QWidget *widget, QObject *parent) + : QAbstractVideoSurface(parent) + , widget(widget) + , imageFormat(QImage::Format_Invalid) +{ +} + +//! [0] +QList VideoWidgetSurface::supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType) const +{ + if (handleType == QAbstractVideoBuffer::NoHandle) { + return QList() + << QVideoFrame::Format_RGB32 + << QVideoFrame::Format_ARGB32 + << QVideoFrame::Format_ARGB32_Premultiplied + << QVideoFrame::Format_RGB565 + << QVideoFrame::Format_RGB555; + } else { + return QList(); + } +} +//! [0] + +//! [1] +bool VideoWidgetSurface::isFormatSupported( + const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const +{ + Q_UNUSED(similar); + + const QImage::Format imageFormat = QVideoFrame::equivalentImageFormat(format.pixelFormat()); + const QSize size = format.frameSize(); + + return imageFormat != QImage::Format_Invalid + && !size.isEmpty() + && format.handleType() == QAbstractVideoBuffer::NoHandle; +} +//! [1] + +//! [2] +bool VideoWidgetSurface::start(const QVideoSurfaceFormat &format) +{ + const QImage::Format imageFormat = QVideoFrame::equivalentImageFormat(format.pixelFormat()); + const QSize size = format.frameSize(); + + if (imageFormat != QImage::Format_Invalid && !size.isEmpty()) { + this->imageFormat = imageFormat; + imageSize = size; + sourceRect = format.viewport(); + + QAbstractVideoSurface::start(format); + + widget->updateGeometry(); + updateVideoRect(); + + return true; + } else { + return false; + } +} +//! [2] + +//! [3] +void VideoWidgetSurface::stop() +{ + currentFrame = QVideoFrame(); + targetRect = QRect(); + + QAbstractVideoSurface::stop(); + + widget->update(); +} +//! [3] + +//! [4] +bool VideoWidgetSurface::present(const QVideoFrame &frame) +{ + if (surfaceFormat().pixelFormat() != frame.pixelFormat() + || surfaceFormat().frameSize() != frame.size()) { + setError(IncorrectFormatError); + stop(); + + return false; + } else { + currentFrame = frame; + + widget->repaint(targetRect); + + return true; + } +} +//! [4] + +//! [5] +void VideoWidgetSurface::updateVideoRect() +{ + QSize size = surfaceFormat().sizeHint(); + size.scale(widget->size().boundedTo(size), Qt::KeepAspectRatio); + + targetRect = QRect(QPoint(0, 0), size); + targetRect.moveCenter(widget->rect().center()); +} +//! [5] + +//! [6] +void VideoWidgetSurface::paint(QPainter *painter) +{ + if (currentFrame.map(QAbstractVideoBuffer::ReadOnly)) { + const QTransform oldTransform = painter->transform(); + + if (surfaceFormat().scanLineDirection() == QVideoSurfaceFormat::BottomToTop) { + painter->scale(1, -1); + painter->translate(0, -widget->height()); + } + + QImage image( + currentFrame.bits(), + currentFrame.width(), + currentFrame.height(), + currentFrame.bytesPerLine(), + imageFormat); + + painter->drawImage(targetRect, image, sourceRect); + + painter->setTransform(oldTransform); + + currentFrame.unmap(); + } +} +//! [6] diff --git a/examples/multimedia/videowidget/videowidgetsurface.h b/examples/multimedia/videowidget/videowidgetsurface.h new file mode 100644 index 0000000..83439d3 --- /dev/null +++ b/examples/multimedia/videowidget/videowidgetsurface.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef VIDEOWIDGETSURFACE_H +#define VIDEOWIDGETSURFACE_H + +#include +#include +#include +#include + +//! [0] +class VideoWidgetSurface : public QAbstractVideoSurface +{ + Q_OBJECT +public: + VideoWidgetSurface(QWidget *widget, QObject *parent = 0); + + QList supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const; + bool isFormatSupported(const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const; + + bool start(const QVideoSurfaceFormat &format); + void stop(); + + bool present(const QVideoFrame &frame); + + QRect videoRect() const { return targetRect; } + void updateVideoRect(); + + void paint(QPainter *painter); + +private: + QWidget *widget; + QImage::Format imageFormat; + QRect targetRect; + QSize imageSize; + QRect sourceRect; + QVideoFrame currentFrame; +}; +//! [0] + +#endif diff --git a/examples/video/video.pro b/examples/video/video.pro deleted file mode 100644 index f0b63b6..0000000 --- a/examples/video/video.pro +++ /dev/null @@ -1,6 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS += \ - videographicsitem \ - videowidget - diff --git a/examples/video/videographicsitem/main.cpp b/examples/video/videographicsitem/main.cpp deleted file mode 100644 index 3bf4c6d..0000000 --- a/examples/video/videographicsitem/main.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "videoplayer.h" - -#include - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - - VideoPlayer player; - player.show(); - - return app.exec(); -} - diff --git a/examples/video/videographicsitem/videographicsitem.pro b/examples/video/videographicsitem/videographicsitem.pro deleted file mode 100644 index d79c3fb..0000000 --- a/examples/video/videographicsitem/videographicsitem.pro +++ /dev/null @@ -1,21 +0,0 @@ -QT += multimedia - -contains(QT_CONFIG, opengl): QT += opengl - -HEADERS += videoplayer.h \ - videoitem.h - -SOURCES += main.cpp \ - videoplayer.cpp \ - videoitem.cpp - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/video/videographicsitem -sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png images -sources.path = $$[QT_INSTALL_EXAMPLES]/video/videographicsitem -INSTALLS += target sources - -symbian { - TARGET.UID3 = 0xA000D7C2 - include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) -} diff --git a/examples/video/videographicsitem/videoitem.cpp b/examples/video/videographicsitem/videoitem.cpp deleted file mode 100644 index c95e335..0000000 --- a/examples/video/videographicsitem/videoitem.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "videoitem.h" - -#include - -VideoItem::VideoItem(QGraphicsItem *parent) - : QGraphicsItem(parent) - , imageFormat(QImage::Format_Invalid) - , framePainted(false) -{ -} - -VideoItem::~VideoItem() -{ -} - -QRectF VideoItem::boundingRect() const -{ - return QRectF(QPointF(0,0), surfaceFormat().sizeHint()); -} - -void VideoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_UNUSED(option); - Q_UNUSED(widget); - - if (currentFrame.map(QAbstractVideoBuffer::ReadOnly)) { - const QTransform oldTransform = painter->transform(); - - if (surfaceFormat().scanLineDirection() == QVideoSurfaceFormat::BottomToTop) { - painter->scale(1, -1); - painter->translate(0, -boundingRect().height()); - } - - painter->drawImage(boundingRect(), QImage( - currentFrame.bits(), - imageSize.width(), - imageSize.height(), - imageFormat)); - - painter->setTransform(oldTransform); - - framePainted = true; - - currentFrame.unmap(); - } -} - -QList VideoItem::supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType) const -{ - if (handleType == QAbstractVideoBuffer::NoHandle) { - return QList() - << QVideoFrame::Format_RGB32 - << QVideoFrame::Format_ARGB32 - << QVideoFrame::Format_ARGB32_Premultiplied - << QVideoFrame::Format_RGB565 - << QVideoFrame::Format_RGB555; - } else { - return QList(); - } -} - -bool VideoItem::start(const QVideoSurfaceFormat &format) -{ - if (isFormatSupported(format)) { - imageFormat = QVideoFrame::equivalentImageFormat(format.pixelFormat()); - imageSize = format.frameSize(); - framePainted = true; - - QAbstractVideoSurface::start(format); - - prepareGeometryChange(); - - return true; - } else { - return false; - } -} - -void VideoItem::stop() -{ - currentFrame = QVideoFrame(); - framePainted = false; - - QAbstractVideoSurface::stop(); -} - -bool VideoItem::present(const QVideoFrame &frame) -{ - if (!framePainted) { - if (!isStarted()) - setError(StoppedError); - - return false; - } else { - currentFrame = frame; - framePainted = false; - - update(); - - return true; - } -} diff --git a/examples/video/videographicsitem/videoitem.h b/examples/video/videographicsitem/videoitem.h deleted file mode 100644 index 96f578a..0000000 --- a/examples/video/videographicsitem/videoitem.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef VIDEOITEM_H -#define VIDEOITEM_H - -#include -#include - -class VideoItem - : public QAbstractVideoSurface, - public QGraphicsItem -{ - Q_OBJECT - Q_INTERFACES(QGraphicsItem) -public: - explicit VideoItem(QGraphicsItem *parentItem = 0); - ~VideoItem(); - - QRectF boundingRect() const; - void paint( - QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); - - //video surface - QList supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const; - - bool start(const QVideoSurfaceFormat &format); - void stop(); - bool present(const QVideoFrame &frame); - -private: - QImage::Format imageFormat; - QSize imageSize; - - QVideoFrame currentFrame; - bool framePainted; -}; - -#endif - diff --git a/examples/video/videographicsitem/videoplayer.cpp b/examples/video/videographicsitem/videoplayer.cpp deleted file mode 100644 index 83644db..0000000 --- a/examples/video/videographicsitem/videoplayer.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "videoplayer.h" -#include "videoitem.h" - -#include - -#ifndef QT_NO_OPENGL -# include -#endif - -VideoPlayer::VideoPlayer(QWidget *parent, Qt::WindowFlags flags) - : QWidget(parent, flags) - , videoItem(0) - , playButton(0) - , positionSlider(0) -{ - connect(&movie, SIGNAL(stateChanged(QMovie::MovieState)), - this, SLOT(movieStateChanged(QMovie::MovieState))); - connect(&movie, SIGNAL(frameChanged(int)), - this, SLOT(frameChanged(int))); - - videoItem = new VideoItem; - - QGraphicsScene *scene = new QGraphicsScene(this); - QGraphicsView *graphicsView = new QGraphicsView(scene); - -#ifndef QT_NO_OPENGL - graphicsView->setViewport(new QGLWidget); -#endif - - scene->addItem(videoItem); - - QSlider *rotateSlider = new QSlider(Qt::Horizontal); - rotateSlider->setRange(-180, 180); - rotateSlider->setValue(0); - - connect(rotateSlider, SIGNAL(valueChanged(int)), - this, SLOT(rotateVideo(int))); - - QAbstractButton *openButton = new QPushButton(tr("Open...")); - connect(openButton, SIGNAL(clicked()), this, SLOT(openFile())); - - playButton = new QPushButton; - playButton->setEnabled(false); - playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); - - connect(playButton, SIGNAL(clicked()), - this, SLOT(play())); - - positionSlider = new QSlider(Qt::Horizontal); - positionSlider->setRange(0, 0); - - connect(positionSlider, SIGNAL(sliderMoved(int)), - this, SLOT(setPosition(int))); - - connect(&movie, SIGNAL(frameChanged(int)), - positionSlider, SLOT(setValue(int))); - - QBoxLayout *controlLayout = new QHBoxLayout; - controlLayout->setMargin(0); - controlLayout->addWidget(openButton); - controlLayout->addWidget(playButton); - controlLayout->addWidget(positionSlider); - - QBoxLayout *layout = new QVBoxLayout; - layout->addWidget(graphicsView); - layout->addWidget(rotateSlider); - layout->addLayout(controlLayout); - - setLayout(layout); -} - -VideoPlayer::~VideoPlayer() -{ -} - -void VideoPlayer::openFile() -{ - QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie")); - - if (!fileName.isEmpty()) { - if (videoItem->isStarted()) - videoItem->stop(); - - movie.setFileName(fileName); - - playButton->setEnabled(true); - positionSlider->setMaximum(movie.frameCount()); - - movie.jumpToFrame(0); - } -} - -void VideoPlayer::play() -{ - switch(movie.state()) { - case QMovie::NotRunning: - movie.start(); - break; - case QMovie::Paused: - movie.setPaused(false); - break; - case QMovie::Running: - movie.setPaused(true); - break; - } -} - -void VideoPlayer::movieStateChanged(QMovie::MovieState state) -{ - switch(state) { - case QMovie::NotRunning: - case QMovie::Paused: - playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); - break; - case QMovie::Running: - playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); - break; - } -} - -void VideoPlayer::frameChanged(int frame) -{ - if (!presentImage(movie.currentImage())) { - movie.stop(); - playButton->setEnabled(false); - positionSlider->setMaximum(0); - } else { - positionSlider->setValue(frame); - } -} - -void VideoPlayer::setPosition(int frame) -{ - movie.jumpToFrame(frame); -} - -void VideoPlayer::rotateVideo(int angle) -{ - //rotate around the center of video element - qreal x = videoItem->boundingRect().width() / 2.0; - qreal y = videoItem->boundingRect().height() / 2.0; - videoItem->setTransform(QTransform().translate(x, y).rotate(angle).translate(-x, -y)); -} - -bool VideoPlayer::presentImage(const QImage &image) -{ - QVideoFrame frame(image); - - if (!frame.isValid()) - return false; - - QVideoSurfaceFormat currentFormat = videoItem->surfaceFormat(); - - if (frame.pixelFormat() != currentFormat.pixelFormat() - || frame.size() != currentFormat.frameSize()) { - QVideoSurfaceFormat format(frame.size(), frame.pixelFormat()); - - if (!videoItem->start(format)) - return false; - } - - if (!videoItem->present(frame)) { - videoItem->stop(); - - return false; - } else { - return true; - } -} diff --git a/examples/video/videographicsitem/videoplayer.h b/examples/video/videographicsitem/videoplayer.h deleted file mode 100644 index 8e73e4c..0000000 --- a/examples/video/videographicsitem/videoplayer.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef VIDEOPLAYER_H -#define VIDEOPLAYER_H - -#include -#include - -QT_BEGIN_NAMESPACE -class QAbstractButton; -class QAbstractVideoSurface; -class QSlider; -QT_END_NAMESPACE - - -class VideoItem; - -class VideoPlayer : public QWidget -{ - Q_OBJECT -public: - VideoPlayer(QWidget *parent = 0, Qt::WindowFlags flags = 0); - ~VideoPlayer(); - - QSize sizeHint() const { return QSize(800, 600); } - -public slots: - void openFile(); - void play(); - -private slots: - void movieStateChanged(QMovie::MovieState state); - void frameChanged(int frame); - void setPosition(int frame); - void rotateVideo(int angle); - -private: - bool presentImage(const QImage &image); - - QMovie movie; - VideoItem *videoItem; - QAbstractButton *playButton; - QSlider *positionSlider; -}; - -#endif - diff --git a/examples/video/videowidget/main.cpp b/examples/video/videowidget/main.cpp deleted file mode 100644 index f5edf73..0000000 --- a/examples/video/videowidget/main.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "videoplayer.h" - -#include - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - VideoPlayer player; - player.show(); - - return app.exec(); -} diff --git a/examples/video/videowidget/videoplayer.cpp b/examples/video/videowidget/videoplayer.cpp deleted file mode 100644 index ed24714..0000000 --- a/examples/video/videowidget/videoplayer.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "videoplayer.h" - -#include "videowidget.h" - -#include - -VideoPlayer::VideoPlayer(QWidget *parent) - : QWidget(parent) - , surface(0) - , playButton(0) - , positionSlider(0) -{ - connect(&movie, SIGNAL(stateChanged(QMovie::MovieState)), - this, SLOT(movieStateChanged(QMovie::MovieState))); - connect(&movie, SIGNAL(frameChanged(int)), - this, SLOT(frameChanged(int))); - - VideoWidget *videoWidget = new VideoWidget; - surface = videoWidget->videoSurface(); - - QAbstractButton *openButton = new QPushButton(tr("Open...")); - connect(openButton, SIGNAL(clicked()), this, SLOT(openFile())); - - playButton = new QPushButton; - playButton->setEnabled(false); - playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); - - connect(playButton, SIGNAL(clicked()), - this, SLOT(play())); - - positionSlider = new QSlider(Qt::Horizontal); - positionSlider->setRange(0, 0); - - connect(positionSlider, SIGNAL(sliderMoved(int)), - this, SLOT(setPosition(int))); - - connect(&movie, SIGNAL(frameChanged(int)), - positionSlider, SLOT(setValue(int))); - - QBoxLayout *controlLayout = new QHBoxLayout; - controlLayout->setMargin(0); - controlLayout->addWidget(openButton); - controlLayout->addWidget(playButton); - controlLayout->addWidget(positionSlider); - - QBoxLayout *layout = new QVBoxLayout; - layout->addWidget(videoWidget); - layout->addLayout(controlLayout); - - setLayout(layout); -} - -VideoPlayer::~VideoPlayer() -{ -} - -void VideoPlayer::openFile() -{ - QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie")); - - if (!fileName.isEmpty()) { - if (surface->isStarted()) - surface->stop(); - - movie.setFileName(fileName); - - playButton->setEnabled(true); - positionSlider->setMaximum(movie.frameCount()); - - movie.jumpToFrame(0); - } -} - -void VideoPlayer::play() -{ - switch(movie.state()) { - case QMovie::NotRunning: - movie.start(); - break; - case QMovie::Paused: - movie.setPaused(false); - break; - case QMovie::Running: - movie.setPaused(true); - break; - } -} - -void VideoPlayer::movieStateChanged(QMovie::MovieState state) -{ - switch(state) { - case QMovie::NotRunning: - case QMovie::Paused: - playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); - break; - case QMovie::Running: - playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); - break; - } -} - -void VideoPlayer::frameChanged(int frame) -{ - if (!presentImage(movie.currentImage())) { - movie.stop(); - playButton->setEnabled(false); - positionSlider->setMaximum(0); - } else { - positionSlider->setValue(frame); - } -} - -void VideoPlayer::setPosition(int frame) -{ - movie.jumpToFrame(frame); -} - -bool VideoPlayer::presentImage(const QImage &image) -{ - QVideoFrame frame(image); - - if (!frame.isValid()) - return false; - - QVideoSurfaceFormat currentFormat = surface->surfaceFormat(); - - if (frame.pixelFormat() != currentFormat.pixelFormat() - || frame.size() != currentFormat.frameSize()) { - QVideoSurfaceFormat format(frame.size(), frame.pixelFormat()); - - if (!surface->start(format)) - return false; - } - - if (!surface->present(frame)) { - surface->stop(); - - return false; - } else { - return true; - } -} diff --git a/examples/video/videowidget/videoplayer.h b/examples/video/videowidget/videoplayer.h deleted file mode 100644 index 6547415..0000000 --- a/examples/video/videowidget/videoplayer.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef VIDEOPLAYER_H -#define VIDEOPLAYER_H - -#include -#include - -QT_BEGIN_NAMESPACE -class QAbstractButton; -class QAbstractVideoSurface; -class QSlider; -QT_END_NAMESPACE - -class VideoPlayer : public QWidget -{ - Q_OBJECT -public: - VideoPlayer(QWidget *parent = 0); - ~VideoPlayer(); - -public slots: - void openFile(); - void play(); - -private slots: - void movieStateChanged(QMovie::MovieState state); - void frameChanged(int frame); - void setPosition(int frame); - -private: - bool presentImage(const QImage &image); - - QMovie movie; - QAbstractVideoSurface *surface; - QAbstractButton *playButton; - QSlider *positionSlider; -}; - -#endif diff --git a/examples/video/videowidget/videowidget.cpp b/examples/video/videowidget/videowidget.cpp deleted file mode 100644 index 80688e1..0000000 --- a/examples/video/videowidget/videowidget.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "videowidget.h" - -#include "videowidgetsurface.h" - -#include - -//! [0] -VideoWidget::VideoWidget(QWidget *parent) - : QWidget(parent) - , surface(0) -{ - setAutoFillBackground(false); - setAttribute(Qt::WA_NoSystemBackground, true); - setAttribute(Qt::WA_PaintOnScreen, true); - - QPalette palette = this->palette(); - palette.setColor(QPalette::Background, Qt::black); - setPalette(palette); - - setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - - surface = new VideoWidgetSurface(this); -} -//! [0] - -//! [1] -VideoWidget::~VideoWidget() -{ - delete surface; -} -//! [1] - -//! [2] -QSize VideoWidget::sizeHint() const -{ - return surface->surfaceFormat().sizeHint(); -} -//! [2] - - -//! [3] -void VideoWidget::paintEvent(QPaintEvent *event) -{ - QPainter painter(this); - - if (surface->isStarted()) { - const QRect videoRect = surface->videoRect(); - - if (!videoRect.contains(event->rect())) { - QRegion region = event->region(); - region.subtract(videoRect); - - QBrush brush = palette().background(); - - foreach (const QRect &rect, region.rects()) - painter.fillRect(rect, brush); - } - - surface->paint(&painter); - } else { - painter.fillRect(event->rect(), palette().background()); - } -} -//! [3] - -//! [4] -void VideoWidget::resizeEvent(QResizeEvent *event) -{ - QWidget::resizeEvent(event); - - surface->updateVideoRect(); -} -//! [4] diff --git a/examples/video/videowidget/videowidget.h b/examples/video/videowidget/videowidget.h deleted file mode 100644 index 8c343bf..0000000 --- a/examples/video/videowidget/videowidget.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef VIDEOWIDGET_H -#define VIDEOWIDGET_H - -#include "videowidgetsurface.h" - -#include - -QT_BEGIN_NAMESPACE -class QAbstractVideoSurface; -QT_END_NAMESPACE - -class VideoWidgetSurface; - -//! [0] -class VideoWidget : public QWidget -{ - Q_OBJECT -public: - VideoWidget(QWidget *parent = 0); - ~VideoWidget(); - - QAbstractVideoSurface *videoSurface() const { return surface; } - - QSize sizeHint() const; - -protected: - void paintEvent(QPaintEvent *event); - void resizeEvent(QResizeEvent *event); - -private: - VideoWidgetSurface *surface; -}; -//! [0] - -#endif diff --git a/examples/video/videowidget/videowidget.pro b/examples/video/videowidget/videowidget.pro deleted file mode 100644 index 4a1d717..0000000 --- a/examples/video/videowidget/videowidget.pro +++ /dev/null @@ -1,19 +0,0 @@ -TEMPLATE = app - -QT += multimedia - -HEADERS = \ - videoplayer.h \ - videowidget.h \ - videowidgetsurface.h - -SOURCES = \ - main.cpp \ - videoplayer.cpp \ - videowidget.cpp \ - videowidgetsurface.cpp - -symbian { - TARGET.UID3 = 0xA000D7C3 - include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) -} diff --git a/examples/video/videowidget/videowidgetsurface.cpp b/examples/video/videowidget/videowidgetsurface.cpp deleted file mode 100644 index ec9b8b5..0000000 --- a/examples/video/videowidget/videowidgetsurface.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "videowidgetsurface.h" - -#include - -VideoWidgetSurface::VideoWidgetSurface(QWidget *widget, QObject *parent) - : QAbstractVideoSurface(parent) - , widget(widget) - , imageFormat(QImage::Format_Invalid) -{ -} - -//! [0] -QList VideoWidgetSurface::supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType) const -{ - if (handleType == QAbstractVideoBuffer::NoHandle) { - return QList() - << QVideoFrame::Format_RGB32 - << QVideoFrame::Format_ARGB32 - << QVideoFrame::Format_ARGB32_Premultiplied - << QVideoFrame::Format_RGB565 - << QVideoFrame::Format_RGB555; - } else { - return QList(); - } -} -//! [0] - -//! [1] -bool VideoWidgetSurface::isFormatSupported( - const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const -{ - Q_UNUSED(similar); - - const QImage::Format imageFormat = QVideoFrame::equivalentImageFormat(format.pixelFormat()); - const QSize size = format.frameSize(); - - return imageFormat != QImage::Format_Invalid - && !size.isEmpty() - && format.handleType() == QAbstractVideoBuffer::NoHandle; -} -//! [1] - -//! [2] -bool VideoWidgetSurface::start(const QVideoSurfaceFormat &format) -{ - const QImage::Format imageFormat = QVideoFrame::equivalentImageFormat(format.pixelFormat()); - const QSize size = format.frameSize(); - - if (imageFormat != QImage::Format_Invalid && !size.isEmpty()) { - this->imageFormat = imageFormat; - imageSize = size; - sourceRect = format.viewport(); - - QAbstractVideoSurface::start(format); - - widget->updateGeometry(); - updateVideoRect(); - - return true; - } else { - return false; - } -} -//! [2] - -//! [3] -void VideoWidgetSurface::stop() -{ - currentFrame = QVideoFrame(); - targetRect = QRect(); - - QAbstractVideoSurface::stop(); - - widget->update(); -} -//! [3] - -//! [4] -bool VideoWidgetSurface::present(const QVideoFrame &frame) -{ - if (surfaceFormat().pixelFormat() != frame.pixelFormat() - || surfaceFormat().frameSize() != frame.size()) { - setError(IncorrectFormatError); - stop(); - - return false; - } else { - currentFrame = frame; - - widget->repaint(targetRect); - - return true; - } -} -//! [4] - -//! [5] -void VideoWidgetSurface::updateVideoRect() -{ - QSize size = surfaceFormat().sizeHint(); - size.scale(widget->size().boundedTo(size), Qt::KeepAspectRatio); - - targetRect = QRect(QPoint(0, 0), size); - targetRect.moveCenter(widget->rect().center()); -} -//! [5] - -//! [6] -void VideoWidgetSurface::paint(QPainter *painter) -{ - if (currentFrame.map(QAbstractVideoBuffer::ReadOnly)) { - const QTransform oldTransform = painter->transform(); - - if (surfaceFormat().scanLineDirection() == QVideoSurfaceFormat::BottomToTop) { - painter->scale(1, -1); - painter->translate(0, -widget->height()); - } - - QImage image( - currentFrame.bits(), - currentFrame.width(), - currentFrame.height(), - currentFrame.bytesPerLine(), - imageFormat); - - painter->drawImage(targetRect, image, sourceRect); - - painter->setTransform(oldTransform); - - currentFrame.unmap(); - } -} -//! [6] diff --git a/examples/video/videowidget/videowidgetsurface.h b/examples/video/videowidget/videowidgetsurface.h deleted file mode 100644 index 83439d3..0000000 --- a/examples/video/videowidget/videowidgetsurface.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef VIDEOWIDGETSURFACE_H -#define VIDEOWIDGETSURFACE_H - -#include -#include -#include -#include - -//! [0] -class VideoWidgetSurface : public QAbstractVideoSurface -{ - Q_OBJECT -public: - VideoWidgetSurface(QWidget *widget, QObject *parent = 0); - - QList supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const; - bool isFormatSupported(const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const; - - bool start(const QVideoSurfaceFormat &format); - void stop(); - - bool present(const QVideoFrame &frame); - - QRect videoRect() const { return targetRect; } - void updateVideoRect(); - - void paint(QPainter *painter); - -private: - QWidget *widget; - QImage::Format imageFormat; - QRect targetRect; - QSize imageSize; - QRect sourceRect; - QVideoFrame currentFrame; -}; -//! [0] - -#endif -- cgit v0.12