summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.qmake.conf2
-rw-r--r--config.tests/opensles/main.cpp47
-rw-r--r--config.tests/opensles/opensles.pro2
-rw-r--r--qtmultimedia.pro1
-rw-r--r--src/gsttools/qgstreamerbushelper.cpp2
-rw-r--r--src/imports/multimedia/multimedia.cpp1
-rw-r--r--src/imports/multimedia/qdeclarativevideooutput.cpp50
-rw-r--r--src/imports/multimedia/qdeclarativevideooutput_p.h9
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp226
-rw-r--r--src/multimedia/audio/qaudiooutput_alsa_p.cpp2
-rw-r--r--src/multimedia/audio/qsamplecache_p.cpp2
-rw-r--r--src/multimedia/doc/qtmultimedia.qdocconf4
-rw-r--r--src/multimedia/doc/src/platform-notes-windows.qdoc2
-rw-r--r--src/multimedia/doc/src/qtmultimedia-cpp.qdoc1
-rw-r--r--src/multimedia/gsttools_headers/qgstxvimagebuffer_p.h3
-rw-r--r--src/multimedia/multimedia.pro5
-rw-r--r--src/multimedia/video/qvideooutputorientationhandler.cpp85
-rw-r--r--src/multimedia/video/qvideooutputorientationhandler_p.h72
-rw-r--r--src/multimedia/video/video.pri2
-rw-r--r--src/multimediawidgets/doc/qtmultimediawidgets.qdocconf3
-rw-r--r--src/multimediawidgets/doc/src/qtmultimediawidgets.qdoc1
-rw-r--r--src/multimediawidgets/multimediawidgets.pro8
-rw-r--r--src/multimediawidgets/qpaintervideosurface.cpp14
-rw-r--r--src/multimediawidgets/qpaintervideosurface_mac.mm289
-rw-r--r--src/plugins/avfoundation/avfoundation.pro4
-rw-r--r--src/plugins/avfoundation/camera/camera.pro10
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.mm16
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm8
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.h7
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm33
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideowidget.h47
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideowidget.mm193
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.h15
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.mm80
-rw-r--r--src/plugins/avfoundation/mediaplayer/mediaplayer.pro33
-rw-r--r--src/plugins/opensles/opensles.json3
-rw-r--r--src/plugins/opensles/opensles.pro25
-rw-r--r--src/plugins/opensles/qopenslesaudioinput.cpp505
-rw-r--r--src/plugins/opensles/qopenslesaudioinput.h134
-rw-r--r--src/plugins/opensles/qopenslesaudiooutput.cpp628
-rw-r--r--src/plugins/opensles/qopenslesaudiooutput.h155
-rw-r--r--src/plugins/opensles/qopenslesdeviceinfo.cpp115
-rw-r--r--src/plugins/opensles/qopenslesdeviceinfo.h77
-rw-r--r--src/plugins/opensles/qopenslesengine.cpp207
-rw-r--r--src/plugins/opensles/qopenslesengine.h (renamed from src/multimediawidgets/qpaintervideosurface_mac_p.h)62
-rw-r--r--src/plugins/opensles/qopenslesplugin.cpp78
-rw-r--r--src/plugins/opensles/qopenslesplugin.h72
-rw-r--r--src/plugins/plugins.pro11
-rw-r--r--src/plugins/pulseaudio/qaudioinput_pulse.h2
-rw-r--r--sync.profile1
50 files changed, 2551 insertions, 803 deletions
diff --git a/.qmake.conf b/.qmake.conf
index 89914d204..4baafa83d 100644
--- a/.qmake.conf
+++ b/.qmake.conf
@@ -1,4 +1,4 @@
load(qt_build_config)
CONFIG += qt_example_installs
-MODULE_VERSION = 5.1.2
+MODULE_VERSION = 5.2.0
diff --git a/config.tests/opensles/main.cpp b/config.tests/opensles/main.cpp
new file mode 100644
index 000000000..45fd2f05d
--- /dev/null
+++ b/config.tests/opensles/main.cpp
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <SLES/OpenSLES.h>
+
+int main()
+{
+ return 0;
+}
diff --git a/config.tests/opensles/opensles.pro b/config.tests/opensles/opensles.pro
new file mode 100644
index 000000000..def49c7ac
--- /dev/null
+++ b/config.tests/opensles/opensles.pro
@@ -0,0 +1,2 @@
+LIBS += -lOpenSLES
+SOURCES += main.cpp
diff --git a/qtmultimedia.pro b/qtmultimedia.pro
index 18c83c37b..d285c3cbc 100644
--- a/qtmultimedia.pro
+++ b/qtmultimedia.pro
@@ -2,6 +2,7 @@ requires(qtHaveModule(gui))
load(configure)
qtCompileTest(openal)
+qtCompileTest(opensles)
win32 {
qtCompileTest(directshow)
qtCompileTest(wmsdk)
diff --git a/src/gsttools/qgstreamerbushelper.cpp b/src/gsttools/qgstreamerbushelper.cpp
index 5ead1080c..da7506ec4 100644
--- a/src/gsttools/qgstreamerbushelper.cpp
+++ b/src/gsttools/qgstreamerbushelper.cpp
@@ -118,7 +118,9 @@ private:
guint m_tag;
GstBus* m_bus;
QGstreamerBusHelper* m_helper;
+#ifdef QT_NO_GLIB
QTimer* m_intervalTimer;
+#endif
private slots:
void doProcessMessage(const QGstreamerMessage& msg)
diff --git a/src/imports/multimedia/multimedia.cpp b/src/imports/multimedia/multimedia.cpp
index 92c9b257d..d2bc829db 100644
--- a/src/imports/multimedia/multimedia.cpp
+++ b/src/imports/multimedia/multimedia.cpp
@@ -76,6 +76,7 @@ public:
qmlRegisterType<QDeclarativeAudio>(uri, 5, 0, "Audio");
qmlRegisterType<QDeclarativeAudio>(uri, 5, 0, "MediaPlayer");
qmlRegisterType<QDeclarativeVideoOutput>(uri, 5, 0, "VideoOutput");
+ qmlRegisterType<QDeclarativeVideoOutput, 1>(uri, 5, 1, "VideoOutput");
qmlRegisterType<QDeclarativeRadio>(uri, 5, 0, "Radio");
qmlRegisterType<QDeclarativeRadioData>(uri, 5, 0, "RadioData");
qmlRegisterType<QDeclarativeCamera>(uri, 5, 0, "Camera");
diff --git a/src/imports/multimedia/qdeclarativevideooutput.cpp b/src/imports/multimedia/qdeclarativevideooutput.cpp
index 653d45b6d..53c810403 100644
--- a/src/imports/multimedia/qdeclarativevideooutput.cpp
+++ b/src/imports/multimedia/qdeclarativevideooutput.cpp
@@ -43,6 +43,7 @@
#include "qdeclarativevideooutput_render_p.h"
#include "qdeclarativevideooutput_window_p.h"
+#include <private/qvideooutputorientationhandler_p.h>
#include <QtMultimedia/qmediaobject.h>
#include <QtMultimedia/qmediaservice.h>
@@ -127,7 +128,9 @@ QDeclarativeVideoOutput::QDeclarativeVideoOutput(QQuickItem *parent) :
m_sourceType(NoSource),
m_fillMode(PreserveAspectFit),
m_geometryDirty(true),
- m_orientation(0)
+ m_orientation(0),
+ m_autoOrientation(false),
+ m_screenOrientationHandler(0)
{
setFlag(ItemHasContents, true);
}
@@ -349,6 +352,12 @@ void QDeclarativeVideoOutput::_q_updateGeometry()
if (m_contentRect != oldContentRect)
emit contentRectChanged();
}
+
+void QDeclarativeVideoOutput::_q_screenOrientationChanged(int orientation)
+{
+ setOrientation(orientation);
+}
+
/*!
\qmlproperty int QtMultimedia5::VideoOutput::orientation
@@ -411,6 +420,45 @@ void QDeclarativeVideoOutput::setOrientation(int orientation)
}
/*!
+ \qmlproperty int QtMultimedia5::VideoOutput::autoOrientation
+
+ This property allows you to enable and disable auto orientation
+ of the video stream, so that its orientation always matches
+ the orientation of the screen. If \c autoOrientation is enabled,
+ the \c orientation property is overwritten.
+
+ By default \c autoOrientation is disabled.
+
+ \since QtMultimedia 5.1
+*/
+bool QDeclarativeVideoOutput::autoOrientation() const
+{
+ return m_autoOrientation;
+}
+
+void QDeclarativeVideoOutput::setAutoOrientation(bool autoOrientation)
+{
+ if (autoOrientation == m_autoOrientation)
+ return;
+
+ m_autoOrientation = autoOrientation;
+ if (m_autoOrientation) {
+ m_screenOrientationHandler = new QVideoOutputOrientationHandler(this);
+ connect(m_screenOrientationHandler, SIGNAL(orientationChanged(int)),
+ this, SLOT(_q_screenOrientationChanged(int)));
+
+ _q_screenOrientationChanged(m_screenOrientationHandler->currentOrientation());
+ } else {
+ disconnect(m_screenOrientationHandler, SIGNAL(orientationChanged(int)),
+ this, SLOT(_q_screenOrientationChanged(int)));
+ m_screenOrientationHandler->deleteLater();
+ m_screenOrientationHandler = 0;
+ }
+
+ emit autoOrientationChanged();
+}
+
+/*!
\qmlproperty rectangle QtMultimedia5::VideoOutput::contentRect
This property holds the item coordinates of the area that
diff --git a/src/imports/multimedia/qdeclarativevideooutput_p.h b/src/imports/multimedia/qdeclarativevideooutput_p.h
index 51ceff9eb..1de1fccbc 100644
--- a/src/imports/multimedia/qdeclarativevideooutput_p.h
+++ b/src/imports/multimedia/qdeclarativevideooutput_p.h
@@ -53,6 +53,7 @@ QT_BEGIN_NAMESPACE
class QMediaObject;
class QMediaService;
class QDeclarativeVideoBackend;
+class QVideoOutputOrientationHandler;
class QDeclarativeVideoOutput : public QQuickItem
{
@@ -61,6 +62,7 @@ class QDeclarativeVideoOutput : public QQuickItem
Q_PROPERTY(QObject* source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
+ Q_PROPERTY(bool autoOrientation READ autoOrientation WRITE setAutoOrientation NOTIFY autoOrientationChanged REVISION 1)
Q_PROPERTY(QRectF sourceRect READ sourceRect NOTIFY sourceRectChanged)
Q_PROPERTY(QRectF contentRect READ contentRect NOTIFY contentRectChanged)
Q_ENUMS(FillMode)
@@ -85,6 +87,9 @@ public:
int orientation() const;
void setOrientation(int);
+ bool autoOrientation() const;
+ void setAutoOrientation(bool);
+
QRectF sourceRect() const;
QRectF contentRect() const;
@@ -108,6 +113,7 @@ Q_SIGNALS:
void sourceChanged();
void fillModeChanged(QDeclarativeVideoOutput::FillMode);
void orientationChanged();
+ void autoOrientationChanged();
void sourceRectChanged();
void contentRectChanged();
@@ -120,6 +126,7 @@ private Q_SLOTS:
void _q_updateMediaObject();
void _q_updateNativeSize();
void _q_updateGeometry();
+ void _q_screenOrientationChanged(int);
private:
bool createBackend(QMediaService *service);
@@ -137,6 +144,8 @@ private:
QRectF m_lastRect; // Cache of last rect to avoid recalculating geometry
QRectF m_contentRect; // Destination pixel coordinates, unclipped
int m_orientation;
+ bool m_autoOrientation;
+ QVideoOutputOrientationHandler *m_screenOrientationHandler;
QScopedPointer<QDeclarativeVideoBackend> m_backend;
};
diff --git a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp
index 9b9c3fb25..d2a4eea3a 100644
--- a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp
+++ b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp
@@ -197,23 +197,22 @@ bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const
{
// Set nearest to closest settings that do work.
// See if what is in settings will work (return value).
- int err = 0;
- snd_pcm_t* handle;
+ int err = -1;
+ snd_pcm_t* pcmHandle;
snd_pcm_hw_params_t *params;
- QString dev = device;
-
- QList<QByteArray> devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioOutput);
+ QString dev;
- if(dev.compare(QLatin1String("default")) == 0) {
#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
- dev = QLatin1String(devices.first().constData());
+ dev = device;
+ if (dev.compare(QLatin1String("default")) == 0) {
+ QList<QByteArray> devices = availableDevices(QAudio::AudioOutput);
+ if (!devices.isEmpty())
+ dev = QLatin1String(devices.first().constData());
+ }
#else
+ if (dev.compare(QLatin1String("default")) == 0) {
dev = QLatin1String("hw:0,0");
-#endif
} else {
-#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
- dev = device;
-#else
int idx = 0;
char *name;
@@ -225,156 +224,81 @@ bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const
idx++;
}
dev = QString(QLatin1String("hw:%1,0")).arg(idx);
-#endif
- }
- if(mode == QAudio::AudioOutput) {
- err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0);
- } else {
- err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0);
- }
- if(err < 0) {
- handle = 0;
- return false;
}
+#endif
- bool testChannel = false;
- bool testCodec = false;
- bool testSampleRate = false;
- bool testType = false;
- bool testSize = false;
+ snd_pcm_stream_t stream = mode == QAudio::AudioOutput
+ ? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE;
- int dir = 0;
+ if (snd_pcm_open(&pcmHandle, dev.toLocal8Bit().constData(), stream, 0) < 0)
+ return false;
- snd_pcm_nonblock( handle, 0 );
- snd_pcm_hw_params_alloca( &params );
- snd_pcm_hw_params_any( handle, params );
+ snd_pcm_nonblock(pcmHandle, 0);
+ snd_pcm_hw_params_alloca(&params);
+ snd_pcm_hw_params_any(pcmHandle, params);
// set the values!
- snd_pcm_hw_params_set_channels(handle,params,format.channelCount());
- snd_pcm_hw_params_set_rate(handle,params,format.sampleRate(),dir);
-
- err = -1;
-
- switch(format.sampleSize()) {
- case 8:
- if(format.sampleType() == QAudioFormat::SignedInt)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8);
- else if(format.sampleType() == QAudioFormat::UnSignedInt)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8);
- break;
- case 16:
- if(format.sampleType() == QAudioFormat::SignedInt) {
- if(format.byteOrder() == QAudioFormat::LittleEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE);
- else if(format.byteOrder() == QAudioFormat::BigEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE);
- } else if(format.sampleType() == QAudioFormat::UnSignedInt) {
- if(format.byteOrder() == QAudioFormat::LittleEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE);
- else if(format.byteOrder() == QAudioFormat::BigEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE);
- }
- break;
- case 32:
- if(format.sampleType() == QAudioFormat::SignedInt) {
- if(format.byteOrder() == QAudioFormat::LittleEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE);
- else if(format.byteOrder() == QAudioFormat::BigEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE);
- } else if(format.sampleType() == QAudioFormat::UnSignedInt) {
- if(format.byteOrder() == QAudioFormat::LittleEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE);
- else if(format.byteOrder() == QAudioFormat::BigEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE);
- } else if (format.sampleType() == QAudioFormat::Float) {
- if (format.byteOrder() == QAudioFormat::LittleEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_FLOAT_LE);
- else if (format.byteOrder() == QAudioFormat::BigEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_FLOAT_BE);
- }
+ snd_pcm_hw_params_set_channels(pcmHandle, params, format.channelCount());
+ snd_pcm_hw_params_set_rate(pcmHandle, params, format.sampleRate(), 0);
+
+ snd_pcm_format_t pcmFormat = SND_PCM_FORMAT_UNKNOWN;
+ switch (format.sampleSize()) {
+ case 8:
+ if (format.sampleType() == QAudioFormat::SignedInt)
+ pcmFormat = SND_PCM_FORMAT_S8;
+ else if (format.sampleType() == QAudioFormat::UnSignedInt)
+ pcmFormat = SND_PCM_FORMAT_U8;
+ break;
+ case 16:
+ if (format.sampleType() == QAudioFormat::SignedInt) {
+ pcmFormat = format.byteOrder() == QAudioFormat::LittleEndian
+ ? SND_PCM_FORMAT_S16_LE : SND_PCM_FORMAT_S16_BE;
+ } else if (format.sampleType() == QAudioFormat::UnSignedInt) {
+ pcmFormat = format.byteOrder() == QAudioFormat::LittleEndian
+ ? SND_PCM_FORMAT_U16_LE : SND_PCM_FORMAT_U16_BE;
+ }
+ break;
+ case 32:
+ if (format.sampleType() == QAudioFormat::SignedInt) {
+ pcmFormat = format.byteOrder() == QAudioFormat::LittleEndian
+ ? SND_PCM_FORMAT_S32_LE : SND_PCM_FORMAT_S32_BE;
+ } else if (format.sampleType() == QAudioFormat::UnSignedInt) {
+ pcmFormat = format.byteOrder() == QAudioFormat::LittleEndian
+ ? SND_PCM_FORMAT_U32_LE : SND_PCM_FORMAT_U32_BE;
+ } else if (format.sampleType() == QAudioFormat::Float) {
+ pcmFormat = format.byteOrder() == QAudioFormat::LittleEndian
+ ? SND_PCM_FORMAT_FLOAT_LE : SND_PCM_FORMAT_FLOAT_BE;
+ }
}
+ if (pcmFormat != SND_PCM_FORMAT_UNKNOWN)
+ err = snd_pcm_hw_params_set_format(pcmHandle, params, pcmFormat);
+
// For now, just accept only audio/pcm codec
- if(!format.codec().startsWith(QLatin1String("audio/pcm"))) {
- err=-1;
- } else
- testCodec = true;
-
- if (err>=0 && format.channelCount() != -1) {
- err = snd_pcm_hw_params_test_channels(handle,params,format.channelCount());
- if(err>=0)
- err = snd_pcm_hw_params_set_channels(handle,params,format.channelCount());
- if(err>=0)
- testChannel = true;
- }
+ if (!format.codec().startsWith(QLatin1String("audio/pcm")))
+ err = -1;
- if (err>=0 && format.sampleRate() != -1) {
- err = snd_pcm_hw_params_test_rate(handle,params,format.sampleRate(),0);
- if(err>=0)
- err = snd_pcm_hw_params_set_rate(handle,params,format.sampleRate(),dir);
- if(err>=0)
- testSampleRate = true;
+ if (err >= 0 && format.channelCount() != -1) {
+ err = snd_pcm_hw_params_test_channels(pcmHandle, params, format.channelCount());
+ if (err >= 0)
+ err = snd_pcm_hw_params_set_channels(pcmHandle, params, format.channelCount());
}
- if((err>=0 && format.sampleSize() != -1) &&
- (format.sampleType() != QAudioFormat::Unknown)) {
- switch(format.sampleSize()) {
- case 8:
- if(format.sampleType() == QAudioFormat::SignedInt)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8);
- else if(format.sampleType() == QAudioFormat::UnSignedInt)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8);
- break;
- case 16:
- if(format.sampleType() == QAudioFormat::SignedInt) {
- if(format.byteOrder() == QAudioFormat::LittleEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE);
- else if(format.byteOrder() == QAudioFormat::BigEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE);
- } else if(format.sampleType() == QAudioFormat::UnSignedInt) {
- if(format.byteOrder() == QAudioFormat::LittleEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE);
- else if(format.byteOrder() == QAudioFormat::BigEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE);
- }
- break;
- case 32:
- if(format.sampleType() == QAudioFormat::SignedInt) {
- if(format.byteOrder() == QAudioFormat::LittleEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE);
- else if(format.byteOrder() == QAudioFormat::BigEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE);
- } else if(format.sampleType() == QAudioFormat::UnSignedInt) {
- if(format.byteOrder() == QAudioFormat::LittleEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE);
- else if(format.byteOrder() == QAudioFormat::BigEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE);
- } else if (format.sampleType() == QAudioFormat::Float) {
- if (format.byteOrder() == QAudioFormat::LittleEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_FLOAT_LE);
- else if (format.byteOrder() == QAudioFormat::BigEndian)
- err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_FLOAT_BE);
- }
- }
- if(err>=0) {
- testSize = true;
- testType = true;
- }
- }
- if(err>=0)
- err = snd_pcm_hw_params(handle, params);
-
- if(err == 0) {
- // settings work
- // close()
- if(handle)
- snd_pcm_close(handle);
- return true;
+ if (err >= 0 && format.sampleRate() != -1) {
+ err = snd_pcm_hw_params_test_rate(pcmHandle, params, format.sampleRate(), 0);
+ if (err >= 0)
+ err = snd_pcm_hw_params_set_rate(pcmHandle, params, format.sampleRate(), 0);
}
- if(handle)
- snd_pcm_close(handle);
- return false;
+ if (err >= 0 && pcmFormat != SND_PCM_FORMAT_UNKNOWN)
+ err = snd_pcm_hw_params_set_format(pcmHandle, params, pcmFormat);
+
+ if (err >= 0)
+ err = snd_pcm_hw_params(pcmHandle, params);
+
+ snd_pcm_close(pcmHandle);
+
+ return (err == 0);
}
void QAudioDeviceInfoInternal::updateLists()
@@ -451,12 +375,10 @@ QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
devices.append(deviceName.toLocal8Bit().constData());
}
- free(name);
- if (descr != NULL)
- free(descr);
- if (io != NULL)
- free(io);
+ free(descr);
+ free(io);
}
+ free(name);
++n;
}
snd_device_name_free_hint(hints);
diff --git a/src/multimedia/audio/qaudiooutput_alsa_p.cpp b/src/multimedia/audio/qaudiooutput_alsa_p.cpp
index 1384dfdc5..3a779f322 100644
--- a/src/multimedia/audio/qaudiooutput_alsa_p.cpp
+++ b/src/multimedia/audio/qaudiooutput_alsa_p.cpp
@@ -125,7 +125,7 @@ void QAudioOutputPrivate::async_callback(snd_async_handler_t *ahandler)
audioOut = static_cast<QAudioOutputPrivate*>
(snd_async_handler_get_callback_private(ahandler));
- if((audioOut->deviceState==QAudio::ActiveState)||(audioOut->resuming))
+ if (audioOut && (audioOut->deviceState == QAudio::ActiveState || audioOut->resuming))
audioOut->feedback();
}
diff --git a/src/multimedia/audio/qsamplecache_p.cpp b/src/multimedia/audio/qsamplecache_p.cpp
index 03ed5710a..39e924f08 100644
--- a/src/multimedia/audio/qsamplecache_p.cpp
+++ b/src/multimedia/audio/qsamplecache_p.cpp
@@ -129,7 +129,7 @@ QSampleCache::~QSampleCache()
foreach (QSample* sample, m_staleSamples)
delete sample; // deleting a sample does affect the m_staleSamples list, but foreach copies it
- delete m_networkAccessManager;
+ m_networkAccessManager->deleteLater();
}
void QSampleCache::loadingRelease()
diff --git a/src/multimedia/doc/qtmultimedia.qdocconf b/src/multimedia/doc/qtmultimedia.qdocconf
index b78c91989..5f82a330b 100644
--- a/src/multimedia/doc/qtmultimedia.qdocconf
+++ b/src/multimedia/doc/qtmultimedia.qdocconf
@@ -44,3 +44,7 @@ sourcedirs += ../..
excludedirs += ../../multimediawidgets
depends += qtcore qtdoc qtquick qtqml qtmultimediawidgets
+
+navigation.landingpage = "Qt Multimedia"
+navigation.cppclassespage = "Qt Multimedia C++ Classes"
+navigation.qmltypespage = "Qt Multimedia QML Types"
diff --git a/src/multimedia/doc/src/platform-notes-windows.qdoc b/src/multimedia/doc/src/platform-notes-windows.qdoc
index 2f72ea1e0..d1ac8b6de 100644
--- a/src/multimedia/doc/src/platform-notes-windows.qdoc
+++ b/src/multimedia/doc/src/platform-notes-windows.qdoc
@@ -26,7 +26,7 @@
****************************************************************************/
/*!
-\page platform-notes-windows.html
+\page qtmultimedia-windows.html
\title Qt Multimedia on Windows
\brief Platform notes for Windows
diff --git a/src/multimedia/doc/src/qtmultimedia-cpp.qdoc b/src/multimedia/doc/src/qtmultimedia-cpp.qdoc
index a821088d8..b67163efe 100644
--- a/src/multimedia/doc/src/qtmultimedia-cpp.qdoc
+++ b/src/multimedia/doc/src/qtmultimedia-cpp.qdoc
@@ -29,6 +29,7 @@
\module QtMultimedia
\title Qt Multimedia C++ Classes
\ingroup modules
+ \qtvariable multimedia
\brief The \l {Qt Multimedia} module provides audio, video, radio and camera
functionality.
diff --git a/src/multimedia/gsttools_headers/qgstxvimagebuffer_p.h b/src/multimedia/gsttools_headers/qgstxvimagebuffer_p.h
index 52efee8a3..30cc4c993 100644
--- a/src/multimedia/gsttools_headers/qgstxvimagebuffer_p.h
+++ b/src/multimedia/gsttools_headers/qgstxvimagebuffer_p.h
@@ -74,7 +74,8 @@ QT_BEGIN_NAMESPACE
class QGstXvImageBufferPool;
-struct QGstXvImageBuffer {
+class QGstXvImageBuffer {
+public:
GstBuffer buffer;
QGstXvImageBufferPool *pool;
XvImage *xvImage;
diff --git a/src/multimedia/multimedia.pro b/src/multimedia/multimedia.pro
index 96b9e79ec..f1f4b3896 100644
--- a/src/multimedia/multimedia.pro
+++ b/src/multimedia/multimedia.pro
@@ -1,5 +1,5 @@
TARGET = QtMultimedia
-QT = core-private network gui
+QT = core-private network gui-private
QMAKE_DOCS = $$PWD/doc/qtmultimedia.qdocconf
@@ -63,9 +63,6 @@ ANDROID_BUNDLED_FILES += \
MODULE_PLUGIN_TYPES = \
mediaservice
-mac {
- LIBS += -framework AppKit -framework QuartzCore -framework QTKit
-}
win32:LIBS += -luuid
HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS
diff --git a/src/multimedia/video/qvideooutputorientationhandler.cpp b/src/multimedia/video/qvideooutputorientationhandler.cpp
new file mode 100644
index 000000000..4c966c02d
--- /dev/null
+++ b/src/multimedia/video/qvideooutputorientationhandler.cpp
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Research In Motion
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qvideooutputorientationhandler_p.h"
+
+#include <QGuiApplication>
+#include <QScreen>
+#include <qpa/qplatformscreen.h>
+
+QT_BEGIN_NAMESPACE
+
+QVideoOutputOrientationHandler::QVideoOutputOrientationHandler(QObject *parent)
+ : QObject(parent)
+ , m_currentOrientation(0)
+{
+ QScreen *screen = QGuiApplication::primaryScreen();
+
+ // we want to be informed about all orientation changes
+ screen->setOrientationUpdateMask(Qt::PortraitOrientation|Qt::LandscapeOrientation
+ |Qt::InvertedPortraitOrientation|Qt::InvertedLandscapeOrientation);
+
+ connect(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)),
+ this, SLOT(screenOrientationChanged(Qt::ScreenOrientation)));
+
+ screenOrientationChanged(screen->orientation());
+}
+
+int QVideoOutputOrientationHandler::currentOrientation() const
+{
+ return m_currentOrientation;
+}
+
+void QVideoOutputOrientationHandler::screenOrientationChanged(Qt::ScreenOrientation orientation)
+{
+ const QScreen *screen = QGuiApplication::primaryScreen();
+ const QPlatformScreen *platformScreen = screen->handle();
+
+ const int angle = (360 - screen->angleBetween(platformScreen->nativeOrientation(), orientation));
+
+ if (angle == m_currentOrientation)
+ return;
+
+ m_currentOrientation = angle;
+ emit orientationChanged(m_currentOrientation);
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/video/qvideooutputorientationhandler_p.h b/src/multimedia/video/qvideooutputorientationhandler_p.h
new file mode 100644
index 000000000..08a45c646
--- /dev/null
+++ b/src/multimedia/video/qvideooutputorientationhandler_p.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Research In Motion
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QVIDEOOUTPUTORIENTATIONHANDLER_P_H
+#define QVIDEOOUTPUTORIENTATIONHANDLER_P_H
+
+#include <qtmultimediadefs.h>
+
+#include <QObject>
+
+QT_BEGIN_NAMESPACE
+
+class Q_MULTIMEDIA_EXPORT QVideoOutputOrientationHandler : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QVideoOutputOrientationHandler(QObject *parent = 0);
+
+ int currentOrientation() const;
+
+signals:
+ void orientationChanged(int angle);
+
+private slots:
+ void screenOrientationChanged(Qt::ScreenOrientation orientation);
+
+private:
+ int m_currentOrientation;
+};
+
+QT_END_NAMESPACE
+
+
+#endif
diff --git a/src/multimedia/video/video.pri b/src/multimedia/video/video.pri
index 1eaed32c1..161163783 100644
--- a/src/multimedia/video/video.pri
+++ b/src/multimedia/video/video.pri
@@ -12,6 +12,7 @@ PRIVATE_HEADERS += \
video/qabstractvideobuffer_p.h \
video/qimagevideobuffer_p.h \
video/qmemoryvideobuffer_p.h \
+ video/qvideooutputorientationhandler_p.h \
video/qvideosurfaceoutput_p.h
SOURCES += \
@@ -20,6 +21,7 @@ SOURCES += \
video/qimagevideobuffer.cpp \
video/qmemoryvideobuffer.cpp \
video/qvideoframe.cpp \
+ video/qvideooutputorientationhandler.cpp \
video/qvideosurfaceformat.cpp \
video/qvideosurfaceoutput.cpp \
video/qvideoprobe.cpp
diff --git a/src/multimediawidgets/doc/qtmultimediawidgets.qdocconf b/src/multimediawidgets/doc/qtmultimediawidgets.qdocconf
index e44a73d77..5648041ad 100644
--- a/src/multimediawidgets/doc/qtmultimediawidgets.qdocconf
+++ b/src/multimediawidgets/doc/qtmultimediawidgets.qdocconf
@@ -40,3 +40,6 @@ sourcedirs += ../
excludedirs +=
depends += qtcore qtdoc qtquick qtqml qtmultimedia qtwidgets qtgui
+
+navigation.landingpage = "Qt Multimedia Widgets"
+navigation.cppclassespage = "Qt Multimedia Widgets C++ Classes"
diff --git a/src/multimediawidgets/doc/src/qtmultimediawidgets.qdoc b/src/multimediawidgets/doc/src/qtmultimediawidgets.qdoc
index cc64ed173..1df92d75f 100644
--- a/src/multimediawidgets/doc/src/qtmultimediawidgets.qdoc
+++ b/src/multimediawidgets/doc/src/qtmultimediawidgets.qdoc
@@ -29,6 +29,7 @@
\module QtMultimediaWidgets
\title Qt Multimedia Widgets C++ Classes
\brief Classes provided by the Qt Multimedia Widgets module.
+\qtvariable multimediawidgets
These classes are part of the \l{Qt Multimedia Widgets} module.
diff --git a/src/multimediawidgets/multimediawidgets.pro b/src/multimediawidgets/multimediawidgets.pro
index c6f214679..d47742028 100644
--- a/src/multimediawidgets/multimediawidgets.pro
+++ b/src/multimediawidgets/multimediawidgets.pro
@@ -28,14 +28,6 @@ SOURCES += \
qvideowidgetcontrol.cpp \
qvideowidget.cpp
-mac:!ios {
- !simulator {
- PRIVATE_HEADERS += qpaintervideosurface_mac_p.h
- OBJECTIVE_SOURCES += qpaintervideosurface_mac.mm
- }
- LIBS += -framework AppKit -framework QuartzCore -framework QTKit
-}
-
maemo6 {
contains(QT_CONFIG, opengles2) {
PRIVATE_HEADERS += qeglimagetexturesurface_p.h
diff --git a/src/multimediawidgets/qpaintervideosurface.cpp b/src/multimediawidgets/qpaintervideosurface.cpp
index e925f577f..8536ba4d1 100644
--- a/src/multimediawidgets/qpaintervideosurface.cpp
+++ b/src/multimediawidgets/qpaintervideosurface.cpp
@@ -40,7 +40,6 @@
****************************************************************************/
#include "qpaintervideosurface_p.h"
-#include "qpaintervideosurface_mac_p.h"
#include <qmath.h>
@@ -51,6 +50,7 @@
#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
#include <qglshaderprogram.h>
#include <QtGui/QOpenGLContext>
+#include <QtGui/QWindow>
#ifndef GL_CLAMP_TO_EDGE
#define GL_CLAMP_TO_EDGE 0x812F
#endif
@@ -1196,8 +1196,8 @@ QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::paint(
if (scissorTestEnabled)
glEnable(GL_SCISSOR_TEST);
- const int width = QGLContext::currentContext()->device()->width();
- const int height = QGLContext::currentContext()->device()->height();
+ const int width = QOpenGLContext::currentContext()->surface()->size().width();
+ const int height = QOpenGLContext::currentContext()->surface()->size().height();
const QTransform transform = painter->deviceTransform();
@@ -1667,14 +1667,6 @@ void QPainterVideoSurface::createPainter()
{
Q_ASSERT(!m_painter);
-#ifdef Q_OS_MAC
- if (m_glContext)
- m_glContext->makeCurrent();
-
- m_painter = new QVideoSurfaceCoreGraphicsPainter(m_glContext != 0);
- return;
-#endif
-
#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
switch (m_shaderType) {
#ifndef QT_OPENGL_ES
diff --git a/src/multimediawidgets/qpaintervideosurface_mac.mm b/src/multimediawidgets/qpaintervideosurface_mac.mm
deleted file mode 100644
index 9c076d041..000000000
--- a/src/multimediawidgets/qpaintervideosurface_mac.mm
+++ /dev/null
@@ -1,289 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <AppKit/AppKit.h>
-#include <QuartzCore/CIContext.h>
-#include <CGLCurrent.h>
-#include <OpenGL/gl.h>
-
-#include "qpaintervideosurface_mac_p.h"
-
-#include <QtCore/qdatetime.h>
-
-#include <qmath.h>
-
-#include <qpainter.h>
-#include <qvariant.h>
-#include <qvideosurfaceformat.h>
-
-#include <QtDebug>
-
-QT_BEGIN_NAMESPACE
-
-extern CGContextRef qt_mac_cg_context(const QPaintDevice *pdev); //qpaintdevice_mac.cpp
-
-QVideoSurfaceCoreGraphicsPainter::QVideoSurfaceCoreGraphicsPainter(bool glSupported)
- : ciContext(0)
- , m_imageFormat(QImage::Format_Invalid)
- , m_scanLineDirection(QVideoSurfaceFormat::TopToBottom)
-{
- //qDebug() << "QVideoSurfaceCoreGraphicsPainter, GL supported:" << glSupported;
- ciContext = 0;
- m_imagePixelFormats
- << QVideoFrame::Format_RGB32
- << QVideoFrame::Format_ARGB32
- << QVideoFrame::Format_ARGB32_Premultiplied
- << QVideoFrame::Format_BGR32
- << QVideoFrame::Format_RGB24
- << QVideoFrame::Format_RGB565
- << QVideoFrame::Format_RGB555
- << QVideoFrame::Format_ARGB8565_Premultiplied;
-
- m_supportedHandles
- << QAbstractVideoBuffer::NoHandle
- << QAbstractVideoBuffer::CoreImageHandle;
-
- if (glSupported)
- m_supportedHandles << QAbstractVideoBuffer::GLTextureHandle;
-}
-
-QVideoSurfaceCoreGraphicsPainter::~QVideoSurfaceCoreGraphicsPainter()
-{
- [(CIContext*)ciContext release];
-}
-
-QList<QVideoFrame::PixelFormat> QVideoSurfaceCoreGraphicsPainter::supportedPixelFormats(
- QAbstractVideoBuffer::HandleType handleType) const
-{
- return m_supportedHandles.contains(handleType)
- ? m_imagePixelFormats
- : QList<QVideoFrame::PixelFormat>();
-}
-
-bool QVideoSurfaceCoreGraphicsPainter::isFormatSupported(const QVideoSurfaceFormat &format) const
-{
- return m_supportedHandles.contains(format.handleType())
- && m_imagePixelFormats.contains(format.pixelFormat())
- && !format.frameSize().isEmpty();
-}
-
-QAbstractVideoSurface::Error QVideoSurfaceCoreGraphicsPainter::start(const QVideoSurfaceFormat &format)
-{
- m_frame = QVideoFrame();
- m_imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat());
- m_imageSize = format.frameSize();
- m_scanLineDirection = format.scanLineDirection();
-
- return m_supportedHandles.contains(format.handleType())
- && ((m_imageFormat != QImage::Format_Invalid) || (format.handleType() == QAbstractVideoBuffer::GLTextureHandle))
- && !m_imageSize.isEmpty()
- ? QAbstractVideoSurface::NoError
- : QAbstractVideoSurface::UnsupportedFormatError;
-}
-
-void QVideoSurfaceCoreGraphicsPainter::stop()
-{
- m_frame = QVideoFrame();
-}
-
-QAbstractVideoSurface::Error QVideoSurfaceCoreGraphicsPainter::setCurrentFrame(const QVideoFrame &frame)
-{
- m_frame = frame;
-
- return QAbstractVideoSurface::NoError;
-}
-
-QAbstractVideoSurface::Error QVideoSurfaceCoreGraphicsPainter::paint(
- const QRectF &target, QPainter *painter, const QRectF &source)
-{
- if (m_frame.handleType() == QAbstractVideoBuffer::CoreImageHandle) {
-//Non OpenGL CI rendering is disabled for now since qt_mac_cg_context is moved to platform plugin
-#ifdef ENABLE_CORE_GRAPHICS_VIDEO_RENDERING
- if (painter->paintEngine()->type() == QPaintEngine::CoreGraphics ) {
-
- CIImage *img = (CIImage*)(m_frame.handle().value<void*>());
-
- if (img) {
- CGContextRef cgContext = qt_mac_cg_context(painter->device());
-
- if (cgContext) {
- painter->beginNativePainting();
-
- CGRect sRect = CGRectMake(source.x(), source.y(), source.width(), source.height());
- CGRect dRect = CGRectMake(target.x(), target.y(), target.width(), target.height());
-
- NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCIImage:img];
-
- if (m_scanLineDirection == QVideoSurfaceFormat::TopToBottom) {
- CGContextSaveGState( cgContext );
- CGContextTranslateCTM(cgContext, 0, dRect.origin.y + CGRectGetMaxY(dRect));
- CGContextScaleCTM(cgContext, 1, -1);
-
- CGContextDrawImage(cgContext, dRect, [bitmap CGImage]);
-
- CGContextRestoreGState(cgContext);
- } else {
- CGContextDrawImage(cgContext, dRect, [bitmap CGImage]);
- }
-
- [bitmap release];
-
- painter->endNativePainting();
-
- return QAbstractVideoSurface::NoError;
- }
- }
- } else
-#endif
- if (painter->paintEngine()->type() == QPaintEngine::OpenGL2 ||
- painter->paintEngine()->type() == QPaintEngine::OpenGL) {
- CIImage *img = (CIImage*)(m_frame.handle().value<void*>());
-
- if (img) {
- CGLContextObj cglContext = CGLGetCurrentContext();
-
- if (cglContext) {
-
- if (!ciContext) {
- CGLContextObj cglContext = CGLGetCurrentContext();
- NSOpenGLPixelFormat *nsglPixelFormat = [NSOpenGLView defaultPixelFormat];
- CGLPixelFormatObj cglPixelFormat = static_cast<CGLPixelFormatObj>([nsglPixelFormat CGLPixelFormatObj]);
-
- ciContext = [CIContext contextWithCGLContext:cglContext
- pixelFormat:cglPixelFormat
- options:nil];
-
- [(CIContext*)ciContext retain];
- }
-
- CGRect sRect = CGRectMake(source.x(), source.y(), source.width(), source.height());
- CGRect dRect = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom ?
- CGRectMake(target.x(), target.y()+target.height(), target.width(), -target.height()) :
- CGRectMake(target.x(), target.y(), target.width(), target.height());
-
-
- painter->beginNativePainting();
-
- [(CIContext*)ciContext drawImage:img inRect:dRect fromRect:sRect];
-
- painter->endNativePainting();
-
- return QAbstractVideoSurface::NoError;
- }
- }
- }
- }
-
- if (m_frame.handleType() == QAbstractVideoBuffer::GLTextureHandle &&
- (painter->paintEngine()->type() == QPaintEngine::OpenGL2 ||
- painter->paintEngine()->type() == QPaintEngine::OpenGL)) {
-
- painter->beginNativePainting();
- GLuint texture = m_frame.handle().toUInt();
-
- glDisable(GL_CULL_FACE);
- glEnable(GL_TEXTURE_2D);
-
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- const float txLeft = source.left() / m_frame.width();
- const float txRight = source.right() / m_frame.width();
- const float txTop = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom
- ? source.top() / m_frame.height()
- : source.bottom() / m_frame.height();
- const float txBottom = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom
- ? source.bottom() / m_frame.height()
- : source.top() / m_frame.height();
-
- glBegin(GL_QUADS);
- QRectF rect = target;
- glTexCoord2f(txLeft, txBottom);
- glVertex2f(rect.topLeft().x(), rect.topLeft().y());
- glTexCoord2f(txRight, txBottom);
- glVertex2f(rect.topRight().x() + 1, rect.topRight().y());
- glTexCoord2f(txRight, txTop);
- glVertex2f(rect.bottomRight().x() + 1, rect.bottomRight().y() + 1);
- glTexCoord2f(txLeft, txTop);
- glVertex2f(rect.bottomLeft().x(), rect.bottomLeft().y() + 1);
- glEnd();
- painter->endNativePainting();
-
- return QAbstractVideoSurface::NoError;
- }
-
- //fallback case, software rendering
- if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) {
- QImage image(
- m_frame.bits(),
- m_imageSize.width(),
- m_imageSize.height(),
- m_frame.bytesPerLine(),
- m_imageFormat);
-
- if (m_scanLineDirection == QVideoSurfaceFormat::BottomToTop) {
- const QTransform oldTransform = painter->transform();
-
- painter->scale(1, -1);
- painter->translate(0, -target.bottom());
- painter->drawImage(
- QRectF(target.x(), 0, target.width(), target.height()), image, source);
- painter->setTransform(oldTransform);
- } else {
- painter->drawImage(target, image, source);
- }
-
- m_frame.unmap();
- } else if (m_frame.isValid()) {
- return QAbstractVideoSurface::IncorrectFormatError;
- } else {
- painter->fillRect(target, Qt::black);
- }
-
- return QAbstractVideoSurface::NoError;
-}
-
-void QVideoSurfaceCoreGraphicsPainter::updateColors(int, int, int, int)
-{
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/avfoundation/avfoundation.pro b/src/plugins/avfoundation/avfoundation.pro
index 7f2ddb2fa..c05331d20 100644
--- a/src/plugins/avfoundation/avfoundation.pro
+++ b/src/plugins/avfoundation/avfoundation.pro
@@ -1,4 +1,4 @@
TEMPLATE = subdirs
-SUBDIRS += camera \
- mediaplayer
+SUBDIRS += mediaplayer \
+ camera
diff --git a/src/plugins/avfoundation/camera/camera.pro b/src/plugins/avfoundation/camera/camera.pro
index 3c7511715..791ab8c48 100644
--- a/src/plugins/avfoundation/camera/camera.pro
+++ b/src/plugins/avfoundation/camera/camera.pro
@@ -8,10 +8,14 @@ PLUGIN_TYPE = mediaservice
PLUGIN_CLASS_NAME = AVFServicePlugin
load(qt_plugin)
-LIBS += -framework AppKit -framework AudioUnit \
- -framework AudioToolbox -framework CoreAudio \
- -framework QuartzCore -framework AVFoundation \
+LIBS += -framework AudioToolbox \
+ -framework CoreAudio \
+ -framework QuartzCore \
+ -framework AVFoundation \
-framework CoreMedia
+osx:LIBS += -framework AppKit \
+ -framework AudioUnit
+ios:LIBS += -framework CoreVideo
OTHER_FILES += avfcamera.json
diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.mm b/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.mm
index b916f47d4..398f00e2f 100644
--- a/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.mm
+++ b/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.mm
@@ -43,11 +43,12 @@
#include "avfmediaplayersession.h"
#include "avfmediaplayercontrol.h"
#include "avfmediaplayermetadatacontrol.h"
-#include "avfvideooutput.h"
-#include "avfvideorenderercontrol.h"
-
+#if defined(Q_OS_OSX)
+# include "avfvideooutput.h"
+# include "avfvideorenderercontrol.h"
+#endif
#ifndef QT_NO_WIDGETS
-#include "avfvideowidgetcontrol.h"
+# include "avfvideowidgetcontrol.h"
#endif
QT_USE_NAMESPACE
@@ -83,7 +84,7 @@ QMediaControl *AVFMediaPlayerService::requestControl(const char *name)
if (qstrcmp(name, QMetaDataReaderControl_iid) == 0)
return m_playerMetaDataControl;
-
+#if defined(Q_OS_OSX)
if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
if (!m_videoOutput)
m_videoOutput = new AVFVideoRendererControl(this);
@@ -91,6 +92,7 @@ QMediaControl *AVFMediaPlayerService::requestControl(const char *name)
m_session->setVideoOutput(qobject_cast<AVFVideoOutput*>(m_videoOutput));
return m_videoOutput;
}
+#endif
#ifndef QT_NO_WIDGETS
if (qstrcmp(name, QVideoWidgetControl_iid) == 0) {
if (!m_videoOutput)
@@ -100,7 +102,6 @@ QMediaControl *AVFMediaPlayerService::requestControl(const char *name)
return m_videoOutput;
}
#endif
-
return 0;
}
@@ -109,7 +110,7 @@ void AVFMediaPlayerService::releaseControl(QMediaControl *control)
#ifdef QT_DEBUG_AVF
qDebug() << Q_FUNC_INFO << control;
#endif
-
+#if defined(Q_OS_OSX)
if (m_videoOutput == control) {
AVFVideoRendererControl *renderControl = qobject_cast<AVFVideoRendererControl*>(m_videoOutput);
if (renderControl)
@@ -118,4 +119,5 @@ void AVFMediaPlayerService::releaseControl(QMediaControl *control)
m_session->setVideoOutput(0);
delete control;
}
+#endif
}
diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm
index 7af6f4394..bb2bc75cb 100644
--- a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm
+++ b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm
@@ -240,9 +240,11 @@ static void *AVFMediaPlayerSessionObserverCurrentItemObservationContext = &AVFMe
m_player = [AVPlayer playerWithPlayerItem:m_playerItem];
[m_player retain];
+#if defined(Q_OS_OSX)
//Set the initial volume on new player object
if (self.session)
m_player.volume = m_session->volume() / 100.0f;
+#endif
//Create a new player layer if we don't have one already
if (!m_playerLayer)
@@ -735,10 +737,12 @@ void AVFMediaPlayerSession::setVolume(int volume)
m_volume = volume;
+#if defined(Q_OS_OSX)
AVPlayer *player = [(AVFMediaPlayerSessionObserver*)m_observer player];
if (player) {
[[(AVFMediaPlayerSessionObserver*)m_observer player] setVolume:m_volume / 100.0f];
}
+#endif
Q_EMIT volumeChanged(m_volume);
}
@@ -752,9 +756,9 @@ void AVFMediaPlayerSession::setMuted(bool muted)
return;
m_muted = muted;
-
+#if defined(Q_OS_OSX)
[[(AVFMediaPlayerSessionObserver*)m_observer player] setMuted:m_muted];
-
+#endif
Q_EMIT mutedChanged(muted);
}
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.h b/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.h
index 5b52e8e53..b33974759 100644
--- a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.h
+++ b/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.h
@@ -56,15 +56,11 @@ class QOpenGLFramebufferObject;
class QWindow;
class QOpenGLContext;
class QAbstractVideoSurface;
-class QGLWidget;
class AVFVideoFrameRenderer : public QObject
{
public:
AVFVideoFrameRenderer(QAbstractVideoSurface *surface, QObject *parent = 0);
-#ifndef QT_NO_WIDGETS
- AVFVideoFrameRenderer(QGLWidget *glWidget, const QSize &size, QObject *parent = 0);
-#endif
virtual ~AVFVideoFrameRenderer();
@@ -76,9 +72,6 @@ private:
void renderLayerToFBO(AVPlayerLayer *layer, QOpenGLFramebufferObject *fbo);
CARenderer *m_videoLayerRenderer;
-#ifndef QT_NO_WIDGETS
- QGLWidget *m_glWidget;
-#endif
QAbstractVideoSurface *m_surface;
QOpenGLFramebufferObject *m_fbo[2];
QWindow *m_offscreenSurface;
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm b/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm
index 210dd568b..fb63392bb 100644
--- a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm
+++ b/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm
@@ -45,10 +45,6 @@
#include <QtGui/QOpenGLFramebufferObject>
#include <QtGui/QWindow>
-#ifndef QT_NO_WIDGETS
-#include <QtOpenGL/QGLWidget>
-#endif
-
#ifdef QT_DEBUG_AVF
#include <QtCore/qdebug.h>
#endif
@@ -76,31 +72,6 @@ AVFVideoFrameRenderer::AVFVideoFrameRenderer(QAbstractVideoSurface *surface, QOb
m_offscreenSurface->setGeometry(0, 0, 1, 1);
m_offscreenSurface->create();
}
-#ifndef QT_NO_WIDGETS
-AVFVideoFrameRenderer::AVFVideoFrameRenderer(QGLWidget *glWidget, const QSize &size, QObject *parent)
- : QObject(parent)
- , m_videoLayerRenderer(0)
- , m_glWidget(glWidget)
- , m_surface(0)
- , m_offscreenSurface(0)
- , m_glContext(0)
- , m_targetSize(size)
- , m_currentBuffer(1)
- , m_isContextShared(true)
-{
- m_fbo[0] = 0;
- m_fbo[1] = 0;
-
- //Create Hidden QWindow surface to create context in this thread
- m_offscreenSurface = new QWindow();
- m_offscreenSurface->setSurfaceType(QWindow::OpenGLSurface);
- //Needs geometry to be a valid surface, but size is not important
- m_offscreenSurface->setGeometry(0, 0, 1, 1);
- m_offscreenSurface->create();
-
-
-}
-#endif
AVFVideoFrameRenderer::~AVFVideoFrameRenderer()
{
@@ -168,10 +139,6 @@ QOpenGLFramebufferObject *AVFVideoFrameRenderer::initRenderer(AVPlayerLayer *lay
if (m_surface) {
//QOpenGLContext *renderThreadContext = 0;
shareContext = qobject_cast<QOpenGLContext*>(m_surface->property("GLContext").value<QObject*>());
-#ifndef QT_NO_WIDGETS
- } else {
- shareContext = m_glWidget->context()->contextHandle();
-#endif
}
m_glContext = new QOpenGLContext();
m_glContext->setFormat(m_offscreenSurface->requestedFormat());
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideowidget.h b/src/plugins/avfoundation/mediaplayer/avfvideowidget.h
index 460d5305e..12b8c26b1 100644
--- a/src/plugins/avfoundation/mediaplayer/avfvideowidget.h
+++ b/src/plugins/avfoundation/mediaplayer/avfvideowidget.h
@@ -42,43 +42,44 @@
#ifndef AVFVIDEOWIDGET_H
#define AVFVIDEOWIDGET_H
-#include <QtOpenGL/QGLWidget>
-#include <QtGui/QMatrix4x4>
+#include <QtWidgets/QWidget>
-QT_BEGIN_NAMESPACE
+@class AVPlayerLayer;
+#if defined(Q_OS_OSX)
+@class NSView;
+#else
+@class UIView;
+#endif
-class QOpenGLShaderProgram;
+QT_BEGIN_NAMESPACE
-class AVFVideoWidget : public QGLWidget
+class AVFVideoWidget : public QWidget
{
public:
- AVFVideoWidget(QWidget *parent, const QGLFormat &format);
+ AVFVideoWidget(QWidget *parent);
virtual ~AVFVideoWidget();
- void initializeGL();
- void resizeGL(int w, int h);
- void paintGL();
-
- void setTexture(GLuint texture);
-
QSize sizeHint() const;
- void setNativeSize(const QSize &size);
-
+ Qt::AspectRatioMode aspectRatioMode() const;
void setAspectRatioMode(Qt::AspectRatioMode mode);
+ void setPlayerLayer(AVPlayerLayer *layer);
+
+protected:
+ void resizeEvent(QResizeEvent *);
+ void paintEvent(QPaintEvent *);
private:
- QRect displayRect() const;
+ void updateAspectRatio();
+ void updatePlayerLayerBounds(const QSize &size);
- GLuint m_textureId;
QSize m_nativeSize;
Qt::AspectRatioMode m_aspectRatioMode;
-
- QOpenGLShaderProgram *m_shaderProgram;
- QMatrix4x4 m_transformMatrix;
-
- int m_matrixLocation;
- int m_vertexCoordEntry;
- int m_textureCoordEntry;
+ AVPlayerLayer *m_playerLayer;
+#if defined(Q_OS_OSX)
+ NSView *m_nativeView;
+#else
+ UIView *m_nativeView;
+#endif
};
QT_END_NAMESPACE
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideowidget.mm b/src/plugins/avfoundation/mediaplayer/avfvideowidget.mm
index 518a6bcea..2e4de37f1 100644
--- a/src/plugins/avfoundation/mediaplayer/avfvideowidget.mm
+++ b/src/plugins/avfoundation/mediaplayer/avfvideowidget.mm
@@ -41,15 +41,19 @@
#include "avfvideowidget.h"
#include <QtCore/QDebug>
-#include <QtGui/QOpenGLShaderProgram>
+
+#include <AVFoundation/AVFoundation.h>
+#include <QtGui/QResizeEvent>
+#include <QtGui/QPaintEvent>
+#include <QtGui/QPainter>
QT_USE_NAMESPACE
-AVFVideoWidget::AVFVideoWidget(QWidget *parent, const QGLFormat &format)
- : QGLWidget(format, parent)
- , m_textureId(0)
+AVFVideoWidget::AVFVideoWidget(QWidget *parent)
+ : QWidget(parent)
, m_aspectRatioMode(Qt::KeepAspectRatio)
- , m_shaderProgram(0)
+ , m_playerLayer(0)
+ , m_nativeView(0)
{
setAutoFillBackground(false);
}
@@ -59,143 +63,114 @@ AVFVideoWidget::~AVFVideoWidget()
#ifdef QT_DEBUG_AVF
qDebug() << Q_FUNC_INFO;
#endif
- delete m_shaderProgram;
+
+ if (m_playerLayer)
+ [m_playerLayer release];
}
-void AVFVideoWidget::initializeGL()
+QSize AVFVideoWidget::sizeHint() const
{
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
-
- m_shaderProgram = new QOpenGLShaderProgram;
-
- static const char *textureVertexProgram =
- "uniform highp mat4 matrix;\n"
- "attribute highp vec3 vertexCoordEntry;\n"
- "attribute highp vec2 textureCoordEntry;\n"
- "varying highp vec2 textureCoord;\n"
- "void main() {\n"
- " textureCoord = textureCoordEntry;\n"
- " gl_Position = matrix * vec4(vertexCoordEntry, 1);\n"
- "}\n";
-
- static const char *textureFragmentProgram =
- "uniform sampler2D texture;\n"
- "varying highp vec2 textureCoord;\n"
- "void main() {\n"
- " gl_FragColor = texture2D(texture, textureCoord);\n"
- "}\n";
-
- m_shaderProgram->addShaderFromSourceCode(QOpenGLShader::Vertex, textureVertexProgram);
- m_shaderProgram->addShaderFromSourceCode(QOpenGLShader::Fragment, textureFragmentProgram);
- m_shaderProgram->link();
+ return m_nativeSize;
}
-void AVFVideoWidget::resizeGL(int w, int h)
+Qt::AspectRatioMode AVFVideoWidget::aspectRatioMode() const
{
- glViewport(0, 0, GLsizei(w), GLsizei(h));
- updateGL();
+ return m_aspectRatioMode;
}
-void AVFVideoWidget::paintGL()
+void AVFVideoWidget::setAspectRatioMode(Qt::AspectRatioMode mode)
{
- glClear(GL_COLOR_BUFFER_BIT);
- if (!m_textureId)
- return;
-
- QRect targetRect = displayRect();
- GLfloat x1 = targetRect.left();
- GLfloat x2 = targetRect.right();
- GLfloat y1 = targetRect.bottom();
- GLfloat y2 = targetRect.top();
- GLfloat zValue = 0;
+ if (m_aspectRatioMode != mode) {
+ m_aspectRatioMode = mode;
- const GLfloat textureCoordinates[] = {
- 0, 0,
- 1, 0,
- 1, 1,
- 0, 1
- };
+ updateAspectRatio();
+ }
+}
- const GLfloat vertexCoordinates[] = {
- x1, y1, zValue,
- x2, y1, zValue,
- x2, y2, zValue,
- x1, y2, zValue
- };
+void AVFVideoWidget::setPlayerLayer(AVPlayerLayer *layer)
+{
+ if (m_playerLayer == layer)
+ return;
- //Set matrix to transfrom geometry values into gl coordinate space.
- m_transformMatrix.setToIdentity();
- m_transformMatrix.scale( 2.0f / size().width(), 2.0f / size().height() );
- m_transformMatrix.translate(-size().width() / 2.0f, -size().height() / 2.0f);
+ if (!m_nativeView) {
+ //make video widget a native window
+#if defined(Q_OS_OSX)
+ m_nativeView = (NSView*)this->winId();
+ [m_nativeView setWantsLayer:YES];
+#else
+ m_nativeView = (UIView*)this->winId();
+#endif
+ }
- m_shaderProgram->bind();
+ if (m_playerLayer) {
+ [m_playerLayer removeFromSuperlayer];
+ [m_playerLayer release];
+ }
- m_vertexCoordEntry = m_shaderProgram->attributeLocation("vertexCoordEntry");
- m_textureCoordEntry = m_shaderProgram->attributeLocation("textureCoordEntry");
- m_matrixLocation = m_shaderProgram->uniformLocation("matrix");
+ m_playerLayer = layer;
- //attach the data!
- glEnableVertexAttribArray(m_vertexCoordEntry);
- glEnableVertexAttribArray(m_textureCoordEntry);
+ CALayer *nativeLayer = [m_nativeView layer];
- glVertexAttribPointer(m_vertexCoordEntry, 3, GL_FLOAT, GL_FALSE, 0, vertexCoordinates);
- glVertexAttribPointer(m_textureCoordEntry, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinates);
- m_shaderProgram->setUniformValue(m_matrixLocation, m_transformMatrix);
+ if (layer) {
+ [layer retain];
- glBindTexture(GL_TEXTURE_2D, m_textureId);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ m_nativeSize = QSize(m_playerLayer.bounds.size.width,
+ m_playerLayer.bounds.size.height);
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ updateAspectRatio();
+ [nativeLayer addSublayer:m_playerLayer];
+ updatePlayerLayerBounds(this->size());
+ }
- glBindTexture(GL_TEXTURE_2D, 0);
+ NSArray *sublayers = [nativeLayer sublayers];
+ qDebug() << "playerlayer: " << "at z:" << [m_playerLayer zPosition]
+ << " frame: " << m_playerLayer.frame.size.width << "x" << m_playerLayer.frame.size.height;
+ qDebug() << "superlayer: " << "at z:" << [nativeLayer zPosition]
+ << " frame: " << nativeLayer.frame.size.width << "x" << nativeLayer.frame.size.height;
+ int i = 0;
+ for (CALayer *layer in sublayers) {
+ qDebug() << "layer " << i << ": at z:" << [layer zPosition]
+ << " frame: " << layer.frame.size.width << "x" << layer.frame.size.height;
+ i++;
+ }
- glDisableVertexAttribArray(m_vertexCoordEntry);
- glDisableVertexAttribArray(m_textureCoordEntry);
- m_shaderProgram->release();
}
-void AVFVideoWidget::setTexture(GLuint texture)
+void AVFVideoWidget::resizeEvent(QResizeEvent *event)
{
- m_textureId = texture;
-
- if (isVisible()) {
- makeCurrent();
- updateGL();
- }
+ updatePlayerLayerBounds(event->size());
+ QWidget::resizeEvent(event);
}
-QSize AVFVideoWidget::sizeHint() const
+void AVFVideoWidget::paintEvent(QPaintEvent *event)
{
- return m_nativeSize;
-}
+ QPainter painter(this);
+ painter.fillRect(rect(), Qt::black);
-void AVFVideoWidget::setNativeSize(const QSize &size)
-{
- m_nativeSize = size;
+ QWidget::paintEvent(event);
}
-void AVFVideoWidget::setAspectRatioMode(Qt::AspectRatioMode mode)
+void AVFVideoWidget::updateAspectRatio()
{
- if (m_aspectRatioMode != mode) {
- m_aspectRatioMode = mode;
- update();
+ if (m_playerLayer) {
+ switch (m_aspectRatioMode) {
+ case Qt::IgnoreAspectRatio:
+ [m_playerLayer setVideoGravity:AVLayerVideoGravityResize];
+ break;
+ case Qt::KeepAspectRatio:
+ [m_playerLayer setVideoGravity:AVLayerVideoGravityResizeAspect];
+ break;
+ case Qt::KeepAspectRatioByExpanding:
+ [m_playerLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
+ break;
+ default:
+ break;
+ }
}
}
-QRect AVFVideoWidget::displayRect() const
+void AVFVideoWidget::updatePlayerLayerBounds(const QSize &size)
{
- QRect displayRect = rect();
-
- if (m_aspectRatioMode == Qt::KeepAspectRatio) {
- QSize size = m_nativeSize;
- size.scale(displayRect.size(), Qt::KeepAspectRatio);
-
- displayRect = QRect(QPoint(0, 0), size);
- displayRect.moveCenter(rect().center());
- }
- return displayRect;
+ m_playerLayer.bounds = CGRectMake(0.0f, 0.0f, (float)size.width(), (float)size.height());
}
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.h b/src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.h
index 5230d7569..89d3e7f56 100644
--- a/src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.h
+++ b/src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.h
@@ -45,13 +45,11 @@
#include <qvideowidgetcontrol.h>
#include "avfvideooutput.h"
-#import <CoreVideo/CVBase.h>
+@class AVPlayerLayer;
QT_BEGIN_NAMESPACE
-class AVFDisplayLink;
class AVFVideoWidget;
-class AVFVideoFrameRenderer;
class AVFVideoWidgetControl : public QVideoWidgetControl, public AVFVideoOutput
{
@@ -83,24 +81,15 @@ public:
int saturation() const;
void setSaturation(int saturation);
-private Q_SLOTS:
- void updateVideoFrame(const CVTimeStamp &ts);
-
private:
- void setupVideoOutput();
-
- AVFDisplayLink *m_displayLink;
AVFVideoWidget *m_videoWidget;
- AVFVideoFrameRenderer *m_frameRenderer;
- QSize m_nativeSize;
- Qt::AspectRatioMode m_aspectRatioMode;
+
bool m_fullscreen;
int m_brightness;
int m_contrast;
int m_hue;
int m_saturation;
- void *m_playerLayer;
};
QT_END_NAMESPACE
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.mm b/src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.mm
index f50117d81..0d62c394b 100644
--- a/src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.mm
+++ b/src/plugins/avfoundation/mediaplayer/avfvideowidgetcontrol.mm
@@ -40,10 +40,7 @@
****************************************************************************/
#include "avfvideowidgetcontrol.h"
-
#include "avfvideowidget.h"
-#include "avfvideoframerenderer.h"
-#include "avfdisplaylink.h"
#ifdef QT_DEBUG_AVF
#include <QtCore/QDebug>
@@ -55,22 +52,13 @@ QT_USE_NAMESPACE
AVFVideoWidgetControl::AVFVideoWidgetControl(QObject *parent)
: QVideoWidgetControl(parent)
- , m_frameRenderer(0)
- , m_aspectRatioMode(Qt::KeepAspectRatio)
, m_fullscreen(false)
, m_brightness(0)
, m_contrast(0)
, m_hue(0)
, m_saturation(0)
- , m_playerLayer(0)
{
- QGLFormat format = QGLFormat::defaultFormat();
- format.setSwapInterval(1); // Vertical sync (avoid tearing)
- format.setDoubleBuffer(true);
- m_videoWidget = new AVFVideoWidget(0, format);
-
- m_displayLink = new AVFDisplayLink(this);
- connect(m_displayLink, SIGNAL(tick(CVTimeStamp)), this, SLOT(updateVideoFrame(CVTimeStamp)));
+ m_videoWidget = new AVFVideoWidget(0);
}
AVFVideoWidgetControl::~AVFVideoWidgetControl()
@@ -78,10 +66,6 @@ AVFVideoWidgetControl::~AVFVideoWidgetControl()
#ifdef QT_DEBUG_AVF
qDebug() << Q_FUNC_INFO;
#endif
- m_displayLink->stop();
- if (m_playerLayer)
- [(AVPlayerLayer*)m_playerLayer release];
-
delete m_videoWidget;
}
@@ -91,26 +75,8 @@ void AVFVideoWidgetControl::setLayer(void *playerLayer)
qDebug() << Q_FUNC_INFO << playerLayer;
#endif
- if (m_playerLayer == playerLayer)
- return;
-
- [(AVPlayerLayer*)playerLayer retain];
- [(AVPlayerLayer*)m_playerLayer release];
-
- m_playerLayer = playerLayer;
-
- //If there is no layer to render, stop scheduling updates
- if (m_playerLayer == 0) {
- m_displayLink->stop();
- return;
- }
+ m_videoWidget->setPlayerLayer((AVPlayerLayer*)playerLayer);
- setupVideoOutput();
-
- //make sure we schedule updates
- if (!m_displayLink->isActive()) {
- m_displayLink->start();
- }
}
QWidget *AVFVideoWidgetControl::videoWidget()
@@ -130,12 +96,11 @@ void AVFVideoWidgetControl::setFullScreen(bool fullScreen)
Qt::AspectRatioMode AVFVideoWidgetControl::aspectRatioMode() const
{
- return m_aspectRatioMode;
+ return m_videoWidget->aspectRatioMode();
}
void AVFVideoWidgetControl::setAspectRatioMode(Qt::AspectRatioMode mode)
{
- m_aspectRatioMode = mode;
m_videoWidget->setAspectRatioMode(mode);
}
@@ -179,41 +144,4 @@ void AVFVideoWidgetControl::setSaturation(int saturation)
m_saturation = saturation;
}
-void AVFVideoWidgetControl::updateVideoFrame(const CVTimeStamp &ts)
-{
- Q_UNUSED(ts)
-
- AVPlayerLayer *playerLayer = (AVPlayerLayer*)m_playerLayer;
-
- if (!playerLayer) {
- qWarning("updateVideoFrame called without AVPlayerLayer (which shouldn't happen)");
- return;
- }
-
- //Don't try to render a layer that is not ready
- if (!playerLayer.readyForDisplay)
- return;
-
- GLuint textureId = m_frameRenderer->renderLayerToTexture(playerLayer);
-
- //Make sure we have a valid texture
- if (textureId == 0) {
- qWarning("renderLayerToTexture failed");
- return;
- }
-
- m_videoWidget->setTexture(textureId);
-}
-
-void AVFVideoWidgetControl::setupVideoOutput()
-{
- CGRect layerBounds = [(AVPlayerLayer*)m_playerLayer bounds];
- m_nativeSize = QSize(layerBounds.size.width, layerBounds.size.height);
- m_videoWidget->setNativeSize(m_nativeSize);
-
- if (m_frameRenderer)
- delete m_frameRenderer;
-
- m_frameRenderer = new AVFVideoFrameRenderer(m_videoWidget, m_nativeSize, this);
-}
-
+#include "moc_avfvideowidgetcontrol.cpp"
diff --git a/src/plugins/avfoundation/mediaplayer/mediaplayer.pro b/src/plugins/avfoundation/mediaplayer/mediaplayer.pro
index a61c62d01..e5bccd150 100644
--- a/src/plugins/avfoundation/mediaplayer/mediaplayer.pro
+++ b/src/plugins/avfoundation/mediaplayer/mediaplayer.pro
@@ -21,9 +21,6 @@ HEADERS += \
avfmediaplayerservice.h \
avfmediaplayersession.h \
avfmediaplayerserviceplugin.h \
- avfvideorenderercontrol.h \
- avfdisplaylink.h \
- avfvideoframerenderer.h \
avfvideooutput.h
OBJECTIVE_SOURCES += \
@@ -32,20 +29,30 @@ OBJECTIVE_SOURCES += \
avfmediaplayerservice.mm \
avfmediaplayerserviceplugin.mm \
avfmediaplayersession.mm \
- avfvideorenderercontrol.mm \
- avfdisplaylink.mm \
- avfvideoframerenderer.mm \
avfvideooutput.mm
-qtHaveModule(widgets) {
- QT += multimediawidgets-private opengl
- HEADERS += \
- avfvideowidgetcontrol.h \
- avfvideowidget.h
+ qtHaveModule(widgets) {
+ QT += multimediawidgets-private
+ HEADERS += \
+ avfvideowidgetcontrol.h \
+ avfvideowidget.h
+
+ OBJECTIVE_SOURCES += \
+ avfvideowidgetcontrol.mm \
+ avfvideowidget.mm
+ }
+!ios {
+ LIBS += -framework QuartzCore -framework AppKit
+
+ HEADERS += \
+ avfvideorenderercontrol.h \
+ avfdisplaylink.h \
+ avfvideoframerenderer.h
OBJECTIVE_SOURCES += \
- avfvideowidgetcontrol.mm \
- avfvideowidget.mm
+ avfvideorenderercontrol.mm \
+ avfdisplaylink.mm \
+ avfvideoframerenderer.mm
}
OTHER_FILES += \
diff --git a/src/plugins/opensles/opensles.json b/src/plugins/opensles/opensles.json
new file mode 100644
index 000000000..a31d52107
--- /dev/null
+++ b/src/plugins/opensles/opensles.json
@@ -0,0 +1,3 @@
+{
+ "Keys": ["default"]
+}
diff --git a/src/plugins/opensles/opensles.pro b/src/plugins/opensles/opensles.pro
new file mode 100644
index 000000000..53c5a120b
--- /dev/null
+++ b/src/plugins/opensles/opensles.pro
@@ -0,0 +1,25 @@
+TARGET = qtaudio_opensles
+QT += multimedia-private
+
+PLUGIN_TYPE = audio
+PLUGIN_CLASS_NAME = QOpenSLESPlugin
+load(qt_plugin)
+
+LIBS += -lOpenSLES
+
+HEADERS += \
+ qopenslesplugin.h \
+ qopenslesengine.h \
+ qopenslesdeviceinfo.h \
+ qopenslesaudioinput.h \
+ qopenslesaudiooutput.h
+
+SOURCES += \
+ qopenslesplugin.cpp \
+ qopenslesengine.cpp \
+ qopenslesdeviceinfo.cpp \
+ qopenslesaudioinput.cpp \
+ qopenslesaudiooutput.cpp
+
+OTHER_FILES += \
+ opensles.json
diff --git a/src/plugins/opensles/qopenslesaudioinput.cpp b/src/plugins/opensles/qopenslesaudioinput.cpp
new file mode 100644
index 000000000..d07421f0e
--- /dev/null
+++ b/src/plugins/opensles/qopenslesaudioinput.cpp
@@ -0,0 +1,505 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qopenslesaudioinput.h"
+
+#include "qopenslesengine.h"
+#include <qbuffer.h>
+#include <qdebug.h>
+
+#ifdef ANDROID
+#include <SLES/OpenSLES_AndroidConfiguration.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+#define NUM_BUFFERS 2
+#define DEFAULT_PERIOD_TIME_MS 50
+#define MINIMUM_PERIOD_TIME_MS 5
+
+#ifdef ANDROID
+static void bufferQueueCallback(SLAndroidSimpleBufferQueueItf, void *context)
+#else
+static void bufferQueueCallback(SLBufferQueueItf, void *context)
+#endif
+{
+ // Process buffer in main thread
+ QMetaObject::invokeMethod(reinterpret_cast<QOpenSLESAudioInput*>(context), "processBuffer");
+}
+
+QOpenSLESAudioInput::QOpenSLESAudioInput(const QByteArray &device)
+ : m_device(device)
+ , m_engine(QOpenSLESEngine::instance())
+ , m_recorderObject(0)
+ , m_recorder(0)
+ , m_bufferQueue(0)
+ , m_pullMode(true)
+ , m_processedBytes(0)
+ , m_audioSource(0)
+ , m_bufferIODevice(0)
+ , m_errorState(QAudio::NoError)
+ , m_deviceState(QAudio::StoppedState)
+ , m_lastNotifyTime(0)
+ , m_volume(1)
+ , m_bufferSize(0)
+ , m_periodSize(0)
+ , m_intervalTime(1000)
+ , m_buffers(new QByteArray[NUM_BUFFERS])
+ , m_currentBuffer(0)
+{
+#ifdef ANDROID
+ if (qstrcmp(device, QT_ANDROID_PRESET_CAMCORDER) == 0)
+ m_recorderPreset = SL_ANDROID_RECORDING_PRESET_CAMCORDER;
+ else if (qstrcmp(device, QT_ANDROID_PRESET_VOICE_RECOGNITION) == 0)
+ m_recorderPreset = SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION;
+ else
+ m_recorderPreset = SL_ANDROID_RECORDING_PRESET_GENERIC;
+#endif
+}
+
+QOpenSLESAudioInput::~QOpenSLESAudioInput()
+{
+ if (m_recorderObject)
+ (*m_recorderObject)->Destroy(m_recorderObject);
+ delete[] m_buffers;
+}
+
+QAudio::Error QOpenSLESAudioInput::error() const
+{
+ return m_errorState;
+}
+
+QAudio::State QOpenSLESAudioInput::state() const
+{
+ return m_deviceState;
+}
+
+void QOpenSLESAudioInput::setFormat(const QAudioFormat &format)
+{
+ if (m_deviceState == QAudio::StoppedState)
+ m_format = format;
+}
+
+QAudioFormat QOpenSLESAudioInput::format() const
+{
+ return m_format;
+}
+
+void QOpenSLESAudioInput::start(QIODevice *device)
+{
+ if (m_deviceState != QAudio::StoppedState)
+ stopRecording();
+
+ if (!m_pullMode && m_bufferIODevice) {
+ m_bufferIODevice->close();
+ delete m_bufferIODevice;
+ m_bufferIODevice = 0;
+ }
+
+ m_pullMode = true;
+ m_audioSource = device;
+
+ if (startRecording()) {
+ m_deviceState = QAudio::ActiveState;
+ } else {
+ m_deviceState = QAudio::StoppedState;
+ Q_EMIT errorChanged(m_errorState);
+ }
+
+ Q_EMIT stateChanged(m_deviceState);
+}
+
+QIODevice *QOpenSLESAudioInput::start()
+{
+ if (m_deviceState != QAudio::StoppedState)
+ stopRecording();
+
+ m_audioSource = 0;
+
+ if (!m_pullMode && m_bufferIODevice) {
+ m_bufferIODevice->close();
+ delete m_bufferIODevice;
+ }
+
+ m_pullMode = false;
+ m_pushBuffer.clear();
+ m_bufferIODevice = new QBuffer(&m_pushBuffer);
+ m_bufferIODevice->open(QIODevice::ReadOnly);
+
+ if (startRecording()) {
+ m_deviceState = QAudio::IdleState;
+ } else {
+ m_deviceState = QAudio::StoppedState;
+ Q_EMIT errorChanged(m_errorState);
+ m_bufferIODevice->close();
+ delete m_bufferIODevice;
+ m_bufferIODevice = 0;
+ }
+
+ Q_EMIT stateChanged(m_deviceState);
+ return m_bufferIODevice;
+}
+
+bool QOpenSLESAudioInput::startRecording()
+{
+ m_processedBytes = 0;
+ m_clockStamp.restart();
+ m_lastNotifyTime = 0;
+
+ SLresult result;
+
+ // configure audio source
+ SLDataLocator_IODevice loc_dev = { SL_DATALOCATOR_IODEVICE, SL_IODEVICE_AUDIOINPUT,
+ SL_DEFAULTDEVICEID_AUDIOINPUT, NULL };
+ SLDataSource audioSrc = { &loc_dev, NULL };
+
+ // configure audio sink
+#ifdef ANDROID
+ SLDataLocator_AndroidSimpleBufferQueue loc_bq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE,
+ NUM_BUFFERS };
+#else
+ SLDataLocator_BufferQueue loc_bq = { SL_DATALOCATOR_BUFFERQUEUE, NUM_BUFFERS };
+#endif
+
+ SLDataFormat_PCM format_pcm = QOpenSLESEngine::audioFormatToSLFormatPCM(m_format);
+ SLDataSink audioSnk = { &loc_bq, &format_pcm };
+
+ // create audio recorder
+ // (requires the RECORD_AUDIO permission)
+#ifdef ANDROID
+ const SLInterfaceID id[2] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE, SL_IID_ANDROIDCONFIGURATION };
+ const SLboolean req[2] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
+#else
+ const SLInterfaceID id[1] = { SL_IID_BUFFERQUEUE };
+ const SLboolean req[1] = { SL_BOOLEAN_TRUE };
+#endif
+
+ result = (*m_engine->slEngine())->CreateAudioRecorder(m_engine->slEngine(), &m_recorderObject,
+ &audioSrc, &audioSnk,
+ sizeof(req) / sizeof(SLboolean), id, req);
+ if (result != SL_RESULT_SUCCESS) {
+ m_errorState = QAudio::OpenError;
+ return false;
+ }
+
+#ifdef ANDROID
+ // configure recorder source
+ SLAndroidConfigurationItf configItf;
+ result = (*m_recorderObject)->GetInterface(m_recorderObject, SL_IID_ANDROIDCONFIGURATION,
+ &configItf);
+ if (result != SL_RESULT_SUCCESS) {
+ m_errorState = QAudio::OpenError;
+ return false;
+ }
+
+ result = (*configItf)->SetConfiguration(configItf, SL_ANDROID_KEY_RECORDING_PRESET,
+ &m_recorderPreset, sizeof(SLuint32));
+
+ SLuint32 presetValue = SL_ANDROID_RECORDING_PRESET_NONE;
+ SLuint32 presetSize = 2*sizeof(SLuint32); // intentionally too big
+ result = (*configItf)->GetConfiguration(configItf, SL_ANDROID_KEY_RECORDING_PRESET,
+ &presetSize, (void*)&presetValue);
+
+ if (result != SL_RESULT_SUCCESS || presetValue == SL_ANDROID_RECORDING_PRESET_NONE) {
+ m_errorState = QAudio::OpenError;
+ return false;
+ }
+#endif
+
+ // realize the audio recorder
+ result = (*m_recorderObject)->Realize(m_recorderObject, SL_BOOLEAN_FALSE);
+ if (result != SL_RESULT_SUCCESS) {
+ m_errorState = QAudio::OpenError;
+ return false;
+ }
+
+ // get the record interface
+ result = (*m_recorderObject)->GetInterface(m_recorderObject, SL_IID_RECORD, &m_recorder);
+ if (result != SL_RESULT_SUCCESS) {
+ m_errorState = QAudio::FatalError;
+ return false;
+ }
+
+ // get the buffer queue interface
+#ifdef ANDROID
+ SLInterfaceID bufferqueueItfID = SL_IID_ANDROIDSIMPLEBUFFERQUEUE;
+#else
+ SLInterfaceID bufferqueueItfID = SL_IID_BUFFERQUEUE;
+#endif
+ result = (*m_recorderObject)->GetInterface(m_recorderObject, bufferqueueItfID, &m_bufferQueue);
+ if (result != SL_RESULT_SUCCESS) {
+ m_errorState = QAudio::FatalError;
+ return false;
+ }
+
+ // register callback on the buffer queue
+ result = (*m_bufferQueue)->RegisterCallback(m_bufferQueue, bufferQueueCallback, this);
+ if (result != SL_RESULT_SUCCESS) {
+ m_errorState = QAudio::FatalError;
+ return false;
+ }
+
+ if (m_bufferSize <= 0) {
+ m_bufferSize = m_format.bytesForDuration(DEFAULT_PERIOD_TIME_MS * 1000);
+ } else {
+ int minimumBufSize = m_format.bytesForDuration(MINIMUM_PERIOD_TIME_MS * 1000);
+ if (m_bufferSize < minimumBufSize)
+ m_bufferSize = minimumBufSize;
+ }
+
+ m_periodSize = m_bufferSize;
+
+ // enqueue empty buffers to be filled by the recorder
+ for (int i = 0; i < NUM_BUFFERS; ++i) {
+ m_buffers[i].resize(m_periodSize);
+
+ result = (*m_bufferQueue)->Enqueue(m_bufferQueue, m_buffers[i].data(), m_periodSize);
+ if (result != SL_RESULT_SUCCESS) {
+ m_errorState = QAudio::FatalError;
+ return false;
+ }
+ }
+
+ // start recording
+ result = (*m_recorder)->SetRecordState(m_recorder, SL_RECORDSTATE_RECORDING);
+ if (result != SL_RESULT_SUCCESS) {
+ m_errorState = QAudio::FatalError;
+ return false;
+ }
+
+ m_errorState = QAudio::NoError;
+
+ return true;
+}
+
+void QOpenSLESAudioInput::stop()
+{
+ if (m_deviceState == QAudio::StoppedState)
+ return;
+
+ m_deviceState = QAudio::StoppedState;
+
+ stopRecording();
+
+ m_errorState = QAudio::NoError;
+ Q_EMIT stateChanged(m_deviceState);
+}
+
+void QOpenSLESAudioInput::stopRecording()
+{
+ flushBuffers();
+
+ SLresult result;
+ result = (*m_recorder)->SetRecordState(m_recorder, SL_RECORDSTATE_STOPPED);
+ result = (*m_bufferQueue)->Clear(m_bufferQueue);
+
+ (*m_recorderObject)->Destroy(m_recorderObject);
+ m_recorderObject = 0;
+
+ for (int i = 0; i < NUM_BUFFERS; ++i)
+ m_buffers[i].clear();
+ m_currentBuffer = 0;
+
+ if (!m_pullMode && m_bufferIODevice) {
+ m_bufferIODevice->close();
+ delete m_bufferIODevice;
+ m_bufferIODevice = 0;
+ m_pushBuffer.clear();
+ }
+}
+
+void QOpenSLESAudioInput::suspend()
+{
+ if (m_deviceState == QAudio::ActiveState) {
+ m_deviceState = QAudio::SuspendedState;
+ emit stateChanged(m_deviceState);
+
+ (*m_recorder)->SetRecordState(m_recorder, SL_RECORDSTATE_PAUSED);
+ }
+}
+
+void QOpenSLESAudioInput::resume()
+{
+ if (m_deviceState == QAudio::SuspendedState || m_deviceState == QAudio::IdleState) {
+ (*m_recorder)->SetRecordState(m_recorder, SL_RECORDSTATE_RECORDING);
+
+ m_deviceState = QAudio::ActiveState;
+ emit stateChanged(m_deviceState);
+ }
+}
+
+void QOpenSLESAudioInput::processBuffer()
+{
+ if (m_deviceState == QAudio::StoppedState || m_deviceState == QAudio::SuspendedState)
+ return;
+
+ if (m_deviceState != QAudio::ActiveState) {
+ m_errorState = QAudio::NoError;
+ m_deviceState = QAudio::ActiveState;
+ emit stateChanged(m_deviceState);
+ }
+
+ QByteArray *processedBuffer = &m_buffers[m_currentBuffer];
+ writeDataToDevice(processedBuffer->constData(), processedBuffer->size());
+
+ // Re-enqueue the buffer
+ SLresult result = (*m_bufferQueue)->Enqueue(m_bufferQueue,
+ processedBuffer->data(),
+ processedBuffer->size());
+
+ m_currentBuffer = (m_currentBuffer + 1) % NUM_BUFFERS;
+
+ // If the buffer queue is empty (shouldn't happen), stop recording.
+#ifdef ANDROID
+ SLAndroidSimpleBufferQueueState state;
+#else
+ SLBufferQueueState state;
+#endif
+ result = (*m_bufferQueue)->GetState(m_bufferQueue, &state);
+ if (result != SL_RESULT_SUCCESS || state.count == 0) {
+ stop();
+ m_errorState = QAudio::FatalError;
+ Q_EMIT errorChanged(m_errorState);
+ }
+}
+
+void QOpenSLESAudioInput::writeDataToDevice(const char *data, int size)
+{
+ m_processedBytes += size;
+
+ if (m_pullMode) {
+ // write buffer to the QIODevice
+ if (m_audioSource->write(data, size) < 0) {
+ stop();
+ m_errorState = QAudio::IOError;
+ Q_EMIT errorChanged(m_errorState);
+ }
+ } else {
+ // emits readyRead() so user will call read() on QIODevice to get some audio data
+ if (m_bufferIODevice != 0) {
+ m_pushBuffer.append(data, size);
+ Q_EMIT m_bufferIODevice->readyRead();
+ }
+ }
+
+ // Send notify signal if needed
+ qint64 processedMsecs = processedUSecs() / 1000;
+ if (m_intervalTime && (processedMsecs - m_lastNotifyTime) >= m_intervalTime) {
+ Q_EMIT notify();
+ m_lastNotifyTime = processedMsecs;
+ }
+}
+
+void QOpenSLESAudioInput::flushBuffers()
+{
+ SLmillisecond recorderPos;
+ (*m_recorder)->GetPosition(m_recorder, &recorderPos);
+ qint64 devicePos = processedUSecs();
+
+ qint64 delta = recorderPos * 1000 - devicePos;
+
+ if (delta > 0)
+ writeDataToDevice(m_buffers[m_currentBuffer].constData(), m_format.bytesForDuration(delta));
+}
+
+int QOpenSLESAudioInput::bytesReady() const
+{
+ if (m_deviceState == QAudio::ActiveState || m_deviceState == QAudio::SuspendedState)
+ return m_bufferIODevice ? m_bufferIODevice->bytesAvailable() : m_periodSize;
+
+ return 0;
+}
+
+void QOpenSLESAudioInput::setBufferSize(int value)
+{
+ m_bufferSize = value;
+}
+
+int QOpenSLESAudioInput::bufferSize() const
+{
+ return m_bufferSize;
+}
+
+int QOpenSLESAudioInput::periodSize() const
+{
+ return m_periodSize;
+}
+
+void QOpenSLESAudioInput::setNotifyInterval(int ms)
+{
+ m_intervalTime = qMax(0, ms);
+}
+
+int QOpenSLESAudioInput::notifyInterval() const
+{
+ return m_intervalTime;
+}
+
+qint64 QOpenSLESAudioInput::processedUSecs() const
+{
+ return m_format.durationForBytes(m_processedBytes);
+}
+
+qint64 QOpenSLESAudioInput::elapsedUSecs() const
+{
+ if (m_deviceState == QAudio::StoppedState)
+ return 0;
+
+ return m_clockStamp.elapsed() * 1000;
+}
+
+void QOpenSLESAudioInput::setVolume(qreal vol)
+{
+ // Volume interface is not available for the recorder on Android
+ m_volume = vol;
+}
+
+qreal QOpenSLESAudioInput::volume() const
+{
+ return m_volume;
+}
+
+void QOpenSLESAudioInput::reset()
+{
+ stop();
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/opensles/qopenslesaudioinput.h b/src/plugins/opensles/qopenslesaudioinput.h
new file mode 100644
index 000000000..c71963087
--- /dev/null
+++ b/src/plugins/opensles/qopenslesaudioinput.h
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QOPENSLESAUDIOINPUT_H
+#define QOPENSLESAUDIOINPUT_H
+
+#include <qaudiosystem.h>
+#include <QTime>
+#include <SLES/OpenSLES.h>
+
+#ifdef ANDROID
+#include <SLES/OpenSLES_Android.h>
+
+#define QT_ANDROID_PRESET_MIC "mic"
+#define QT_ANDROID_PRESET_CAMCORDER "camcorder"
+#define QT_ANDROID_PRESET_VOICE_RECOGNITION "voicerecognition"
+
+#endif
+
+QT_BEGIN_NAMESPACE
+
+class QOpenSLESEngine;
+class QIODevice;
+class QBuffer;
+
+class QOpenSLESAudioInput : public QAbstractAudioInput
+{
+ Q_OBJECT
+
+public:
+ QOpenSLESAudioInput(const QByteArray &device);
+ ~QOpenSLESAudioInput();
+
+ void start(QIODevice *device);
+ QIODevice *start();
+ void stop();
+ void reset();
+ void suspend();
+ void resume();
+ int bytesReady() const;
+ int periodSize() const;
+ void setBufferSize(int value);
+ int bufferSize() const;
+ void setNotifyInterval(int milliSeconds);
+ int notifyInterval() const;
+ qint64 processedUSecs() const;
+ qint64 elapsedUSecs() const;
+ QAudio::Error error() const;
+ QAudio::State state() const;
+ void setFormat(const QAudioFormat &format);
+ QAudioFormat format() const;
+
+ void setVolume(qreal volume);
+ qreal volume() const;
+
+public Q_SLOTS:
+ void processBuffer();
+
+private:
+ bool startRecording();
+ void stopRecording();
+ void writeDataToDevice(const char *data, int size);
+ void flushBuffers();
+
+ QByteArray m_device;
+ QOpenSLESEngine *m_engine;
+ SLObjectItf m_recorderObject;
+ SLRecordItf m_recorder;
+#ifdef ANDROID
+ SLuint32 m_recorderPreset;
+ SLAndroidSimpleBufferQueueItf m_bufferQueue;
+#else
+ SLBufferQueueItf m_bufferQueue;
+#endif
+
+ bool m_pullMode;
+ qint64 m_processedBytes;
+ QIODevice *m_audioSource;
+ QBuffer *m_bufferIODevice;
+ QByteArray m_pushBuffer;
+ QAudioFormat m_format;
+ QAudio::Error m_errorState;
+ QAudio::State m_deviceState;
+ QTime m_clockStamp;
+ qint64 m_lastNotifyTime;
+ qreal m_volume;
+ int m_bufferSize;
+ int m_periodSize;
+ int m_intervalTime;
+ QByteArray *m_buffers;
+ int m_currentBuffer;
+};
+
+QT_END_NAMESPACE
+
+#endif // QOPENSLESAUDIOINPUT_H
diff --git a/src/plugins/opensles/qopenslesaudiooutput.cpp b/src/plugins/opensles/qopenslesaudiooutput.cpp
new file mode 100644
index 000000000..908e299c1
--- /dev/null
+++ b/src/plugins/opensles/qopenslesaudiooutput.cpp
@@ -0,0 +1,628 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qopenslesaudiooutput.h"
+#include "qopenslesengine.h"
+#include <QDebug>
+#include <qmath.h>
+
+#ifdef ANDROID
+#include <SLES/OpenSLES_Android.h>
+#include <SLES/OpenSLES_AndroidConfiguration.h>
+#endif // ANDROID
+
+#define BUFFER_COUNT 2
+#define DEFAULT_PERIOD_TIME_MS 50
+#define MINIMUM_PERIOD_TIME_MS 5
+
+QT_BEGIN_NAMESPACE
+
+QMap<QString, qint32> QOpenSLESAudioOutput::m_categories;
+
+QOpenSLESAudioOutput::QOpenSLESAudioOutput(const QByteArray &device)
+ : m_deviceName(device),
+ m_state(QAudio::StoppedState),
+ m_error(QAudio::NoError),
+ m_outputMixObject(Q_NULLPTR),
+ m_playerObject(Q_NULLPTR),
+ m_playItf(Q_NULLPTR),
+ m_volumeItf(Q_NULLPTR),
+ m_bufferQueueItf(Q_NULLPTR),
+ m_audioSource(Q_NULLPTR),
+ m_buffers(Q_NULLPTR),
+ m_volume(1.0),
+ m_pullMode(false),
+ m_nextBuffer(0),
+ m_bufferSize(0),
+ m_notifyInterval(1000),
+ m_periodSize(0),
+ m_elapsedTime(0),
+ m_processedBytes(0),
+ m_availableBuffers(BUFFER_COUNT)
+{
+#ifndef ANDROID
+ m_streamType = -1;
+#else
+ m_streamType = SL_ANDROID_STREAM_MEDIA;
+ m_category = QLatin1String("media");
+#endif // ANDROID
+}
+
+QOpenSLESAudioOutput::~QOpenSLESAudioOutput()
+{
+ destroyPlayer();
+}
+
+QAudio::Error QOpenSLESAudioOutput::error() const
+{
+ return m_error;
+}
+
+QAudio::State QOpenSLESAudioOutput::state() const
+{
+ return m_state;
+}
+
+void QOpenSLESAudioOutput::start(QIODevice *device)
+{
+ Q_ASSERT(device);
+ destroyPlayer();
+
+ m_pullMode = true;
+
+ if (!preparePlayer())
+ return;
+
+ m_audioSource = device;
+ setState(QAudio::ActiveState);
+ setError(QAudio::NoError);
+
+ // Attempt to fill buffers first.
+ for (int i = 0; i != BUFFER_COUNT; ++i) {
+ const int index = i * m_bufferSize;
+ const qint64 readSize = m_audioSource->read(m_buffers + index, m_bufferSize);
+ if (readSize && SL_RESULT_SUCCESS != (*m_bufferQueueItf)->Enqueue(m_bufferQueueItf,
+ m_buffers + index,
+ readSize)) {
+ setError(QAudio::FatalError);
+ destroyPlayer();
+ return;
+ }
+ m_processedBytes += readSize;
+ }
+
+ // Change to state to playing.
+ // We need to do this after filling the buffers or processedBytes might get corrupted.
+ if (SL_RESULT_SUCCESS != (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_PLAYING)) {
+ setError(QAudio::FatalError);
+ destroyPlayer();
+ }
+}
+
+QIODevice *QOpenSLESAudioOutput::start()
+{
+ destroyPlayer();
+
+ m_pullMode = false;
+
+ if (!preparePlayer())
+ return Q_NULLPTR;
+
+ m_audioSource = new SLIODevicePrivate(this);
+ m_audioSource->open(QIODevice::WriteOnly | QIODevice::Unbuffered);
+
+ // Change to state to playing
+ if (SL_RESULT_SUCCESS != (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_PLAYING)) {
+ setError(QAudio::FatalError);
+ destroyPlayer();
+ }
+
+ setState(QAudio::IdleState);
+ return m_audioSource;
+}
+
+void QOpenSLESAudioOutput::stop()
+{
+ if (m_state == QAudio::StoppedState)
+ return;
+
+ destroyPlayer();
+ setError(QAudio::NoError);
+}
+
+int QOpenSLESAudioOutput::bytesFree() const
+{
+ if (m_state != QAudio::ActiveState && m_state != QAudio::IdleState)
+ return 0;
+
+ return m_availableBuffers.load() ? m_bufferSize : 0;
+}
+
+int QOpenSLESAudioOutput::periodSize() const
+{
+ return m_periodSize;
+}
+
+void QOpenSLESAudioOutput::setBufferSize(int value)
+{
+ if (m_state != QAudio::StoppedState)
+ return;
+
+ m_bufferSize = value;
+}
+
+int QOpenSLESAudioOutput::bufferSize() const
+{
+ return m_bufferSize;
+}
+
+void QOpenSLESAudioOutput::setNotifyInterval(int ms)
+{
+ m_notifyInterval = ms > 0 ? ms : 0;
+}
+
+int QOpenSLESAudioOutput::notifyInterval() const
+{
+ return m_notifyInterval;
+}
+
+qint64 QOpenSLESAudioOutput::processedUSecs() const
+{
+ if (m_state == QAudio::IdleState || m_state == QAudio::SuspendedState)
+ return m_format.durationForBytes(m_processedBytes);
+
+ SLmillisecond processMSec = 0;
+ if (m_playItf)
+ (*m_playItf)->GetPosition(m_playItf, &processMSec);
+
+ return processMSec * 1000;
+}
+
+void QOpenSLESAudioOutput::resume()
+{
+ if (m_state != QAudio::SuspendedState)
+ return;
+
+ if (SL_RESULT_SUCCESS != (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_PLAYING)) {
+ setError(QAudio::FatalError);
+ destroyPlayer();
+ return;
+ }
+
+ setState(QAudio::ActiveState);
+ setError(QAudio::NoError);
+}
+
+void QOpenSLESAudioOutput::setFormat(const QAudioFormat &format)
+{
+ m_format = format;
+}
+
+QAudioFormat QOpenSLESAudioOutput::format() const
+{
+ return m_format;
+}
+
+void QOpenSLESAudioOutput::suspend()
+{
+ if (m_state != QAudio::ActiveState && m_state != QAudio::IdleState)
+ return;
+
+ if (SL_RESULT_SUCCESS != (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_PAUSED)) {
+ setError(QAudio::FatalError);
+ destroyPlayer();
+ return;
+ }
+
+ setState(QAudio::SuspendedState);
+ setError(QAudio::NoError);
+}
+
+qint64 QOpenSLESAudioOutput::elapsedUSecs() const
+{
+ if (m_state == QAudio::StoppedState)
+ return 0;
+
+ return m_clockStamp.elapsed() * 1000;
+}
+
+void QOpenSLESAudioOutput::reset()
+{
+ destroyPlayer();
+}
+
+void QOpenSLESAudioOutput::setVolume(qreal vol)
+{
+ m_volume = qBound(qreal(0.0), vol, qreal(1.0));
+ const SLmillibel newVolume = adjustVolume(m_volume);
+ if (m_volumeItf && SL_RESULT_SUCCESS != (*m_volumeItf)->SetVolumeLevel(m_volumeItf, newVolume))
+ qWarning() << "Unable to change volume";
+}
+
+qreal QOpenSLESAudioOutput::volume() const
+{
+ return m_volume;
+}
+
+void QOpenSLESAudioOutput::setCategory(const QString &category)
+{
+#ifndef ANDROID
+ Q_UNUSED(category);
+#else
+ if (m_categories.isEmpty()) {
+ m_categories.insert(QLatin1String("voice"), SL_ANDROID_STREAM_VOICE);
+ m_categories.insert(QLatin1String("system"), SL_ANDROID_STREAM_SYSTEM);
+ m_categories.insert(QLatin1String("ring"), SL_ANDROID_STREAM_RING);
+ m_categories.insert(QLatin1String("media"), SL_ANDROID_STREAM_MEDIA);
+ m_categories.insert(QLatin1String("alarm"), SL_ANDROID_STREAM_ALARM);
+ m_categories.insert(QLatin1String("notification"), SL_ANDROID_STREAM_NOTIFICATION);
+ }
+
+ const SLint32 streamType = m_categories.value(category, -1);
+ if (streamType == -1) {
+ qWarning() << "Unknown category" << category
+ << ", available categories are:" << m_categories.keys()
+ << ". Defaulting to category \"media\"";
+ return;
+ }
+
+ m_streamType = streamType;
+ m_category = category;
+#endif // ANDROID
+}
+
+QString QOpenSLESAudioOutput::category() const
+{
+ return m_category;
+}
+
+void QOpenSLESAudioOutput::onEOSEvent()
+{
+ if (m_state != QAudio::ActiveState)
+ return;
+
+ SLBufferQueueState state;
+ if (SL_RESULT_SUCCESS != (*m_bufferQueueItf)->GetState(m_bufferQueueItf, &state))
+ return;
+
+ if (state.count > 0)
+ return;
+
+ setState(QAudio::IdleState);
+ setError(QAudio::UnderrunError);
+}
+
+void QOpenSLESAudioOutput::bufferAvailable(quint32 count, quint32 playIndex)
+{
+ Q_UNUSED(count);
+ Q_UNUSED(playIndex);
+
+ if (m_state == QAudio::StoppedState)
+ return;
+
+ if (!m_pullMode) {
+ m_availableBuffers.fetchAndAddRelaxed(1);
+ return;
+ }
+
+ const int index = m_nextBuffer * m_bufferSize;
+ const qint64 readSize = m_audioSource->read(m_buffers + index, m_bufferSize);
+
+ if (1 > readSize)
+ return;
+
+ if (SL_RESULT_SUCCESS != (*m_bufferQueueItf)->Enqueue(m_bufferQueueItf,
+ m_buffers + index,
+ readSize)) {
+ setError(QAudio::FatalError);
+ destroyPlayer();
+ return;
+ }
+
+ m_processedBytes += readSize;
+ m_nextBuffer = (m_nextBuffer + 1) % BUFFER_COUNT;
+}
+
+void QOpenSLESAudioOutput::playCallback(SLPlayItf player, void *ctx, SLuint32 event)
+{
+ Q_UNUSED(player);
+ QOpenSLESAudioOutput *audioOutput = reinterpret_cast<QOpenSLESAudioOutput *>(ctx);
+ if (event & SL_PLAYEVENT_HEADATEND)
+ QMetaObject::invokeMethod(audioOutput, "onEOSEvent", Qt::QueuedConnection);
+ if (event & SL_PLAYEVENT_HEADATNEWPOS)
+ Q_EMIT audioOutput->notify();
+
+}
+
+void QOpenSLESAudioOutput::bufferQueueCallback(SLBufferQueueItf bufferQueue, void *ctx)
+{
+ SLBufferQueueState state;
+ (*bufferQueue)->GetState(bufferQueue, &state);
+ QOpenSLESAudioOutput *audioOutput = reinterpret_cast<QOpenSLESAudioOutput *>(ctx);
+ audioOutput->bufferAvailable(state.count, state.playIndex);
+}
+
+bool QOpenSLESAudioOutput::preparePlayer()
+{
+ SLEngineItf engine = QOpenSLESEngine::instance()->slEngine();
+ if (!engine) {
+ qWarning() << "No engine";
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ SLDataLocator_BufferQueue bufferQueueLocator = { SL_DATALOCATOR_BUFFERQUEUE, BUFFER_COUNT };
+ SLDataFormat_PCM pcmFormat = QOpenSLESEngine::audioFormatToSLFormatPCM(m_format);
+
+ SLDataSource audioSrc = { &bufferQueueLocator, &pcmFormat };
+
+ // OutputMix
+ if (SL_RESULT_SUCCESS != (*engine)->CreateOutputMix(engine,
+ &m_outputMixObject,
+ 0,
+ Q_NULLPTR,
+ Q_NULLPTR)) {
+ qWarning() << "Unable to create output mix";
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ if (SL_RESULT_SUCCESS != (*m_outputMixObject)->Realize(m_outputMixObject, SL_BOOLEAN_FALSE)) {
+ qWarning() << "Unable to initialize output mix";
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ SLDataLocator_OutputMix outputMixLocator = { SL_DATALOCATOR_OUTPUTMIX, m_outputMixObject };
+ SLDataSink audioSink = { &outputMixLocator, Q_NULLPTR };
+
+#ifndef ANDROID
+ const int iids = 2;
+ const SLInterfaceID ids[iids] = { SL_IID_BUFFERQUEUE, SL_IID_VOLUME };
+ const SLboolean req[iids] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
+#else
+ const int iids = 3;
+ const SLInterfaceID ids[iids] = { SL_IID_BUFFERQUEUE,
+ SL_IID_VOLUME,
+ SL_IID_ANDROIDCONFIGURATION };
+ const SLboolean req[iids] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
+#endif // ANDROID
+
+ // AudioPlayer
+ if (SL_RESULT_SUCCESS != (*engine)->CreateAudioPlayer(engine,
+ &m_playerObject,
+ &audioSrc,
+ &audioSink,
+ iids,
+ ids,
+ req)) {
+ qWarning() << "Unable to create AudioPlayer";
+ setError(QAudio::OpenError);
+ return false;
+ }
+
+#ifdef ANDROID
+ // Set profile/category
+ SLAndroidConfigurationItf playerConfig;
+ if (SL_RESULT_SUCCESS == (*m_playerObject)->GetInterface(m_playerObject,
+ SL_IID_ANDROIDCONFIGURATION,
+ &playerConfig)) {
+ (*playerConfig)->SetConfiguration(playerConfig,
+ SL_ANDROID_KEY_STREAM_TYPE,
+ &m_streamType,
+ sizeof(SLint32));
+ }
+#endif // ANDROID
+
+ if (SL_RESULT_SUCCESS != (*m_playerObject)->Realize(m_playerObject, SL_BOOLEAN_FALSE)) {
+ qWarning() << "Unable to initialize AudioPlayer";
+ setError(QAudio::OpenError);
+ return false;
+ }
+
+ // Buffer interface
+ if (SL_RESULT_SUCCESS != (*m_playerObject)->GetInterface(m_playerObject,
+ SL_IID_BUFFERQUEUE,
+ &m_bufferQueueItf)) {
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ if (SL_RESULT_SUCCESS != (*m_bufferQueueItf)->RegisterCallback(m_bufferQueueItf,
+ bufferQueueCallback,
+ this)) {
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ // Play interface
+ if (SL_RESULT_SUCCESS != (*m_playerObject)->GetInterface(m_playerObject,
+ SL_IID_PLAY,
+ &m_playItf)) {
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ if (SL_RESULT_SUCCESS != (*m_playItf)->RegisterCallback(m_playItf, playCallback, this)) {
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ SLuint32 mask = SL_PLAYEVENT_HEADATEND;
+ if (m_notifyInterval && SL_RESULT_SUCCESS == (*m_playItf)->SetPositionUpdatePeriod(m_playItf,
+ m_notifyInterval)) {
+ mask |= SL_PLAYEVENT_HEADATNEWPOS;
+ }
+
+ if (SL_RESULT_SUCCESS != (*m_playItf)->SetCallbackEventsMask(m_playItf, mask)) {
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ // Volume interface
+ if (SL_RESULT_SUCCESS != (*m_playerObject)->GetInterface(m_playerObject,
+ SL_IID_VOLUME,
+ &m_volumeItf)) {
+ setError(QAudio::FatalError);
+ return false;
+ }
+
+ setVolume(m_volume);
+
+ // Buffer size
+ if (m_bufferSize <= 0) {
+ m_bufferSize = m_format.bytesForDuration(DEFAULT_PERIOD_TIME_MS * 1000);
+ } else {
+ const int minimumBufSize = m_format.bytesForDuration(MINIMUM_PERIOD_TIME_MS * 1000);
+ if (m_bufferSize < minimumBufSize)
+ m_bufferSize = minimumBufSize;
+ }
+
+ m_periodSize = m_bufferSize;
+
+ if (!m_buffers)
+ m_buffers = new char[BUFFER_COUNT * m_bufferSize];
+
+ m_clockStamp.restart();
+ setError(QAudio::NoError);
+
+ return true;
+}
+
+void QOpenSLESAudioOutput::destroyPlayer()
+{
+ setState(QAudio::StoppedState);
+
+ // We need to change the state manually...
+ if (m_playItf)
+ (*m_playItf)->SetPlayState(m_playItf, SL_PLAYSTATE_STOPPED);
+
+ if (m_bufferQueueItf && SL_RESULT_SUCCESS != (*m_bufferQueueItf)->Clear(m_bufferQueueItf))
+ qWarning() << "Unable to clear buffer";
+
+ if (m_playerObject) {
+ (*m_playerObject)->Destroy(m_playerObject);
+ m_playerObject = Q_NULLPTR;
+ }
+
+ if (m_outputMixObject) {
+ (*m_outputMixObject)->Destroy(m_outputMixObject);
+ m_outputMixObject = Q_NULLPTR;
+ }
+
+ if (!m_pullMode && m_audioSource) {
+ m_audioSource->close();
+ delete m_audioSource;
+ m_audioSource = Q_NULLPTR;
+ }
+
+ delete [] m_buffers;
+ m_buffers = Q_NULLPTR;
+ m_processedBytes = 0;
+ m_nextBuffer = 0;
+ m_availableBuffers = BUFFER_COUNT;
+ m_playItf = Q_NULLPTR;
+ m_volumeItf = Q_NULLPTR;
+ m_bufferQueueItf = Q_NULLPTR;
+}
+
+qint64 QOpenSLESAudioOutput::writeData(const char *data, qint64 len)
+{
+ if (!len)
+ return 0;
+
+ if (len > m_bufferSize)
+ len = m_bufferSize;
+
+ const int index = m_nextBuffer * m_bufferSize;
+ ::memcpy(m_buffers + index, data, len);
+ const SLuint32 res = (*m_bufferQueueItf)->Enqueue(m_bufferQueueItf,
+ m_buffers + index,
+ len);
+
+ if (res == SL_RESULT_BUFFER_INSUFFICIENT)
+ return 0;
+
+ if (res != SL_RESULT_SUCCESS) {
+ setError(QAudio::FatalError);
+ destroyPlayer();
+ return -1;
+ }
+
+ m_processedBytes += len;
+ m_availableBuffers.fetchAndAddRelaxed(-1);
+ setState(QAudio::ActiveState);
+ setError(QAudio::NoError);
+ m_nextBuffer = (m_nextBuffer + 1) % BUFFER_COUNT;
+
+ return len;
+}
+
+inline void QOpenSLESAudioOutput::setState(QAudio::State state)
+{
+ if (m_state == state)
+ return;
+
+ m_state = state;
+ Q_EMIT stateChanged(m_state);
+}
+
+inline void QOpenSLESAudioOutput::setError(QAudio::Error error)
+{
+ if (m_error == error)
+ return;
+
+ m_error = error;
+ Q_EMIT errorChanged(m_error);
+}
+
+inline SLmillibel QOpenSLESAudioOutput::adjustVolume(qreal vol)
+{
+ if (qFuzzyIsNull(vol))
+ return SL_MILLIBEL_MIN;
+
+ if (qFuzzyCompare(vol, qreal(1.0)))
+ return 0;
+
+ return SL_MILLIBEL_MIN + ((1 - (qLn(10 - (vol * 10)) / qLn(10))) * SL_MILLIBEL_MAX);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/opensles/qopenslesaudiooutput.h b/src/plugins/opensles/qopenslesaudiooutput.h
new file mode 100644
index 000000000..b0f01fa22
--- /dev/null
+++ b/src/plugins/opensles/qopenslesaudiooutput.h
@@ -0,0 +1,155 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QOPENSLESAUDIOOUTPUT_H
+#define QOPENSLESAUDIOOUTPUT_H
+
+#include <qaudiosystem.h>
+#include <SLES/OpenSLES.h>
+#include <qbytearray.h>
+#include <qmap.h>
+#include <QTime>
+
+QT_BEGIN_NAMESPACE
+
+class QOpenSLESAudioOutput : public QAbstractAudioOutput
+{
+ Q_OBJECT
+
+public:
+ QOpenSLESAudioOutput(const QByteArray &device);
+ ~QOpenSLESAudioOutput();
+
+ void start(QIODevice *device) Q_DECL_OVERRIDE;
+ QIODevice *start() Q_DECL_OVERRIDE;
+ void stop() Q_DECL_OVERRIDE;
+ void reset() Q_DECL_OVERRIDE;
+ void suspend() Q_DECL_OVERRIDE;
+ void resume() Q_DECL_OVERRIDE;
+ int bytesFree() const Q_DECL_OVERRIDE;
+ int periodSize() const Q_DECL_OVERRIDE;
+ void setBufferSize(int value) Q_DECL_OVERRIDE;
+ int bufferSize() const Q_DECL_OVERRIDE;
+ void setNotifyInterval(int milliSeconds) Q_DECL_OVERRIDE;
+ int notifyInterval() const Q_DECL_OVERRIDE;
+ qint64 processedUSecs() const Q_DECL_OVERRIDE;
+ qint64 elapsedUSecs() const Q_DECL_OVERRIDE;
+ QAudio::Error error() const Q_DECL_OVERRIDE;
+ QAudio::State state() const Q_DECL_OVERRIDE;
+ void setFormat(const QAudioFormat &format) Q_DECL_OVERRIDE;
+ QAudioFormat format() const Q_DECL_OVERRIDE;
+
+ void setVolume(qreal volume) Q_DECL_OVERRIDE;
+ qreal volume() const Q_DECL_OVERRIDE;
+
+ void setCategory(const QString &category) Q_DECL_OVERRIDE;
+ QString category() const Q_DECL_OVERRIDE;
+
+private:
+ friend class SLIODevicePrivate;
+
+ Q_INVOKABLE void onEOSEvent();
+ void bufferAvailable(quint32 count, quint32 playIndex);
+
+ static void playCallback(SLPlayItf playItf, void *ctx, SLuint32 event);
+ static void bufferQueueCallback(SLBufferQueueItf bufferQueue, void *ctx);
+
+ bool preparePlayer();
+ void destroyPlayer();
+ qint64 writeData(const char *data, qint64 len);
+
+ void setState(QAudio::State state);
+ void setError(QAudio::Error error);
+
+ SLmillibel adjustVolume(qreal vol);
+
+ QByteArray m_deviceName;
+ QAudio::State m_state;
+ QAudio::Error m_error;
+ SLObjectItf m_outputMixObject;
+ SLObjectItf m_playerObject;
+ SLPlayItf m_playItf;
+ SLVolumeItf m_volumeItf;
+ SLBufferQueueItf m_bufferQueueItf;
+ QIODevice *m_audioSource;
+ char *m_buffers;
+ qreal m_volume;
+ bool m_pullMode;
+ int m_nextBuffer;
+ int m_bufferSize;
+ int m_notifyInterval;
+ int m_periodSize;
+ qint64 m_elapsedTime;
+ qint64 m_processedBytes;
+ QAtomicInt m_availableBuffers;
+
+ qint32 m_streamType;
+ QTime m_clockStamp;
+ QAudioFormat m_format;
+ QString m_category;
+ static QMap<QString, qint32> m_categories;
+};
+
+class SLIODevicePrivate : public QIODevice
+{
+ Q_OBJECT
+
+public:
+ inline SLIODevicePrivate(QOpenSLESAudioOutput *audio) : m_audioDevice(audio) {}
+ inline ~SLIODevicePrivate() Q_DECL_OVERRIDE {}
+
+protected:
+ inline qint64 readData(char *, qint64) Q_DECL_OVERRIDE { return 0; }
+ inline qint64 writeData(const char *data, qint64 len) Q_DECL_OVERRIDE;
+
+private:
+ QOpenSLESAudioOutput *m_audioDevice;
+};
+
+qint64 SLIODevicePrivate::writeData(const char *data, qint64 len)
+{
+ Q_ASSERT(m_audioDevice);
+ return m_audioDevice->writeData(data, len);
+}
+
+QT_END_NAMESPACE
+
+#endif // QOPENSLESAUDIOOUTPUT_H
diff --git a/src/plugins/opensles/qopenslesdeviceinfo.cpp b/src/plugins/opensles/qopenslesdeviceinfo.cpp
new file mode 100644
index 000000000..8301beaa5
--- /dev/null
+++ b/src/plugins/opensles/qopenslesdeviceinfo.cpp
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qopenslesdeviceinfo.h"
+
+#include "qopenslesengine.h"
+
+QT_BEGIN_NAMESPACE
+
+QOpenSLESDeviceInfo::QOpenSLESDeviceInfo(const QByteArray &device, QAudio::Mode mode)
+ : m_engine(QOpenSLESEngine::instance())
+ , m_device(device)
+ , m_mode(mode)
+{
+}
+
+bool QOpenSLESDeviceInfo::isFormatSupported(const QAudioFormat &format) const
+{
+ QOpenSLESDeviceInfo *that = const_cast<QOpenSLESDeviceInfo*>(this);
+ return that->supportedCodecs().contains(format.codec())
+ && that->supportedSampleRates().contains(format.sampleRate())
+ && that->supportedChannelCounts().contains(format.channelCount())
+ && that->supportedSampleSizes().contains(format.sampleSize())
+ && that->supportedByteOrders().contains(format.byteOrder())
+ && that->supportedSampleTypes().contains(format.sampleType());
+}
+
+QAudioFormat QOpenSLESDeviceInfo::preferredFormat() const
+{
+ QAudioFormat format;
+ format.setCodec(QStringLiteral("audio/pcm"));
+ format.setSampleSize(16);
+ format.setSampleType(QAudioFormat::SignedInt);
+ format.setSampleRate(44100);
+ format.setChannelCount(m_mode == QAudio::AudioInput ? 1 : 2);
+ return format;
+}
+
+QString QOpenSLESDeviceInfo::deviceName() const
+{
+ return m_device;
+}
+
+QStringList QOpenSLESDeviceInfo::supportedCodecs()
+{
+ return QStringList() << QStringLiteral("audio/pcm");
+}
+
+QList<int> QOpenSLESDeviceInfo::supportedSampleRates()
+{
+ return m_engine->supportedSampleRates(m_mode);
+}
+
+QList<int> QOpenSLESDeviceInfo::supportedChannelCounts()
+{
+ return m_engine->supportedChannelCounts(m_mode);
+}
+
+QList<int> QOpenSLESDeviceInfo::supportedSampleSizes()
+{
+ if (m_mode == QAudio::AudioInput)
+ return QList<int>() << 16;
+ else
+ return QList<int>() << 8 << 16;
+}
+
+QList<QAudioFormat::Endian> QOpenSLESDeviceInfo::supportedByteOrders()
+{
+ return QList<QAudioFormat::Endian>() << QAudioFormat::LittleEndian;
+}
+
+QList<QAudioFormat::SampleType> QOpenSLESDeviceInfo::supportedSampleTypes()
+{
+ return QList<QAudioFormat::SampleType>() << QAudioFormat::SignedInt;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/opensles/qopenslesdeviceinfo.h b/src/plugins/opensles/qopenslesdeviceinfo.h
new file mode 100644
index 000000000..15a5c52f3
--- /dev/null
+++ b/src/plugins/opensles/qopenslesdeviceinfo.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QOPENSLESDEVICEINFO_H
+#define QOPENSLESDEVICEINFO_H
+
+#include <qaudiosystem.h>
+
+QT_BEGIN_NAMESPACE
+
+class QOpenSLESEngine;
+
+class QOpenSLESDeviceInfo : public QAbstractAudioDeviceInfo
+{
+ Q_OBJECT
+
+public:
+ QOpenSLESDeviceInfo(const QByteArray &device, QAudio::Mode mode);
+ ~QOpenSLESDeviceInfo() {}
+
+ QAudioFormat preferredFormat() const;
+ bool isFormatSupported(const QAudioFormat &format) const;
+ QString deviceName() const;
+ QStringList supportedCodecs();
+ QList<int> supportedSampleRates();
+ QList<int> supportedChannelCounts();
+ QList<int> supportedSampleSizes();
+ QList<QAudioFormat::Endian> supportedByteOrders();
+ QList<QAudioFormat::SampleType> supportedSampleTypes();
+
+private:
+ QOpenSLESEngine *m_engine;
+ QByteArray m_device;
+ QAudio::Mode m_mode;
+};
+
+QT_END_NAMESPACE
+
+#endif // QOPENSLESDEVICEINFO_H
diff --git a/src/plugins/opensles/qopenslesengine.cpp b/src/plugins/opensles/qopenslesengine.cpp
new file mode 100644
index 000000000..056b51e26
--- /dev/null
+++ b/src/plugins/opensles/qopenslesengine.cpp
@@ -0,0 +1,207 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qopenslesengine.h"
+
+#include "qopenslesaudioinput.h"
+#include <qdebug.h>
+
+#ifdef ANDROID
+#include <SLES/OpenSLES_Android.h>
+#endif
+
+#define CheckError(message) if (result != SL_RESULT_SUCCESS) { qWarning(message); return; }
+
+Q_GLOBAL_STATIC(QOpenSLESEngine, openslesEngine);
+
+QOpenSLESEngine::QOpenSLESEngine()
+ : m_engineObject(0)
+ , m_engine(0)
+{
+ SLresult result;
+
+ result = slCreateEngine(&m_engineObject, 0, 0, 0, 0, 0);
+ CheckError("Failed to create engine");
+
+ result = (*m_engineObject)->Realize(m_engineObject, SL_BOOLEAN_FALSE);
+ CheckError("Failed to realize engine");
+
+ result = (*m_engineObject)->GetInterface(m_engineObject, SL_IID_ENGINE, &m_engine);
+ CheckError("Failed to get engine interface");
+
+ checkSupportedInputFormats();
+}
+
+QOpenSLESEngine::~QOpenSLESEngine()
+{
+ if (m_engineObject)
+ (*m_engineObject)->Destroy(m_engineObject);
+}
+
+QOpenSLESEngine *QOpenSLESEngine::instance()
+{
+ return openslesEngine();
+}
+
+SLDataFormat_PCM QOpenSLESEngine::audioFormatToSLFormatPCM(const QAudioFormat &format)
+{
+ SLDataFormat_PCM format_pcm;
+ format_pcm.formatType = SL_DATAFORMAT_PCM;
+ format_pcm.numChannels = format.channelCount();
+ format_pcm.samplesPerSec = format.sampleRate() * 1000;
+ format_pcm.bitsPerSample = format.sampleSize();
+ format_pcm.containerSize = format.sampleSize();
+ format_pcm.channelMask = (format.channelCount() == 1 ?
+ SL_SPEAKER_FRONT_CENTER :
+ SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT);
+ format_pcm.endianness = (format.byteOrder() == QAudioFormat::LittleEndian ?
+ SL_BYTEORDER_LITTLEENDIAN :
+ SL_BYTEORDER_BIGENDIAN);
+ return format_pcm;
+
+}
+
+QList<QByteArray> QOpenSLESEngine::availableDevices(QAudio::Mode mode) const
+{
+ QList<QByteArray> devices;
+ if (mode == QAudio::AudioInput) {
+#ifdef ANDROID
+ devices << QT_ANDROID_PRESET_MIC
+ << QT_ANDROID_PRESET_CAMCORDER
+ << QT_ANDROID_PRESET_VOICE_RECOGNITION;
+#else
+ devices << "default";
+#endif
+ } else {
+ devices << "default";
+ }
+ return devices;
+}
+
+QList<int> QOpenSLESEngine::supportedChannelCounts(QAudio::Mode mode) const
+{
+ if (mode == QAudio::AudioInput)
+ return m_supportedInputChannelCounts;
+ else
+ return QList<int>() << 1 << 2;
+}
+
+QList<int> QOpenSLESEngine::supportedSampleRates(QAudio::Mode mode) const
+{
+ if (mode == QAudio::AudioInput) {
+ return m_supportedInputSampleRates;
+ } else {
+ return QList<int>() << 8000 << 11025 << 12000 << 16000 << 22050
+ << 24000 << 32000 << 44100 << 48000;
+ }
+}
+
+void QOpenSLESEngine::checkSupportedInputFormats()
+{
+ m_supportedInputChannelCounts = QList<int>() << 1;
+ m_supportedInputSampleRates.clear();
+
+ SLDataFormat_PCM defaultFormat;
+ defaultFormat.formatType = SL_DATAFORMAT_PCM;
+ defaultFormat.numChannels = 1;
+ defaultFormat.samplesPerSec = SL_SAMPLINGRATE_44_1;
+ defaultFormat.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16;
+ defaultFormat.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16;
+ defaultFormat.channelMask = SL_SPEAKER_FRONT_CENTER;
+ defaultFormat.endianness = SL_BYTEORDER_LITTLEENDIAN;
+
+ const SLuint32 rates[9] = { SL_SAMPLINGRATE_8,
+ SL_SAMPLINGRATE_11_025,
+ SL_SAMPLINGRATE_12,
+ SL_SAMPLINGRATE_16,
+ SL_SAMPLINGRATE_22_05,
+ SL_SAMPLINGRATE_24,
+ SL_SAMPLINGRATE_32,
+ SL_SAMPLINGRATE_44_1,
+ SL_SAMPLINGRATE_48 };
+
+
+ // Test sampling rates
+ for (int i = 0 ; i < 9; ++i) {
+ SLDataFormat_PCM format = defaultFormat;
+ format.samplesPerSec = rates[i];
+
+ if (inputFormatIsSupported(format))
+ m_supportedInputSampleRates.append(rates[i] / 1000);
+
+ }
+
+ // Test if stereo is supported
+ {
+ SLDataFormat_PCM format = defaultFormat;
+ format.numChannels = 2;
+ format.channelMask = 0;
+ if (inputFormatIsSupported(format))
+ m_supportedInputChannelCounts.append(2);
+ }
+}
+
+bool QOpenSLESEngine::inputFormatIsSupported(SLDataFormat_PCM format)
+{
+ SLresult result;
+ SLObjectItf recorder = 0;
+ SLDataLocator_IODevice loc_dev = { SL_DATALOCATOR_IODEVICE, SL_IODEVICE_AUDIOINPUT,
+ SL_DEFAULTDEVICEID_AUDIOINPUT, NULL };
+ SLDataSource audioSrc = { &loc_dev, NULL };
+
+#ifdef ANDROID
+ SLDataLocator_AndroidSimpleBufferQueue loc_bq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 1 };
+#else
+ SLDataLocator_BufferQueue loc_bq = { SL_DATALOCATOR_BUFFERQUEUE, 1 };
+#endif
+ SLDataSink audioSnk = { &loc_bq, &format };
+
+ result = (*m_engine)->CreateAudioRecorder(m_engine, &recorder, &audioSrc, &audioSnk, 0, 0, 0);
+ if (result == SL_RESULT_SUCCESS)
+ result = (*recorder)->Realize(recorder, false);
+
+ if (result == SL_RESULT_SUCCESS) {
+ (*recorder)->Destroy(recorder);
+ return true;
+ }
+
+ return false;
+}
diff --git a/src/multimediawidgets/qpaintervideosurface_mac_p.h b/src/plugins/opensles/qopenslesengine.h
index a56a650d5..9f12ac65d 100644
--- a/src/multimediawidgets/qpaintervideosurface_mac_p.h
+++ b/src/plugins/opensles/qopenslesengine.h
@@ -39,58 +39,44 @@
**
****************************************************************************/
-#ifndef QPAINTERVIDEOSURFACE_MAC_P_H
-#define QPAINTERVIDEOSURFACE_MAC_P_H
+#ifndef QOPENSLESENGINE_H
+#define QOPENSLESENGINE_H
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qpaintervideosurface_p.h"
-#include <qvideosurfaceformat.h>
-#include <qvideoframe.h>
+#include <qglobal.h>
+#include <qaudio.h>
+#include <qlist.h>
+#include <qaudioformat.h>
+#include <SLES/OpenSLES.h>
QT_BEGIN_NAMESPACE
-
-class QVideoSurfaceCoreGraphicsPainter : public QVideoSurfacePainter
+class QOpenSLESEngine
{
public:
- QVideoSurfaceCoreGraphicsPainter(bool glSupported);
- ~QVideoSurfaceCoreGraphicsPainter();
+ QOpenSLESEngine();
+ ~QOpenSLESEngine();
- QList<QVideoFrame::PixelFormat> supportedPixelFormats(
- QAbstractVideoBuffer::HandleType handleType) const;
+ static QOpenSLESEngine *instance();
- bool isFormatSupported(const QVideoSurfaceFormat &format) const;
+ SLEngineItf slEngine() const { return m_engine; }
- QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format);
- void stop();
+ static SLDataFormat_PCM audioFormatToSLFormatPCM(const QAudioFormat &format);
- QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame);
+ QList<QByteArray> availableDevices(QAudio::Mode mode) const;
+ QList<int> supportedChannelCounts(QAudio::Mode mode) const;
+ QList<int> supportedSampleRates(QAudio::Mode mode) const;
- QAbstractVideoSurface::Error paint(
- const QRectF &target, QPainter *painter, const QRectF &source);
+private:
+ void checkSupportedInputFormats();
+ bool inputFormatIsSupported(SLDataFormat_PCM format);
- void updateColors(int brightness, int contrast, int hue, int saturation);
+ SLObjectItf m_engineObject;
+ SLEngineItf m_engine;
-private:
- void* ciContext;
- QList<QVideoFrame::PixelFormat> m_imagePixelFormats;
- QVideoFrame m_frame;
- QSize m_imageSize;
- QImage::Format m_imageFormat;
- QVector<QAbstractVideoBuffer::HandleType> m_supportedHandles;
- QVideoSurfaceFormat::Direction m_scanLineDirection;
+ QList<int> m_supportedInputChannelCounts;
+ QList<int> m_supportedInputSampleRates;
};
QT_END_NAMESPACE
-#endif
+#endif // QOPENSLESENGINE_H
diff --git a/src/plugins/opensles/qopenslesplugin.cpp b/src/plugins/opensles/qopenslesplugin.cpp
new file mode 100644
index 000000000..a7fdb9bd4
--- /dev/null
+++ b/src/plugins/opensles/qopenslesplugin.cpp
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qopenslesplugin.h"
+
+#include "qopenslesengine.h"
+#include "qopenslesdeviceinfo.h"
+#include "qopenslesaudioinput.h"
+#include "qopenslesaudiooutput.h"
+
+QT_BEGIN_NAMESPACE
+
+QOpenSLESPlugin::QOpenSLESPlugin(QObject *parent)
+ : QAudioSystemPlugin(parent)
+ , m_engine(QOpenSLESEngine::instance())
+{
+}
+
+QList<QByteArray> QOpenSLESPlugin::availableDevices(QAudio::Mode mode) const
+{
+ return m_engine->availableDevices(mode);
+}
+
+QAbstractAudioInput *QOpenSLESPlugin::createInput(const QByteArray &device)
+{
+ return new QOpenSLESAudioInput(device);
+}
+
+QAbstractAudioOutput *QOpenSLESPlugin::createOutput(const QByteArray &device)
+{
+ return new QOpenSLESAudioOutput(device);
+}
+
+QAbstractAudioDeviceInfo *QOpenSLESPlugin::createDeviceInfo(const QByteArray &device, QAudio::Mode mode)
+{
+ return new QOpenSLESDeviceInfo(device, mode);
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/plugins/opensles/qopenslesplugin.h b/src/plugins/opensles/qopenslesplugin.h
new file mode 100644
index 000000000..46144abe2
--- /dev/null
+++ b/src/plugins/opensles/qopenslesplugin.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QOPENSLESPLUGIN_H
+#define QOPENSLESPLUGIN_H
+
+#include <qaudiosystemplugin.h>
+
+QT_BEGIN_NAMESPACE
+
+class QOpenSLESEngine;
+
+class QOpenSLESPlugin : public QAudioSystemPlugin
+{
+ Q_OBJECT
+
+ Q_PLUGIN_METADATA(IID "org.qt-project.qt.audiosystemfactory/5.0" FILE "opensles.json")
+
+public:
+ QOpenSLESPlugin(QObject *parent = 0);
+ ~QOpenSLESPlugin() {}
+
+ QList<QByteArray> availableDevices(QAudio::Mode mode) const;
+ QAbstractAudioInput *createInput(const QByteArray &device);
+ QAbstractAudioOutput *createOutput(const QByteArray &device);
+ QAbstractAudioDeviceInfo *createDeviceInfo(const QByteArray &device, QAudio::Mode mode);
+
+private:
+ QOpenSLESEngine *m_engine;
+};
+
+QT_END_NAMESPACE
+
+#endif // QOPENSLESPLUGIN_H
diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro
index 8234e7ee3..b0356636a 100644
--- a/src/plugins/plugins.pro
+++ b/src/plugins/plugins.pro
@@ -47,10 +47,13 @@ unix:!mac {
mac:!simulator {
SUBDIRS += audiocapture
- !ios {
- SUBDIRS += qt7
- config_avfoundation: SUBDIRS += avfoundation
- }
+ config_avfoundation: SUBDIRS += avfoundation
+
+ !ios: SUBDIRS += qt7
+}
+
+config_opensles {
+ SUBDIRS += opensles
}
config_resourcepolicy {
diff --git a/src/plugins/pulseaudio/qaudioinput_pulse.h b/src/plugins/pulseaudio/qaudioinput_pulse.h
index 4c1881e67..bb72628f8 100644
--- a/src/plugins/pulseaudio/qaudioinput_pulse.h
+++ b/src/plugins/pulseaudio/qaudioinput_pulse.h
@@ -130,11 +130,9 @@ private:
int m_bufferSize;
int m_periodSize;
int m_intervalTime;
- unsigned int m_bufferTime;
unsigned int m_periodTime;
QTimer *m_timer;
qint64 m_elapsedTimeOffset;
- char *audioBuffer;
pa_stream *m_stream;
QTime m_timeStamp;
QTime m_clockStamp;
diff --git a/sync.profile b/sync.profile
index 27a84c72c..0d0eb51b7 100644
--- a/sync.profile
+++ b/sync.profile
@@ -24,5 +24,4 @@
"qtbase" => "",
"qtxmlpatterns" => "",
"qtdeclarative" => "",
- "qtjsbackend" => "",
);