summaryrefslogtreecommitdiffstats
path: root/src/plugins/audiocapture
diff options
context:
space:
mode:
authorLev Zelenskiy <lev.zelenskiy@nokia.com>2012-07-30 13:06:47 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-30 08:05:44 +0200
commit8b9b5ba6371b8787b5f6fcf47feaecbcc9fbf36b (patch)
tree0cac83dfe5773799e04c33cff67615a8233b2fa4 /src/plugins/audiocapture
parent802176ea8d5d971796aaa7e655dfff8d81813c40 (diff)
Audio probes for AudioCapture plugin.
Change-Id: Iea37d455ee53c9d055af4f9ca62d8a9ea241d31f Reviewed-by: Michael Goddard <michael.goddard@nokia.com> Reviewed-by: Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com>
Diffstat (limited to 'src/plugins/audiocapture')
-rw-r--r--src/plugins/audiocapture/audiocapture.pro6
-rw-r--r--src/plugins/audiocapture/audiocaptureprobecontrol.cpp60
-rw-r--r--src/plugins/audiocapture/audiocaptureprobecontrol.h61
-rw-r--r--src/plugins/audiocapture/audiocaptureservice.cpp7
-rw-r--r--src/plugins/audiocapture/audiocapturesession.cpp51
-rw-r--r--src/plugins/audiocapture/audiocapturesession.h24
6 files changed, 206 insertions, 3 deletions
diff --git a/src/plugins/audiocapture/audiocapture.pro b/src/plugins/audiocapture/audiocapture.pro
index 9422682b8..6ff7676d6 100644
--- a/src/plugins/audiocapture/audiocapture.pro
+++ b/src/plugins/audiocapture/audiocapture.pro
@@ -13,7 +13,8 @@ HEADERS += audioencodercontrol.h \
audioinputselector.h \
audiocaptureservice.h \
audiocaptureserviceplugin.h \
- audiocapturesession.h
+ audiocapturesession.h \
+ audiocaptureprobecontrol.h
SOURCES += audioencodercontrol.cpp \
audiocontainercontrol.cpp \
@@ -21,7 +22,8 @@ SOURCES += audioencodercontrol.cpp \
audioinputselector.cpp \
audiocaptureservice.cpp \
audiocaptureserviceplugin.cpp \
- audiocapturesession.cpp
+ audiocapturesession.cpp \
+ audiocaptureprobecontrol.cpp
target.path += $$[QT_INSTALL_PLUGINS]/$${PLUGIN_TYPE}
INSTALLS += target
diff --git a/src/plugins/audiocapture/audiocaptureprobecontrol.cpp b/src/plugins/audiocapture/audiocaptureprobecontrol.cpp
new file mode 100644
index 000000000..8e97c4ad9
--- /dev/null
+++ b/src/plugins/audiocapture/audiocaptureprobecontrol.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "audiocaptureprobecontrol.h"
+
+AudioCaptureProbeControl::AudioCaptureProbeControl(QObject *parent):
+ QMediaAudioProbeControl(parent)
+{
+}
+
+AudioCaptureProbeControl::~AudioCaptureProbeControl()
+{
+}
+
+void AudioCaptureProbeControl::bufferProbed(const char *data, quint32 size, const QAudioFormat& format)
+{
+ if (!format.isValid())
+ return;
+
+ QAudioBuffer audioBuffer = QAudioBuffer(QByteArray::fromRawData(data, size), format);
+ QMetaObject::invokeMethod(this, "audioBufferProbed", Qt::QueuedConnection, Q_ARG(QAudioBuffer, audioBuffer));
+}
diff --git a/src/plugins/audiocapture/audiocaptureprobecontrol.h b/src/plugins/audiocapture/audiocaptureprobecontrol.h
new file mode 100644
index 000000000..2dc03fc6a
--- /dev/null
+++ b/src/plugins/audiocapture/audiocaptureprobecontrol.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef AUDIOCAPTUREPROBECONTROL_H
+#define AUDIOCAPTUREPROBECONTROL_H
+
+#include <qmediaaudioprobecontrol.h>
+#include <QtCore/qmutex.h>
+#include <qaudiobuffer.h>
+
+QT_USE_NAMESPACE
+
+class AudioCaptureProbeControl : public QMediaAudioProbeControl
+{
+ Q_OBJECT
+public:
+ explicit AudioCaptureProbeControl(QObject *parent);
+ virtual ~AudioCaptureProbeControl();
+
+ void bufferProbed(const char *data, quint32 size, const QAudioFormat& format);
+};
+
+#endif
diff --git a/src/plugins/audiocapture/audiocaptureservice.cpp b/src/plugins/audiocapture/audiocaptureservice.cpp
index e71b2e1c6..829e9d8e5 100644
--- a/src/plugins/audiocapture/audiocaptureservice.cpp
+++ b/src/plugins/audiocapture/audiocaptureservice.cpp
@@ -45,6 +45,7 @@
#include "audioencodercontrol.h"
#include "audiocontainercontrol.h"
#include "audiomediarecordercontrol.h"
+#include "audiocaptureprobecontrol.h"
AudioCaptureService::AudioCaptureService(QObject *parent):
QMediaService(parent)
@@ -79,6 +80,12 @@ QMediaControl *AudioCaptureService::requestControl(const char *name)
if (qstrcmp(name,QMediaContainerControl_iid) == 0)
return m_containerControl;
+ if (qstrcmp(name,QMediaAudioProbeControl_iid) == 0) {
+ AudioCaptureProbeControl *probe = new AudioCaptureProbeControl(this);
+ m_session->addProbe(probe);
+ return probe;
+ }
+
return 0;
}
diff --git a/src/plugins/audiocapture/audiocapturesession.cpp b/src/plugins/audiocapture/audiocapturesession.cpp
index 9493420d6..8fd36d35b 100644
--- a/src/plugins/audiocapture/audiocapturesession.cpp
+++ b/src/plugins/audiocapture/audiocapturesession.cpp
@@ -47,6 +47,45 @@
#include "qmediarecorder.h"
#include "audiocapturesession.h"
+#include "audiocaptureprobecontrol.h"
+
+void FileProbeProxy::startProbes(const QAudioFormat &format)
+{
+ m_format = format;
+}
+
+void FileProbeProxy::stopProbes()
+{
+ m_format = QAudioFormat();
+}
+
+void FileProbeProxy::addProbe(AudioCaptureProbeControl *probe)
+{
+ QMutexLocker locker(&m_probeMutex);
+
+ if (m_probes.contains(probe))
+ return;
+
+ m_probes.append(probe);
+}
+
+void FileProbeProxy::removeProbe(AudioCaptureProbeControl *probe)
+{
+ QMutexLocker locker(&m_probeMutex);
+ m_probes.removeOne(probe);
+}
+
+qint64 FileProbeProxy::writeData(const char *data, qint64 len)
+{
+ if (m_format.isValid()) {
+ QMutexLocker locker(&m_probeMutex);
+
+ foreach (AudioCaptureProbeControl* probe, m_probes)
+ probe->bufferProbed(data, len, m_format);
+ }
+
+ return QFile::writeData(data, len);
+}
AudioCaptureSession::AudioCaptureSession(QObject *parent):
QObject(parent)
@@ -274,6 +313,7 @@ void AudioCaptureSession::record()
if (wavFile)
file.write((char*)&header,sizeof(CombinedHeader));
+ file.startProbes(m_format);
m_audioInput->start(qobject_cast<QIODevice*>(&file));
} else {
emit error(1,QString("can't open source, failed"));
@@ -298,6 +338,7 @@ void AudioCaptureSession::stop()
{
if(m_audioInput) {
m_audioInput->stop();
+ file.stopProbes();
file.close();
if (wavFile) {
qint32 fileSize = file.size()-8;
@@ -314,6 +355,16 @@ void AudioCaptureSession::stop()
m_state = QMediaRecorder::StoppedState;
}
+void AudioCaptureSession::addProbe(AudioCaptureProbeControl *probe)
+{
+ file.addProbe(probe);
+}
+
+void AudioCaptureSession::removeProbe(AudioCaptureProbeControl *probe)
+{
+ file.removeProbe(probe);
+}
+
void AudioCaptureSession::stateChanged(QAudio::State state)
{
switch(state) {
diff --git a/src/plugins/audiocapture/audiocapturesession.h b/src/plugins/audiocapture/audiocapturesession.h
index 4d1374391..d1241a8b6 100644
--- a/src/plugins/audiocapture/audiocapturesession.h
+++ b/src/plugins/audiocapture/audiocapturesession.h
@@ -45,6 +45,7 @@
#include <QFile>
#include <QUrl>
#include <QDir>
+#include <QMutex>
#include "audioencodercontrol.h"
#include "audioinputselector.h"
@@ -56,6 +57,25 @@
QT_USE_NAMESPACE
+class AudioCaptureProbeControl;
+
+class FileProbeProxy: public QFile {
+public:
+ void startProbes(const QAudioFormat& format);
+ void stopProbes();
+ void addProbe(AudioCaptureProbeControl *probe);
+ void removeProbe(AudioCaptureProbeControl *probe);
+
+protected:
+ virtual qint64 writeData(const char *data, qint64 len);
+
+private:
+ QAudioFormat m_format;
+ QList<AudioCaptureProbeControl*> m_probes;
+ QMutex m_probeMutex;
+};
+
+
class AudioCaptureSession : public QObject
{
Q_OBJECT
@@ -80,6 +100,8 @@ public:
void record();
void pause();
void stop();
+ void addProbe(AudioCaptureProbeControl *probe);
+ void removeProbe(AudioCaptureProbeControl *probe);
public slots:
void setCaptureDevice(const QString &deviceName);
@@ -97,7 +119,7 @@ private:
QDir defaultDir() const;
QString generateFileName(const QDir &dir, const QString &ext) const;
- QFile file;
+ FileProbeProxy file;
QString m_captureDevice;
QUrl m_sink;
QUrl m_actualSink;