Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
This commit is contained in:
2
examples/examples.pro
Normal file
2
examples/examples.pro
Normal file
@@ -0,0 +1,2 @@
|
||||
TEMPLATE = subdirs
|
||||
SUBDIRS += multimedia
|
||||
34
examples/multimedia/README
Normal file
34
examples/multimedia/README
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
The example launcher provided with Qt can be used to explore each of the
|
||||
examples in this directory.
|
||||
|
||||
Documentation for these examples can be found via the Tutorial and Examples
|
||||
link in the main Qt documentation.
|
||||
|
||||
|
||||
Finding the Qt Examples and Demos launcher
|
||||
==========================================
|
||||
|
||||
On Windows:
|
||||
|
||||
The launcher can be accessed via the Windows Start menu. Select the menu
|
||||
entry entitled "Qt Examples and Demos" entry in the submenu containing
|
||||
the Qt tools.
|
||||
|
||||
On Mac OS X:
|
||||
|
||||
For the binary distribution, the qtdemo executable is installed in the
|
||||
/Developer/Applications/Qt directory. For the source distribution, it is
|
||||
installed alongside the other Qt tools on the path specified when Qt is
|
||||
configured.
|
||||
|
||||
On Unix/Linux:
|
||||
|
||||
The qtdemo executable is installed alongside the other Qt tools on the path
|
||||
specified when Qt is configured.
|
||||
|
||||
On all platforms:
|
||||
|
||||
The source code for the launcher can be found in the demos/qtdemo directory
|
||||
in the Qt package. This example is built at the same time as the Qt libraries,
|
||||
tools, examples, and demonstrations.
|
||||
314
examples/multimedia/audiodevices/audiodevices.cpp
Normal file
314
examples/multimedia/audiodevices/audiodevices.cpp
Normal file
@@ -0,0 +1,314 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include <QAudioDeviceInfo>
|
||||
|
||||
#include "audiodevices.h"
|
||||
|
||||
// Utility functions for converting QAudioFormat fields into text
|
||||
|
||||
QString toString(QAudioFormat::SampleType sampleType)
|
||||
{
|
||||
QString result("Unknown");
|
||||
switch (sampleType) {
|
||||
case QAudioFormat::SignedInt:
|
||||
result = "SignedInt";
|
||||
break;
|
||||
case QAudioFormat::UnSignedInt:
|
||||
result = "UnSignedInt";
|
||||
break;
|
||||
case QAudioFormat::Float:
|
||||
result = "Float";
|
||||
break;
|
||||
case QAudioFormat::Unknown:
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QString toString(QAudioFormat::Endian endian)
|
||||
{
|
||||
QString result("Unknown");
|
||||
switch (endian) {
|
||||
case QAudioFormat::LittleEndian:
|
||||
result = "LittleEndian";
|
||||
break;
|
||||
case QAudioFormat::BigEndian:
|
||||
result = "BigEndian";
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
AudioDevicesBase::AudioDevicesBase(QWidget *parent, Qt::WFlags f)
|
||||
: QMainWindow(parent, f)
|
||||
{
|
||||
setupUi(this);
|
||||
}
|
||||
|
||||
AudioDevicesBase::~AudioDevicesBase() {}
|
||||
|
||||
|
||||
AudioTest::AudioTest(QWidget *parent, Qt::WFlags f)
|
||||
: AudioDevicesBase(parent, f)
|
||||
{
|
||||
mode = QAudio::AudioOutput;
|
||||
|
||||
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)));
|
||||
connect(populateTableButton, SIGNAL(clicked()), SLOT(populateTable()));
|
||||
|
||||
modeBox->setCurrentIndex(0);
|
||||
modeChanged(0);
|
||||
deviceBox->setCurrentIndex(0);
|
||||
deviceChanged(0);
|
||||
}
|
||||
|
||||
AudioTest::~AudioTest()
|
||||
{
|
||||
}
|
||||
|
||||
void AudioTest::test()
|
||||
{
|
||||
// tries to set all the settings picked.
|
||||
testResult->clear();
|
||||
|
||||
if (!deviceInfo.isNull()) {
|
||||
if (deviceInfo.isFormatSupported(settings)) {
|
||||
testResult->setText(tr("Success"));
|
||||
nearestFreq->setText("");
|
||||
nearestChannel->setText("");
|
||||
nearestCodec->setText("");
|
||||
nearestSampleSize->setText("");
|
||||
nearestSampleType->setText("");
|
||||
nearestEndian->setText("");
|
||||
} else {
|
||||
QAudioFormat nearest = deviceInfo.nearestFormat(settings);
|
||||
testResult->setText(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()));
|
||||
nearestSampleType->setText(toString(nearest.sampleType()));
|
||||
nearestEndian->setText(toString(nearest.byteOrder()));
|
||||
}
|
||||
}
|
||||
else
|
||||
testResult->setText(tr("No Device"));
|
||||
}
|
||||
|
||||
void AudioTest::modeChanged(int idx)
|
||||
{
|
||||
testResult->clear();
|
||||
|
||||
// mode has changed
|
||||
if (idx == 0)
|
||||
mode = QAudio::AudioInput;
|
||||
else
|
||||
mode = QAudio::AudioOutput;
|
||||
|
||||
deviceBox->clear();
|
||||
foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(mode))
|
||||
deviceBox->addItem(deviceInfo.deviceName(), QVariant::fromValue(deviceInfo));
|
||||
|
||||
deviceBox->setCurrentIndex(0);
|
||||
deviceChanged(0);
|
||||
}
|
||||
|
||||
void AudioTest::deviceChanged(int idx)
|
||||
{
|
||||
testResult->clear();
|
||||
|
||||
if (deviceBox->count() == 0)
|
||||
return;
|
||||
|
||||
// device has changed
|
||||
deviceInfo = deviceBox->itemData(idx).value<QAudioDeviceInfo>();
|
||||
|
||||
frequencyBox->clear();
|
||||
QList<int> 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<int> 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<int> 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<QAudioFormat::SampleType> sampleTypez = deviceInfo.supportedSampleTypes();
|
||||
|
||||
for (int i = 0; i < sampleTypez.size(); ++i)
|
||||
sampleTypesBox->addItem(toString(sampleTypez.at(i)));
|
||||
if (sampleTypez.size())
|
||||
settings.setSampleType(sampleTypez.at(0));
|
||||
|
||||
endianBox->clear();
|
||||
QList<QAudioFormat::Endian> endianz = deviceInfo.supportedByteOrders();
|
||||
for (int i = 0; i < endianz.size(); ++i)
|
||||
endianBox->addItem(toString(endianz.at(i)));
|
||||
if (endianz.size())
|
||||
settings.setByteOrder(endianz.at(0));
|
||||
|
||||
allFormatsTable->clearContents();
|
||||
}
|
||||
|
||||
void AudioTest::populateTable()
|
||||
{
|
||||
int row = 0;
|
||||
|
||||
QAudioFormat format;
|
||||
foreach (QString codec, deviceInfo.supportedCodecs()) {
|
||||
format.setCodec(codec);
|
||||
foreach (int frequency, deviceInfo.supportedFrequencies()) {
|
||||
format.setFrequency(frequency);
|
||||
foreach (int channels, deviceInfo.supportedChannels()) {
|
||||
format.setChannels(channels);
|
||||
foreach (QAudioFormat::SampleType sampleType, deviceInfo.supportedSampleTypes()) {
|
||||
format.setSampleType(sampleType);
|
||||
foreach (int sampleSize, deviceInfo.supportedSampleSizes()) {
|
||||
format.setSampleSize(sampleSize);
|
||||
foreach (QAudioFormat::Endian endian, deviceInfo.supportedByteOrders()) {
|
||||
format.setByteOrder(endian);
|
||||
if (deviceInfo.isFormatSupported(format)) {
|
||||
allFormatsTable->setRowCount(row + 1);
|
||||
|
||||
QTableWidgetItem *codecItem = new QTableWidgetItem(format.codec());
|
||||
allFormatsTable->setItem(row, 0, codecItem);
|
||||
|
||||
QTableWidgetItem *frequencyItem = new QTableWidgetItem(QString("%1").arg(format.frequency()));
|
||||
allFormatsTable->setItem(row, 1, frequencyItem);
|
||||
|
||||
QTableWidgetItem *channelsItem = new QTableWidgetItem(QString("%1").arg(format.channels()));
|
||||
allFormatsTable->setItem(row, 2, channelsItem);
|
||||
|
||||
QTableWidgetItem *sampleTypeItem = new QTableWidgetItem(toString(format.sampleType()));
|
||||
allFormatsTable->setItem(row, 3, sampleTypeItem);
|
||||
|
||||
QTableWidgetItem *sampleSizeItem = new QTableWidgetItem(QString("%1").arg(format.sampleSize()));
|
||||
allFormatsTable->setItem(row, 4, sampleSizeItem);
|
||||
|
||||
QTableWidgetItem *byteOrderItem = new QTableWidgetItem(toString(format.byteOrder()));
|
||||
allFormatsTable->setItem(row, 5, byteOrderItem);
|
||||
|
||||
++row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
83
examples/multimedia/audiodevices/audiodevices.h
Normal file
83
examples/multimedia/audiodevices/audiodevices.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef AUDIODEVICES_H
|
||||
#define AUDIODEVICES_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMainWindow>
|
||||
#include <QAudioDeviceInfo>
|
||||
|
||||
#include "ui_audiodevicesbase.h"
|
||||
|
||||
class AudioDevicesBase : public QMainWindow, public Ui::AudioDevicesBase
|
||||
{
|
||||
public:
|
||||
AudioDevicesBase(QWidget *parent = 0, Qt::WFlags f = 0);
|
||||
virtual ~AudioDevicesBase();
|
||||
};
|
||||
|
||||
class AudioTest : public AudioDevicesBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AudioTest(QWidget *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();
|
||||
void populateTable();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
17
examples/multimedia/audiodevices/audiodevices.pro
Normal file
17
examples/multimedia/audiodevices/audiodevices.pro
Normal file
@@ -0,0 +1,17 @@
|
||||
HEADERS = audiodevices.h
|
||||
SOURCES = audiodevices.cpp \
|
||||
main.cpp
|
||||
FORMS += audiodevicesbase.ui
|
||||
|
||||
QT += multimedia
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/qtmultimedia/multimedia/audiodevices
|
||||
sources.files = $$SOURCES *.h $$RESOURCES $$FORMS audiodevices.pro
|
||||
sources.path = $$[QT_INSTALL_EXAMPLES]/qtmultimedia/multimedia/audiodevices
|
||||
INSTALLS += target sources
|
||||
|
||||
symbian {
|
||||
TARGET.UID3 = 0xA000D7BE
|
||||
include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
|
||||
}
|
||||
399
examples/multimedia/audiodevices/audiodevicesbase.ui
Normal file
399
examples/multimedia/audiodevices/audiodevicesbase.ui
Normal file
@@ -0,0 +1,399 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AudioDevicesBase</class>
|
||||
<widget class="QMainWindow" name="AudioDevicesBase">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>679</width>
|
||||
<height>598</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Audio Devices</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>659</width>
|
||||
<height>558</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="modeLabel">
|
||||
<property name="text">
|
||||
<string>Mode</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="deviceLabel">
|
||||
<property name="text">
|
||||
<string>Device</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QComboBox" name="modeBox">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Input</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Output</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="deviceBox"/>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="testFormatTab">
|
||||
<attribute name="title">
|
||||
<string>Test format</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="actualLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><i>Actual Settings</i></string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::RichText</enum>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="nearestLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Nearest Settings</span></p></body></html></string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::RichText</enum>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="frequencyBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QLineEdit" name="nearestFreq">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QComboBox" name="channelsBox"/>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<widget class="QLineEdit" name="nearestChannel">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="1">
|
||||
<widget class="QComboBox" name="sampleSizesBox"/>
|
||||
</item>
|
||||
<item row="9" column="2">
|
||||
<widget class="QLineEdit" name="nearestSampleSize">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="14" column="1">
|
||||
<widget class="QComboBox" name="endianBox"/>
|
||||
</item>
|
||||
<item row="14" column="2">
|
||||
<widget class="QLineEdit" name="nearestEndian">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="15" column="1">
|
||||
<widget class="QPushButton" name="testButton">
|
||||
<property name="text">
|
||||
<string>Test</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="15" column="2">
|
||||
<widget class="QLabel" name="testResult">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="actualFreqLabel">
|
||||
<property name="text">
|
||||
<string>Frequency (Hz)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="actualChannelLabel">
|
||||
<property name="text">
|
||||
<string>Channels</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<widget class="QLabel" name="actualSampleSizeLabel">
|
||||
<property name="text">
|
||||
<string>Sample size (bits)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="14" column="0">
|
||||
<widget class="QLabel" name="actualEndianLabel">
|
||||
<property name="text">
|
||||
<string>Endianess</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="16" column="0" colspan="3">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Note: an invalid codec 'audio/test' exists in order to allow an invalid format to be constructed, and therefore to trigger a 'nearest format' calculation.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="actualCodecLabel">
|
||||
<property name="text">
|
||||
<string>Codec</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLineEdit" name="nearestCodec">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="codecsBox"/>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="actualSampleTypeLabel">
|
||||
<property name="text">
|
||||
<string>SampleType</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QComboBox" name="sampleTypesBox"/>
|
||||
</item>
|
||||
<item row="6" column="2">
|
||||
<widget class="QLineEdit" name="nearestSampleType">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>All formats</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="populateTableButton">
|
||||
<property name="text">
|
||||
<string>Populate table</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="allFormatsTable">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="dragDropOverwriteMode">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::NoSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectItems</enum>
|
||||
</property>
|
||||
<property name="textElideMode">
|
||||
<enum>Qt::ElideNone</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="cornerButtonEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderHighlightSections">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderHighlightSections">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderHighlightSections">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderHighlightSections">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Codec</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Frequency (Hz)</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Channels</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Sample type</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Sample size (bits)</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Endianness</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
58
examples/multimedia/audiodevices/main.cpp
Normal file
58
examples/multimedia/audiodevices/main.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#include "audiodevices.h"
|
||||
|
||||
int main(int argv, char **args)
|
||||
{
|
||||
QApplication app(argv, args);
|
||||
app.setApplicationName("Audio Device Test");
|
||||
|
||||
AudioTest audio;
|
||||
#ifdef Q_OS_SYMBIAN
|
||||
audio.showMaximized();
|
||||
#else
|
||||
audio.show();
|
||||
#endif
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
379
examples/multimedia/audioinput/audioinput.cpp
Normal file
379
examples/multimedia/audioinput/audioinput.cpp
Normal file
@@ -0,0 +1,379 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <QAudioDeviceInfo>
|
||||
#include <QAudioInput>
|
||||
|
||||
#include <QtCore/qendian.h>
|
||||
|
||||
#include "audioinput.h"
|
||||
|
||||
const QString InputTest::PushModeLabel(tr("Enable push mode"));
|
||||
const QString InputTest::PullModeLabel(tr("Enable pull mode"));
|
||||
const QString InputTest::SuspendLabel(tr("Suspend recording"));
|
||||
const QString InputTest::ResumeLabel(tr("Resume recording"));
|
||||
|
||||
const int BufferSize = 4096;
|
||||
|
||||
AudioInfo::AudioInfo(const QAudioFormat &format, QObject *parent)
|
||||
: QIODevice(parent)
|
||||
, m_format(format)
|
||||
, m_maxAmplitude(0)
|
||||
, m_level(0.0)
|
||||
|
||||
{
|
||||
switch (m_format.sampleSize()) {
|
||||
case 8:
|
||||
switch (m_format.sampleType()) {
|
||||
case QAudioFormat::UnSignedInt:
|
||||
m_maxAmplitude = 255;
|
||||
break;
|
||||
case QAudioFormat::SignedInt:
|
||||
m_maxAmplitude = 127;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 16:
|
||||
switch (m_format.sampleType()) {
|
||||
case QAudioFormat::UnSignedInt:
|
||||
m_maxAmplitude = 65535;
|
||||
break;
|
||||
case QAudioFormat::SignedInt:
|
||||
m_maxAmplitude = 32767;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (m_maxAmplitude) {
|
||||
Q_ASSERT(m_format.sampleSize() % 8 == 0);
|
||||
const int channelBytes = m_format.sampleSize() / 8;
|
||||
const int sampleBytes = m_format.channels() * channelBytes;
|
||||
Q_ASSERT(len % sampleBytes == 0);
|
||||
const int numSamples = len / sampleBytes;
|
||||
|
||||
quint16 maxValue = 0;
|
||||
const unsigned char *ptr = reinterpret_cast<const unsigned char *>(data);
|
||||
|
||||
for (int i = 0; i < numSamples; ++i) {
|
||||
for(int j = 0; j < m_format.channels(); ++j) {
|
||||
quint16 value = 0;
|
||||
|
||||
if (m_format.sampleSize() == 8 && m_format.sampleType() == QAudioFormat::UnSignedInt) {
|
||||
value = *reinterpret_cast<const quint8*>(ptr);
|
||||
} else if (m_format.sampleSize() == 8 && m_format.sampleType() == QAudioFormat::SignedInt) {
|
||||
value = qAbs(*reinterpret_cast<const qint8*>(ptr));
|
||||
} else if (m_format.sampleSize() == 16 && m_format.sampleType() == QAudioFormat::UnSignedInt) {
|
||||
if (m_format.byteOrder() == QAudioFormat::LittleEndian)
|
||||
value = qFromLittleEndian<quint16>(ptr);
|
||||
else
|
||||
value = qFromBigEndian<quint16>(ptr);
|
||||
} else if (m_format.sampleSize() == 16 && m_format.sampleType() == QAudioFormat::SignedInt) {
|
||||
if (m_format.byteOrder() == QAudioFormat::LittleEndian)
|
||||
value = qAbs(qFromLittleEndian<qint16>(ptr));
|
||||
else
|
||||
value = qAbs(qFromBigEndian<qint16>(ptr));
|
||||
}
|
||||
|
||||
maxValue = qMax(value, maxValue);
|
||||
ptr += channelBytes;
|
||||
}
|
||||
}
|
||||
|
||||
maxValue = qMin(maxValue, m_maxAmplitude);
|
||||
m_level = qreal(maxValue) / m_maxAmplitude;
|
||||
}
|
||||
|
||||
emit update();
|
||||
return len;
|
||||
}
|
||||
|
||||
RenderArea::RenderArea(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setBackgroundRole(QPalette::Base);
|
||||
setAutoFillBackground(true);
|
||||
|
||||
m_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 (m_level == 0.0)
|
||||
return;
|
||||
|
||||
painter.setPen(Qt::red);
|
||||
|
||||
int pos = ((painter.viewport().right()-20)-(painter.viewport().left()+11))*m_level;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
int x1 = painter.viewport().left()+11;
|
||||
int y1 = painter.viewport().top()+10+i;
|
||||
int x2 = painter.viewport().left()+20+pos;
|
||||
int 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(qreal value)
|
||||
{
|
||||
m_level = value;
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
InputTest::InputTest()
|
||||
: m_canvas(0)
|
||||
, m_modeButton(0)
|
||||
, m_suspendResumeButton(0)
|
||||
, m_deviceBox(0)
|
||||
, m_device(QAudioDeviceInfo::defaultInputDevice())
|
||||
, m_audioInfo(0)
|
||||
, m_audioInput(0)
|
||||
, m_input(0)
|
||||
, m_pullMode(false)
|
||||
, m_buffer(BufferSize, 0)
|
||||
{
|
||||
initializeWindow();
|
||||
initializeAudio();
|
||||
}
|
||||
|
||||
InputTest::~InputTest() {}
|
||||
|
||||
void InputTest::initializeWindow()
|
||||
{
|
||||
QScopedPointer<QWidget> window(new QWidget);
|
||||
QScopedPointer<QVBoxLayout> layout(new QVBoxLayout);
|
||||
|
||||
m_canvas = new RenderArea(this);
|
||||
layout->addWidget(m_canvas);
|
||||
|
||||
m_deviceBox = new QComboBox(this);
|
||||
QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
|
||||
for(int i = 0; i < devices.size(); ++i)
|
||||
m_deviceBox->addItem(devices.at(i).deviceName(), QVariant::fromValue(devices.at(i)));
|
||||
|
||||
connect(m_deviceBox, SIGNAL(activated(int)), SLOT(deviceChanged(int)));
|
||||
layout->addWidget(m_deviceBox);
|
||||
|
||||
m_modeButton = new QPushButton(this);
|
||||
m_modeButton->setText(PushModeLabel);
|
||||
connect(m_modeButton, SIGNAL(clicked()), SLOT(toggleMode()));
|
||||
layout->addWidget(m_modeButton);
|
||||
|
||||
m_suspendResumeButton = new QPushButton(this);
|
||||
m_suspendResumeButton->setText(SuspendLabel);
|
||||
connect(m_suspendResumeButton, SIGNAL(clicked()), SLOT(toggleSuspend()));
|
||||
layout->addWidget(m_suspendResumeButton);
|
||||
|
||||
window->setLayout(layout.data());
|
||||
layout.take(); // ownership transferred
|
||||
|
||||
setCentralWidget(window.data());
|
||||
QWidget *const windowPtr = window.take(); // ownership transferred
|
||||
windowPtr->show();
|
||||
}
|
||||
|
||||
void InputTest::initializeAudio()
|
||||
{
|
||||
m_pullMode = true;
|
||||
|
||||
m_format.setFrequency(8000);
|
||||
m_format.setChannels(1);
|
||||
m_format.setSampleSize(16);
|
||||
m_format.setSampleType(QAudioFormat::SignedInt);
|
||||
m_format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
m_format.setCodec("audio/pcm");
|
||||
|
||||
QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());
|
||||
if (!info.isFormatSupported(m_format)) {
|
||||
qWarning() << "Default format not supported - trying to use nearest";
|
||||
m_format = info.nearestFormat(m_format);
|
||||
}
|
||||
|
||||
m_audioInfo = new AudioInfo(m_format, this);
|
||||
connect(m_audioInfo, SIGNAL(update()), SLOT(refreshDisplay()));
|
||||
|
||||
createAudioInput();
|
||||
}
|
||||
|
||||
void InputTest::createAudioInput()
|
||||
{
|
||||
m_audioInput = new QAudioInput(m_device, m_format, this);
|
||||
connect(m_audioInput, SIGNAL(notify()), SLOT(notified()));
|
||||
connect(m_audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State)));
|
||||
m_audioInfo->start();
|
||||
m_audioInput->start(m_audioInfo);
|
||||
}
|
||||
|
||||
void InputTest::notified()
|
||||
{
|
||||
qWarning() << "bytesReady = " << m_audioInput->bytesReady()
|
||||
<< ", " << "elapsedUSecs = " <<m_audioInput->elapsedUSecs()
|
||||
<< ", " << "processedUSecs = "<<m_audioInput->processedUSecs();
|
||||
}
|
||||
|
||||
void InputTest::readMore()
|
||||
{
|
||||
if(!m_audioInput)
|
||||
return;
|
||||
qint64 len = m_audioInput->bytesReady();
|
||||
if(len > 4096)
|
||||
len = 4096;
|
||||
qint64 l = m_input->read(m_buffer.data(), len);
|
||||
if(l > 0) {
|
||||
m_audioInfo->write(m_buffer.constData(), l);
|
||||
}
|
||||
}
|
||||
|
||||
void InputTest::toggleMode()
|
||||
{
|
||||
// Change bewteen pull and push modes
|
||||
if (m_input != 0) {
|
||||
disconnect(m_input, 0, this, 0);
|
||||
m_input = 0;
|
||||
}
|
||||
|
||||
m_audioInput->stop();
|
||||
|
||||
if (m_pullMode) {
|
||||
m_modeButton->setText(PullModeLabel);
|
||||
m_input = m_audioInput->start();
|
||||
connect(m_input, SIGNAL(readyRead()), SLOT(readMore()));
|
||||
m_pullMode = false;
|
||||
} else {
|
||||
m_modeButton->setText(PushModeLabel);
|
||||
m_pullMode = true;
|
||||
m_audioInput->start(m_audioInfo);
|
||||
}
|
||||
|
||||
m_suspendResumeButton->setText(SuspendLabel);
|
||||
}
|
||||
|
||||
void InputTest::toggleSuspend()
|
||||
{
|
||||
// toggle suspend/resume
|
||||
if(m_audioInput->state() == QAudio::SuspendedState) {
|
||||
qWarning() << "status: Suspended, resume()";
|
||||
m_audioInput->resume();
|
||||
m_suspendResumeButton->setText(SuspendLabel);
|
||||
} else if (m_audioInput->state() == QAudio::ActiveState) {
|
||||
qWarning() << "status: Active, suspend()";
|
||||
m_audioInput->suspend();
|
||||
m_suspendResumeButton->setText(ResumeLabel);
|
||||
} else if (m_audioInput->state() == QAudio::StoppedState) {
|
||||
qWarning() << "status: Stopped, resume()";
|
||||
m_audioInput->resume();
|
||||
m_suspendResumeButton->setText(SuspendLabel);
|
||||
} else if (m_audioInput->state() == QAudio::IdleState) {
|
||||
qWarning() << "status: IdleState";
|
||||
}
|
||||
}
|
||||
|
||||
void InputTest::stateChanged(QAudio::State state)
|
||||
{
|
||||
qWarning() << "state = " << state;
|
||||
}
|
||||
|
||||
void InputTest::refreshDisplay()
|
||||
{
|
||||
m_canvas->setLevel(m_audioInfo->level());
|
||||
m_canvas->repaint();
|
||||
}
|
||||
|
||||
void InputTest::deviceChanged(int index)
|
||||
{
|
||||
m_audioInfo->stop();
|
||||
m_audioInput->stop();
|
||||
m_audioInput->disconnect(this);
|
||||
delete m_audioInput;
|
||||
|
||||
m_device = m_deviceBox->itemData(index).value<QAudioDeviceInfo>();
|
||||
createAudioInput();
|
||||
}
|
||||
139
examples/multimedia/audioinput/audioinput.h
Normal file
139
examples/multimedia/audioinput/audioinput.h
Normal file
@@ -0,0 +1,139 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef AUDIOINPUT_H
|
||||
#define AUDIOINPUT_H
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QWidget>
|
||||
#include <QObject>
|
||||
#include <QMainWindow>
|
||||
#include <QPushButton>
|
||||
#include <QComboBox>
|
||||
#include <QByteArray>
|
||||
|
||||
#include <qaudioinput.h>
|
||||
|
||||
class AudioInfo : public QIODevice
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AudioInfo(const QAudioFormat &format, QObject *parent);
|
||||
~AudioInfo();
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
qreal level() const { return m_level; }
|
||||
|
||||
qint64 readData(char *data, qint64 maxlen);
|
||||
qint64 writeData(const char *data, qint64 len);
|
||||
|
||||
private:
|
||||
const QAudioFormat m_format;
|
||||
quint16 m_maxAmplitude;
|
||||
qreal m_level; // 0.0 <= m_level <= 1.0
|
||||
|
||||
signals:
|
||||
void update();
|
||||
};
|
||||
|
||||
|
||||
class RenderArea : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RenderArea(QWidget *parent = 0);
|
||||
|
||||
void setLevel(qreal value);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
private:
|
||||
qreal m_level;
|
||||
QPixmap m_pixmap;
|
||||
};
|
||||
|
||||
class InputTest : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
InputTest();
|
||||
~InputTest();
|
||||
|
||||
private:
|
||||
void initializeWindow();
|
||||
void initializeAudio();
|
||||
void createAudioInput();
|
||||
|
||||
private slots:
|
||||
void refreshDisplay();
|
||||
void notified();
|
||||
void readMore();
|
||||
void toggleMode();
|
||||
void toggleSuspend();
|
||||
void stateChanged(QAudio::State state);
|
||||
void deviceChanged(int index);
|
||||
|
||||
private:
|
||||
// Owned by layout
|
||||
RenderArea *m_canvas;
|
||||
QPushButton *m_modeButton;
|
||||
QPushButton *m_suspendResumeButton;
|
||||
QComboBox *m_deviceBox;
|
||||
|
||||
QAudioDeviceInfo m_device;
|
||||
AudioInfo *m_audioInfo;
|
||||
QAudioFormat m_format;
|
||||
QAudioInput *m_audioInput;
|
||||
QIODevice *m_input;
|
||||
bool m_pullMode;
|
||||
QByteArray m_buffer;
|
||||
|
||||
static const QString PushModeLabel;
|
||||
static const QString PullModeLabel;
|
||||
static const QString SuspendLabel;
|
||||
static const QString ResumeLabel;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
17
examples/multimedia/audioinput/audioinput.pro
Normal file
17
examples/multimedia/audioinput/audioinput.pro
Normal file
@@ -0,0 +1,17 @@
|
||||
HEADERS = audioinput.h
|
||||
SOURCES = audioinput.cpp \
|
||||
main.cpp
|
||||
|
||||
QT += multimedia
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/qtmultimedia/multimedia/audioinput
|
||||
sources.files = $$SOURCES *.h $$RESOURCES $$FORMS audioinput.pro
|
||||
sources.path = $$[QT_INSTALL_EXAMPLES]/qtmultimedia/multimedia/audioinput
|
||||
INSTALLS += target sources
|
||||
|
||||
symbian {
|
||||
TARGET.UID3 = 0xA000D7BF
|
||||
TARGET.CAPABILITY += UserEnvironment
|
||||
include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
|
||||
}
|
||||
54
examples/multimedia/audioinput/main.cpp
Normal file
54
examples/multimedia/audioinput/main.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#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();
|
||||
}
|
||||
314
examples/multimedia/audiooutput/audiooutput.cpp
Normal file
314
examples/multimedia/audiooutput/audiooutput.cpp
Normal file
@@ -0,0 +1,314 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QDebug>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <QAudioOutput>
|
||||
#include <QAudioDeviceInfo>
|
||||
#include <QtCore/qmath.h>
|
||||
#include <QtCore/qendian.h>
|
||||
#include "audiooutput.h"
|
||||
|
||||
const QString AudioTest::PushModeLabel(tr("Enable push mode"));
|
||||
const QString AudioTest::PullModeLabel(tr("Enable pull mode"));
|
||||
const QString AudioTest::SuspendLabel(tr("Suspend playback"));
|
||||
const QString AudioTest::ResumeLabel(tr("Resume playback"));
|
||||
|
||||
const int DurationSeconds = 1;
|
||||
const int ToneFrequencyHz = 600;
|
||||
const int DataFrequencyHz = 44100;
|
||||
const int BufferSize = 32768;
|
||||
|
||||
|
||||
Generator::Generator(const QAudioFormat &format,
|
||||
qint64 durationUs,
|
||||
int frequency,
|
||||
QObject *parent)
|
||||
: QIODevice(parent)
|
||||
, m_pos(0)
|
||||
{
|
||||
generateData(format, durationUs, frequency);
|
||||
}
|
||||
|
||||
Generator::~Generator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Generator::start()
|
||||
{
|
||||
open(QIODevice::ReadOnly);
|
||||
}
|
||||
|
||||
void Generator::stop()
|
||||
{
|
||||
m_pos = 0;
|
||||
close();
|
||||
}
|
||||
|
||||
void Generator::generateData(const QAudioFormat &format, qint64 durationUs, int frequency)
|
||||
{
|
||||
const int channelBytes = format.sampleSize() / 8;
|
||||
const int sampleBytes = format.channels() * channelBytes;
|
||||
|
||||
qint64 length = (format.frequency() * format.channels() * (format.sampleSize() / 8))
|
||||
* durationUs / 100000;
|
||||
|
||||
Q_ASSERT(length % sampleBytes == 0);
|
||||
Q_UNUSED(sampleBytes) // suppress warning in release builds
|
||||
|
||||
m_buffer.resize(length);
|
||||
unsigned char *ptr = reinterpret_cast<unsigned char *>(m_buffer.data());
|
||||
int sampleIndex = 0;
|
||||
|
||||
while (length) {
|
||||
const qreal x = qSin(2 * M_PI * frequency * qreal(sampleIndex % format.frequency()) / format.frequency());
|
||||
for (int i=0; i<format.channels(); ++i) {
|
||||
if (format.sampleSize() == 8 && format.sampleType() == QAudioFormat::UnSignedInt) {
|
||||
const quint8 value = static_cast<quint8>((1.0 + x) / 2 * 255);
|
||||
*reinterpret_cast<quint8*>(ptr) = value;
|
||||
} else if (format.sampleSize() == 8 && format.sampleType() == QAudioFormat::SignedInt) {
|
||||
const qint8 value = static_cast<qint8>(x * 127);
|
||||
*reinterpret_cast<quint8*>(ptr) = value;
|
||||
} else if (format.sampleSize() == 16 && format.sampleType() == QAudioFormat::UnSignedInt) {
|
||||
quint16 value = static_cast<quint16>((1.0 + x) / 2 * 65535);
|
||||
if (format.byteOrder() == QAudioFormat::LittleEndian)
|
||||
qToLittleEndian<quint16>(value, ptr);
|
||||
else
|
||||
qToBigEndian<quint16>(value, ptr);
|
||||
} else if (format.sampleSize() == 16 && format.sampleType() == QAudioFormat::SignedInt) {
|
||||
qint16 value = static_cast<qint16>(x * 32767);
|
||||
if (format.byteOrder() == QAudioFormat::LittleEndian)
|
||||
qToLittleEndian<qint16>(value, ptr);
|
||||
else
|
||||
qToBigEndian<qint16>(value, ptr);
|
||||
}
|
||||
|
||||
ptr += channelBytes;
|
||||
length -= channelBytes;
|
||||
}
|
||||
++sampleIndex;
|
||||
}
|
||||
}
|
||||
|
||||
qint64 Generator::readData(char *data, qint64 len)
|
||||
{
|
||||
qint64 total = 0;
|
||||
while (len - total > 0) {
|
||||
const qint64 chunk = qMin((m_buffer.size() - m_pos), len - total);
|
||||
memcpy(data + total, m_buffer.constData() + m_pos, chunk);
|
||||
m_pos = (m_pos + chunk) % m_buffer.size();
|
||||
total += chunk;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
qint64 Generator::writeData(const char *data, qint64 len)
|
||||
{
|
||||
Q_UNUSED(data);
|
||||
Q_UNUSED(len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
qint64 Generator::bytesAvailable() const
|
||||
{
|
||||
return m_buffer.size() + QIODevice::bytesAvailable();
|
||||
}
|
||||
|
||||
AudioTest::AudioTest()
|
||||
: m_pullTimer(new QTimer(this))
|
||||
, m_modeButton(0)
|
||||
, m_suspendResumeButton(0)
|
||||
, m_deviceBox(0)
|
||||
, m_device(QAudioDeviceInfo::defaultOutputDevice())
|
||||
, m_generator(0)
|
||||
, m_audioOutput(0)
|
||||
, m_output(0)
|
||||
, m_buffer(BufferSize, 0)
|
||||
{
|
||||
initializeWindow();
|
||||
initializeAudio();
|
||||
}
|
||||
|
||||
void AudioTest::initializeWindow()
|
||||
{
|
||||
QScopedPointer<QWidget> window(new QWidget);
|
||||
QScopedPointer<QVBoxLayout> layout(new QVBoxLayout);
|
||||
|
||||
m_deviceBox = new QComboBox(this);
|
||||
foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput))
|
||||
m_deviceBox->addItem(deviceInfo.deviceName(), QVariant::fromValue(deviceInfo));
|
||||
connect(m_deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int)));
|
||||
layout->addWidget(m_deviceBox);
|
||||
|
||||
m_modeButton = new QPushButton(this);
|
||||
m_modeButton->setText(PushModeLabel);
|
||||
connect(m_modeButton, SIGNAL(clicked()), SLOT(toggleMode()));
|
||||
layout->addWidget(m_modeButton);
|
||||
|
||||
m_suspendResumeButton = new QPushButton(this);
|
||||
m_suspendResumeButton->setText(SuspendLabel);
|
||||
connect(m_suspendResumeButton, SIGNAL(clicked()), SLOT(toggleSuspendResume()));
|
||||
layout->addWidget(m_suspendResumeButton);
|
||||
|
||||
window->setLayout(layout.data());
|
||||
layout.take(); // ownership transferred
|
||||
|
||||
setCentralWidget(window.data());
|
||||
QWidget *const windowPtr = window.take(); // ownership transferred
|
||||
windowPtr->show();
|
||||
}
|
||||
|
||||
void AudioTest::initializeAudio()
|
||||
{
|
||||
connect(m_pullTimer, SIGNAL(timeout()), SLOT(pullTimerExpired()));
|
||||
|
||||
m_pullMode = true;
|
||||
|
||||
m_format.setFrequency(DataFrequencyHz);
|
||||
m_format.setChannels(1);
|
||||
m_format.setSampleSize(16);
|
||||
m_format.setCodec("audio/pcm");
|
||||
m_format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
m_format.setSampleType(QAudioFormat::SignedInt);
|
||||
|
||||
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
|
||||
if (!info.isFormatSupported(m_format)) {
|
||||
qWarning() << "Default format not supported - trying to use nearest";
|
||||
m_format = info.nearestFormat(m_format);
|
||||
}
|
||||
|
||||
m_generator = new Generator(m_format, DurationSeconds*1000000, ToneFrequencyHz, this);
|
||||
|
||||
createAudioOutput();
|
||||
}
|
||||
|
||||
void AudioTest::createAudioOutput()
|
||||
{
|
||||
delete m_audioOutput;
|
||||
m_audioOutput = 0;
|
||||
m_audioOutput = new QAudioOutput(m_device, m_format, this);
|
||||
connect(m_audioOutput, SIGNAL(notify()), SLOT(notified()));
|
||||
connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State)));
|
||||
m_generator->start();
|
||||
m_audioOutput->start(m_generator);
|
||||
}
|
||||
|
||||
AudioTest::~AudioTest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AudioTest::deviceChanged(int index)
|
||||
{
|
||||
m_pullTimer->stop();
|
||||
m_generator->stop();
|
||||
m_audioOutput->stop();
|
||||
m_audioOutput->disconnect(this);
|
||||
m_device = m_deviceBox->itemData(index).value<QAudioDeviceInfo>();
|
||||
createAudioOutput();
|
||||
}
|
||||
|
||||
void AudioTest::notified()
|
||||
{
|
||||
qWarning() << "bytesFree = " << m_audioOutput->bytesFree()
|
||||
<< ", " << "elapsedUSecs = " << m_audioOutput->elapsedUSecs()
|
||||
<< ", " << "processedUSecs = " << m_audioOutput->processedUSecs();
|
||||
}
|
||||
|
||||
void AudioTest::pullTimerExpired()
|
||||
{
|
||||
if (m_audioOutput && m_audioOutput->state() != QAudio::StoppedState) {
|
||||
int chunks = m_audioOutput->bytesFree()/m_audioOutput->periodSize();
|
||||
while (chunks) {
|
||||
const qint64 len = m_generator->read(m_buffer.data(), m_audioOutput->periodSize());
|
||||
if (len)
|
||||
m_output->write(m_buffer.data(), len);
|
||||
if (len != m_audioOutput->periodSize())
|
||||
break;
|
||||
--chunks;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AudioTest::toggleMode()
|
||||
{
|
||||
m_pullTimer->stop();
|
||||
m_audioOutput->stop();
|
||||
|
||||
if (m_pullMode) {
|
||||
m_modeButton->setText(PullModeLabel);
|
||||
m_output = m_audioOutput->start();
|
||||
m_pullMode = false;
|
||||
m_pullTimer->start(20);
|
||||
} else {
|
||||
m_modeButton->setText(PushModeLabel);
|
||||
m_pullMode = true;
|
||||
m_audioOutput->start(m_generator);
|
||||
}
|
||||
|
||||
m_suspendResumeButton->setText(SuspendLabel);
|
||||
}
|
||||
|
||||
void AudioTest::toggleSuspendResume()
|
||||
{
|
||||
if (m_audioOutput->state() == QAudio::SuspendedState) {
|
||||
qWarning() << "status: Suspended, resume()";
|
||||
m_audioOutput->resume();
|
||||
m_suspendResumeButton->setText(SuspendLabel);
|
||||
} else if (m_audioOutput->state() == QAudio::ActiveState) {
|
||||
qWarning() << "status: Active, suspend()";
|
||||
m_audioOutput->suspend();
|
||||
m_suspendResumeButton->setText(ResumeLabel);
|
||||
} else if (m_audioOutput->state() == QAudio::StoppedState) {
|
||||
qWarning() << "status: Stopped, resume()";
|
||||
m_audioOutput->resume();
|
||||
m_suspendResumeButton->setText(SuspendLabel);
|
||||
} else if (m_audioOutput->state() == QAudio::IdleState) {
|
||||
qWarning() << "status: IdleState";
|
||||
}
|
||||
}
|
||||
|
||||
void AudioTest::stateChanged(QAudio::State state)
|
||||
{
|
||||
qWarning() << "state = " << state;
|
||||
}
|
||||
122
examples/multimedia/audiooutput/audiooutput.h
Normal file
122
examples/multimedia/audiooutput/audiooutput.h
Normal file
@@ -0,0 +1,122 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef AUDIOOUTPUT_H
|
||||
#define AUDIOOUTPUT_H
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QMainWindow>
|
||||
#include <QIODevice>
|
||||
#include <QTimer>
|
||||
#include <QPushButton>
|
||||
#include <QComboBox>
|
||||
#include <QByteArray>
|
||||
|
||||
#include <QAudioOutput>
|
||||
|
||||
class Generator : public QIODevice
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Generator(const QAudioFormat &format, qint64 durationUs, int frequency, QObject *parent);
|
||||
~Generator();
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
qint64 readData(char *data, qint64 maxlen);
|
||||
qint64 writeData(const char *data, qint64 len);
|
||||
qint64 bytesAvailable() const;
|
||||
|
||||
private:
|
||||
void generateData(const QAudioFormat &format, qint64 durationUs, int frequency);
|
||||
|
||||
private:
|
||||
qint64 m_pos;
|
||||
QByteArray m_buffer;
|
||||
};
|
||||
|
||||
class AudioTest : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AudioTest();
|
||||
~AudioTest();
|
||||
|
||||
private:
|
||||
void initializeWindow();
|
||||
void initializeAudio();
|
||||
void createAudioOutput();
|
||||
|
||||
private:
|
||||
QTimer* m_pullTimer;
|
||||
|
||||
// Owned by layout
|
||||
QPushButton* m_modeButton;
|
||||
QPushButton* m_suspendResumeButton;
|
||||
QComboBox* m_deviceBox;
|
||||
|
||||
QAudioDeviceInfo m_device;
|
||||
Generator* m_generator;
|
||||
QAudioOutput* m_audioOutput;
|
||||
QIODevice* m_output; // not owned
|
||||
QAudioFormat m_format;
|
||||
|
||||
bool m_pullMode;
|
||||
QByteArray m_buffer;
|
||||
|
||||
static const QString PushModeLabel;
|
||||
static const QString PullModeLabel;
|
||||
static const QString SuspendLabel;
|
||||
static const QString ResumeLabel;
|
||||
|
||||
private slots:
|
||||
void notified();
|
||||
void pullTimerExpired();
|
||||
void toggleMode();
|
||||
void toggleSuspendResume();
|
||||
void stateChanged(QAudio::State state);
|
||||
void deviceChanged(int index);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
16
examples/multimedia/audiooutput/audiooutput.pro
Normal file
16
examples/multimedia/audiooutput/audiooutput.pro
Normal file
@@ -0,0 +1,16 @@
|
||||
HEADERS = audiooutput.h
|
||||
SOURCES = audiooutput.cpp \
|
||||
main.cpp
|
||||
|
||||
QT += multimedia
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/qtmultimedia/multimedia/audiooutput
|
||||
sources.files = $$SOURCES *.h $$RESOURCES $$FORMS audiooutput.pro
|
||||
sources.path = $$[QT_INSTALL_EXAMPLES]/qtmultimedia/multimedia/audiooutput
|
||||
INSTALLS += target sources
|
||||
|
||||
symbian {
|
||||
TARGET.UID3 = 0xA000D7C0
|
||||
include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
|
||||
}
|
||||
55
examples/multimedia/audiooutput/main.cpp
Normal file
55
examples/multimedia/audiooutput/main.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#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();
|
||||
}
|
||||
18
examples/multimedia/multimedia.pro
Normal file
18
examples/multimedia/multimedia.pro
Normal file
@@ -0,0 +1,18 @@
|
||||
TEMPLATE = subdirs
|
||||
|
||||
!static {
|
||||
SUBDIRS += \
|
||||
audiodevices \
|
||||
audioinput \
|
||||
audiooutput
|
||||
}
|
||||
|
||||
SUBDIRS += \
|
||||
videographicsitem \
|
||||
videowidget
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/qtmultimedia/multimedia
|
||||
sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS multimedia.pro README
|
||||
sources.path = $$[QT_INSTALL_EXAMPLES]/qtmultimedia/multimedia
|
||||
INSTALLS += target sources
|
||||
54
examples/multimedia/videographicsitem/main.cpp
Normal file
54
examples/multimedia/videographicsitem/main.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "videoplayer.h"
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
VideoPlayer player;
|
||||
player.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
21
examples/multimedia/videographicsitem/videographicsitem.pro
Normal file
21
examples/multimedia/videographicsitem/videographicsitem.pro
Normal file
@@ -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]/qtmultimedia/multimedia/videographicsitem
|
||||
sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png images
|
||||
sources.path = $$[QT_INSTALL_EXAMPLES]/qtmultimedia/multimedia/videographicsitem
|
||||
INSTALLS += target sources
|
||||
|
||||
symbian {
|
||||
TARGET.UID3 = 0xA000D7C2
|
||||
include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
|
||||
}
|
||||
143
examples/multimedia/videographicsitem/videoitem.cpp
Normal file
143
examples/multimedia/videographicsitem/videoitem.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "videoitem.h"
|
||||
|
||||
#include <QtMultimedia>
|
||||
|
||||
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<QVideoFrame::PixelFormat> VideoItem::supportedPixelFormats(
|
||||
QAbstractVideoBuffer::HandleType handleType) const
|
||||
{
|
||||
if (handleType == QAbstractVideoBuffer::NoHandle) {
|
||||
return QList<QVideoFrame::PixelFormat>()
|
||||
<< QVideoFrame::Format_RGB32
|
||||
<< QVideoFrame::Format_ARGB32
|
||||
<< QVideoFrame::Format_ARGB32_Premultiplied
|
||||
<< QVideoFrame::Format_RGB565
|
||||
<< QVideoFrame::Format_RGB555;
|
||||
} else {
|
||||
return QList<QVideoFrame::PixelFormat>();
|
||||
}
|
||||
}
|
||||
|
||||
bool VideoItem::start(const QVideoSurfaceFormat &format)
|
||||
{
|
||||
if (isFormatSupported(format)) {
|
||||
imageFormat = QVideoFrame::imageFormatFromPixelFormat(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 (!QAbstractVideoSurface::isActive())
|
||||
setError(StoppedError);
|
||||
|
||||
return false;
|
||||
} else {
|
||||
currentFrame = frame;
|
||||
framePainted = false;
|
||||
|
||||
update();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
78
examples/multimedia/videographicsitem/videoitem.h
Normal file
78
examples/multimedia/videographicsitem/videoitem.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef VIDEOITEM_H
|
||||
#define VIDEOITEM_H
|
||||
|
||||
#include <QtMultimedia/QAbstractVideoSurface>
|
||||
#include <QtGui/QGraphicsItem>
|
||||
|
||||
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<QVideoFrame::PixelFormat> 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
|
||||
|
||||
221
examples/multimedia/videographicsitem/videoplayer.cpp
Normal file
221
examples/multimedia/videographicsitem/videoplayer.cpp
Normal file
@@ -0,0 +1,221 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "videoplayer.h"
|
||||
#include "videoitem.h"
|
||||
|
||||
#include <QtMultimedia>
|
||||
|
||||
#ifndef QT_NO_OPENGL
|
||||
# include <QtOpenGL/QGLWidget>
|
||||
#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()
|
||||
{
|
||||
QStringList supportedFormats;
|
||||
foreach (QString fmt, QMovie::supportedFormats())
|
||||
supportedFormats << fmt;
|
||||
foreach (QString fmt, QImageReader::supportedImageFormats())
|
||||
supportedFormats << fmt;
|
||||
|
||||
QString filter = "Images (";
|
||||
foreach ( QString fmt, supportedFormats) {
|
||||
filter.append(QString("*.%1 ").arg(fmt));
|
||||
}
|
||||
filter.append(")");
|
||||
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie"),
|
||||
QDir::homePath(), filter);
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
85
examples/multimedia/videographicsitem/videoplayer.h
Normal file
85
examples/multimedia/videographicsitem/videoplayer.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef VIDEOPLAYER_H
|
||||
#define VIDEOPLAYER_H
|
||||
|
||||
#include <QtGui/QMovie>
|
||||
#include <QtGui/QWidget>
|
||||
|
||||
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
|
||||
|
||||
53
examples/multimedia/videowidget/main.cpp
Normal file
53
examples/multimedia/videowidget/main.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "videoplayer.h"
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
VideoPlayer player;
|
||||
player.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
194
examples/multimedia/videowidget/videoplayer.cpp
Normal file
194
examples/multimedia/videowidget/videoplayer.cpp
Normal file
@@ -0,0 +1,194 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "videoplayer.h"
|
||||
|
||||
#include "videowidget.h"
|
||||
|
||||
#include <QtMultimedia>
|
||||
|
||||
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()
|
||||
{
|
||||
QStringList supportedFormats;
|
||||
foreach (QString fmt, QMovie::supportedFormats())
|
||||
supportedFormats << fmt;
|
||||
foreach (QString fmt, QImageReader::supportedImageFormats())
|
||||
supportedFormats << fmt;
|
||||
|
||||
QString filter = "Images (";
|
||||
foreach ( QString fmt, supportedFormats) {
|
||||
filter.append(QString("*.%1 ").arg(fmt));
|
||||
}
|
||||
filter.append(")");
|
||||
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie"),
|
||||
QDir::homePath(), filter);
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
78
examples/multimedia/videowidget/videoplayer.h
Normal file
78
examples/multimedia/videowidget/videoplayer.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef VIDEOPLAYER_H
|
||||
#define VIDEOPLAYER_H
|
||||
|
||||
#include <QtGui/QMovie>
|
||||
#include <QtGui/QWidget>
|
||||
|
||||
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
|
||||
113
examples/multimedia/videowidget/videowidget.cpp
Normal file
113
examples/multimedia/videowidget/videowidget.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "videowidget.h"
|
||||
|
||||
#include "videowidgetsurface.h"
|
||||
|
||||
#include <QtMultimedia>
|
||||
|
||||
//! [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->isActive()) {
|
||||
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]
|
||||
75
examples/multimedia/videowidget/videowidget.h
Normal file
75
examples/multimedia/videowidget/videowidget.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef VIDEOWIDGET_H
|
||||
#define VIDEOWIDGET_H
|
||||
|
||||
#include "videowidgetsurface.h"
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
|
||||
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
|
||||
25
examples/multimedia/videowidget/videowidget.pro
Normal file
25
examples/multimedia/videowidget/videowidget.pro
Normal file
@@ -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]/qtmultimedia/multimedia/videowidget
|
||||
sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png images
|
||||
sources.path = $$[QT_INSTALL_EXAMPLES]/qtmultimedia/multimedia/videowidget
|
||||
INSTALLS += target sources
|
||||
|
||||
symbian {
|
||||
TARGET.UID3 = 0xA000D7C3
|
||||
include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
|
||||
}
|
||||
174
examples/multimedia/videowidget/videowidgetsurface.cpp
Normal file
174
examples/multimedia/videowidget/videowidgetsurface.cpp
Normal file
@@ -0,0 +1,174 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "videowidgetsurface.h"
|
||||
|
||||
#include <QtMultimedia>
|
||||
|
||||
VideoWidgetSurface::VideoWidgetSurface(QWidget *widget, QObject *parent)
|
||||
: QAbstractVideoSurface(parent)
|
||||
, widget(widget)
|
||||
, imageFormat(QImage::Format_Invalid)
|
||||
{
|
||||
}
|
||||
|
||||
//! [0]
|
||||
QList<QVideoFrame::PixelFormat> VideoWidgetSurface::supportedPixelFormats(
|
||||
QAbstractVideoBuffer::HandleType handleType) const
|
||||
{
|
||||
if (handleType == QAbstractVideoBuffer::NoHandle) {
|
||||
return QList<QVideoFrame::PixelFormat>()
|
||||
<< QVideoFrame::Format_RGB32
|
||||
<< QVideoFrame::Format_ARGB32
|
||||
<< QVideoFrame::Format_ARGB32_Premultiplied
|
||||
<< QVideoFrame::Format_RGB565
|
||||
<< QVideoFrame::Format_RGB555;
|
||||
} else {
|
||||
return QList<QVideoFrame::PixelFormat>();
|
||||
}
|
||||
}
|
||||
//! [0]
|
||||
|
||||
//! [1]
|
||||
bool VideoWidgetSurface::isFormatSupported(
|
||||
const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const
|
||||
{
|
||||
Q_UNUSED(similar);
|
||||
|
||||
const QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(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::imageFormatFromPixelFormat(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]
|
||||
80
examples/multimedia/videowidget/videowidgetsurface.h
Normal file
80
examples/multimedia/videowidget/videowidgetsurface.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 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:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||
** the names of its contributors may be used to endorse or promote
|
||||
** products derived from this software without specific prior written
|
||||
** permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef VIDEOWIDGETSURFACE_H
|
||||
#define VIDEOWIDGETSURFACE_H
|
||||
|
||||
#include <QtCore/QRect>
|
||||
#include <QtGui/QImage>
|
||||
#include <QtMultimedia/QAbstractVideoSurface>
|
||||
#include <QtMultimedia/QVideoFrame>
|
||||
|
||||
//! [0]
|
||||
class VideoWidgetSurface : public QAbstractVideoSurface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
VideoWidgetSurface(QWidget *widget, QObject *parent = 0);
|
||||
|
||||
QList<QVideoFrame::PixelFormat> 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
|
||||
Reference in New Issue
Block a user