Audio probes for AudioCapture plugin.

Change-Id: Iea37d455ee53c9d055af4f9ca62d8a9ea241d31f
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
Reviewed-by: Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com>
This commit is contained in:
Lev Zelenskiy
2012-07-30 13:06:47 +10:00
committed by Qt by Nokia
parent 802176ea8d
commit 8b9b5ba637
6 changed files with 206 additions and 3 deletions

View File

@@ -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

View File

@@ -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));
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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;