summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/audiocapture/audiocaptureprobecontrol.cpp4
-rw-r--r--src/plugins/audiocapture/audiocaptureprobecontrol.h4
-rw-r--r--src/plugins/audiocapture/audiocaptureservice.cpp4
-rw-r--r--src/plugins/audiocapture/audiocaptureservice.h6
-rw-r--r--src/plugins/audiocapture/audiocaptureserviceplugin.cpp2
-rw-r--r--src/plugins/audiocapture/audiocaptureserviceplugin.h4
-rw-r--r--src/plugins/audiocapture/audiocapturesession.cpp322
-rw-r--r--src/plugins/audiocapture/audiocapturesession.h48
-rw-r--r--src/plugins/audiocapture/audiocontainercontrol.cpp16
-rw-r--r--src/plugins/audiocapture/audiocontainercontrol.h6
-rw-r--r--src/plugins/audiocapture/audioencodercontrol.cpp127
-rw-r--r--src/plugins/audiocapture/audioencodercontrol.h10
-rw-r--r--src/plugins/audiocapture/audioinputselector.cpp5
-rw-r--r--src/plugins/audiocapture/audioinputselector.h6
-rw-r--r--src/plugins/audiocapture/audiomediarecordercontrol.cpp72
-rw-r--r--src/plugins/audiocapture/audiomediarecordercontrol.h15
16 files changed, 347 insertions, 304 deletions
diff --git a/src/plugins/audiocapture/audiocaptureprobecontrol.cpp b/src/plugins/audiocapture/audiocaptureprobecontrol.cpp
index 38f263be9..323aec622 100644
--- a/src/plugins/audiocapture/audiocaptureprobecontrol.cpp
+++ b/src/plugins/audiocapture/audiocaptureprobecontrol.cpp
@@ -41,6 +41,8 @@
#include "audiocaptureprobecontrol.h"
+QT_BEGIN_NAMESPACE
+
AudioCaptureProbeControl::AudioCaptureProbeControl(QObject *parent):
QMediaAudioProbeControl(parent)
{
@@ -58,3 +60,5 @@ void AudioCaptureProbeControl::bufferProbed(const char *data, quint32 size, cons
QAudioBuffer audioBuffer = QAudioBuffer(QByteArray::fromRawData(data, size), format);
QMetaObject::invokeMethod(this, "audioBufferProbed", Qt::QueuedConnection, Q_ARG(QAudioBuffer, audioBuffer));
}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audiocaptureprobecontrol.h b/src/plugins/audiocapture/audiocaptureprobecontrol.h
index 64d31601a..f1df8a1c7 100644
--- a/src/plugins/audiocapture/audiocaptureprobecontrol.h
+++ b/src/plugins/audiocapture/audiocaptureprobecontrol.h
@@ -46,7 +46,7 @@
#include <QtCore/qmutex.h>
#include <qaudiobuffer.h>
-QT_USE_NAMESPACE
+QT_BEGIN_NAMESPACE
class AudioCaptureProbeControl : public QMediaAudioProbeControl
{
@@ -58,4 +58,6 @@ public:
void bufferProbed(const char *data, quint32 size, const QAudioFormat& format);
};
+QT_END_NAMESPACE
+
#endif
diff --git a/src/plugins/audiocapture/audiocaptureservice.cpp b/src/plugins/audiocapture/audiocaptureservice.cpp
index fa9045646..044ac97a4 100644
--- a/src/plugins/audiocapture/audiocaptureservice.cpp
+++ b/src/plugins/audiocapture/audiocaptureservice.cpp
@@ -47,6 +47,8 @@
#include "audiomediarecordercontrol.h"
#include "audiocaptureprobecontrol.h"
+QT_BEGIN_NAMESPACE
+
AudioCaptureService::AudioCaptureService(QObject *parent):
QMediaService(parent)
{
@@ -94,4 +96,4 @@ void AudioCaptureService::releaseControl(QMediaControl *control)
Q_UNUSED(control)
}
-
+QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audiocaptureservice.h b/src/plugins/audiocapture/audiocaptureservice.h
index 2c1e81642..6805168b8 100644
--- a/src/plugins/audiocapture/audiocaptureservice.h
+++ b/src/plugins/audiocapture/audiocaptureservice.h
@@ -46,14 +46,14 @@
#include "qmediaservice.h"
+QT_BEGIN_NAMESPACE
+
class AudioCaptureSession;
class AudioEncoderControl;
class AudioContainerControl;
class AudioMediaRecorderControl;
class AudioInputSelector;
-QT_USE_NAMESPACE
-
class AudioCaptureService : public QMediaService
{
Q_OBJECT
@@ -71,4 +71,6 @@ private:
AudioMediaRecorderControl *m_mediaControl;
};
+QT_END_NAMESPACE
+
#endif
diff --git a/src/plugins/audiocapture/audiocaptureserviceplugin.cpp b/src/plugins/audiocapture/audiocaptureserviceplugin.cpp
index eafe18b8e..c3ae8af27 100644
--- a/src/plugins/audiocapture/audiocaptureserviceplugin.cpp
+++ b/src/plugins/audiocapture/audiocaptureserviceplugin.cpp
@@ -46,6 +46,7 @@
#include "qmediaserviceproviderplugin.h"
+QT_BEGIN_NAMESPACE
QMediaService* AudioCaptureServicePlugin::create(QString const& key)
{
@@ -60,3 +61,4 @@ void AudioCaptureServicePlugin::release(QMediaService *service)
delete service;
}
+QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audiocaptureserviceplugin.h b/src/plugins/audiocapture/audiocaptureserviceplugin.h
index eba64a3a7..cf51c7428 100644
--- a/src/plugins/audiocapture/audiocaptureserviceplugin.h
+++ b/src/plugins/audiocapture/audiocaptureserviceplugin.h
@@ -45,7 +45,7 @@
#include "qmediaserviceproviderplugin.h"
-QT_USE_NAMESPACE
+QT_BEGIN_NAMESPACE
class AudioCaptureServicePlugin : public QMediaServiceProviderPlugin
{
@@ -58,4 +58,6 @@ public:
void release(QMediaService *service);
};
+QT_END_NAMESPACE
+
#endif // AUDIOCAPTURESERVICEPLUGIN_H
diff --git a/src/plugins/audiocapture/audiocapturesession.cpp b/src/plugins/audiocapture/audiocapturesession.cpp
index e242b4c3b..e34c0ee7d 100644
--- a/src/plugins/audiocapture/audiocapturesession.cpp
+++ b/src/plugins/audiocapture/audiocapturesession.cpp
@@ -49,6 +49,8 @@
#include "audiocapturesession.h"
#include "audiocaptureprobecontrol.h"
+QT_BEGIN_NAMESPACE
+
void FileProbeProxy::startProbes(const QAudioFormat &format)
{
m_format = format;
@@ -87,33 +89,20 @@ qint64 FileProbeProxy::writeData(const char *data, qint64 len)
return QFile::writeData(data, len);
}
-AudioCaptureSession::AudioCaptureSession(QObject *parent):
- QObject(parent)
+AudioCaptureSession::AudioCaptureSession(QObject *parent)
+ : QObject(parent)
+ , m_state(QMediaRecorder::StoppedState)
+ , m_status(QMediaRecorder::UnloadedStatus)
+ , m_audioInput(0)
+ , m_deviceInfo(QAudioDeviceInfo::defaultInputDevice())
+ , m_wavFile(true)
{
- m_deviceInfo = new QAudioDeviceInfo(QAudioDeviceInfo::defaultInputDevice());
- m_audioInput = 0;
- m_position = 0;
- m_state = QMediaRecorder::StoppedState;
-
- m_format.setSampleRate(8000);
- m_format.setChannelCount(1);
- m_format.setSampleSize(8);
- m_format.setSampleType(QAudioFormat::UnSignedInt);
- m_format.setCodec("audio/pcm");
- wavFile = true;
+ m_format = m_deviceInfo.preferredFormat();
}
AudioCaptureSession::~AudioCaptureSession()
{
- stop();
-
- if(m_audioInput)
- delete m_audioInput;
-}
-
-QAudioDeviceInfo* AudioCaptureSession::deviceInfo() const
-{
- return m_deviceInfo;
+ setState(QMediaRecorder::StoppedState);
}
QAudioFormat AudioCaptureSession::format() const
@@ -121,118 +110,96 @@ QAudioFormat AudioCaptureSession::format() const
return m_format;
}
-bool AudioCaptureSession::isFormatSupported(const QAudioFormat &format) const
+void AudioCaptureSession::setFormat(const QAudioFormat &format)
{
- if(m_deviceInfo) {
- if(format.codec().contains(QLatin1String("audio/x-wav"))) {
- QAudioFormat fmt = format;
- fmt.setCodec("audio/pcm");
- return m_deviceInfo->isFormatSupported(fmt);
- } else
- return m_deviceInfo->isFormatSupported(format);
- }
- return false;
+ m_format = format;
}
-bool AudioCaptureSession::setFormat(const QAudioFormat &format)
+void AudioCaptureSession::setContainerFormat(const QString &formatMimeType)
{
- if(m_deviceInfo) {
-
- QAudioFormat fmt = format;
-
- if(m_deviceInfo->isFormatSupported(fmt)) {
- m_format = fmt;
- if(m_audioInput) delete m_audioInput;
- m_audioInput = 0;
- QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
- for(int i=0;i<devices.size();i++) {
- if(qstrcmp(m_deviceInfo->deviceName().toLocal8Bit().constData(),
- devices.at(i).deviceName().toLocal8Bit().constData()) == 0) {
- m_audioInput = new QAudioInput(devices.at(i),m_format);
- connect(m_audioInput,SIGNAL(stateChanged(QAudio::State)),this,SLOT(stateChanged(QAudio::State)));
- connect(m_audioInput,SIGNAL(notify()),this,SLOT(notify()));
- break;
- }
- }
- } else {
- m_format = m_deviceInfo->preferredFormat();
- qWarning()<<"failed to setFormat using preferred...";
- }
- }
- return false;
+ m_wavFile = (formatMimeType.isEmpty()
+ || QString::compare(formatMimeType, QLatin1String("audio/x-wav")) == 0);
}
-QStringList AudioCaptureSession::supportedContainers() const
+QString AudioCaptureSession::containerFormat() const
{
- QStringList list;
- if(m_deviceInfo) {
- if (m_deviceInfo->supportedCodecs().size() > 0) {
- list << "audio/x-wav";
- list << "audio/pcm";
- }
- }
- return list;
+ if (m_wavFile)
+ return QStringLiteral("audio/x-wav");
+
+ return QStringLiteral("audio/x-raw");
}
-QString AudioCaptureSession::containerDescription(const QString &formatMimeType) const
+QUrl AudioCaptureSession::outputLocation() const
{
- if(m_deviceInfo) {
- if (formatMimeType.contains(QLatin1String("audio/pcm")))
- return tr("RAW file format");
- if (formatMimeType.contains(QLatin1String("audio/x-wav")))
- return tr("WAV file format");
- }
- return QString();
+ return m_actualOutputLocation;
}
-void AudioCaptureSession::setContainerFormat(const QString &formatMimeType)
+bool AudioCaptureSession::setOutputLocation(const QUrl& location)
{
- if (!formatMimeType.contains(QLatin1String("audio/x-wav")) &&
- !formatMimeType.contains(QLatin1String("audio/pcm")) &&
- !formatMimeType.isEmpty())
- return;
+ if (m_requestedOutputLocation == location)
+ return false;
- if(m_deviceInfo) {
- if (!m_deviceInfo->supportedCodecs().contains(QLatin1String("audio/pcm")))
- return;
+ m_actualOutputLocation = QUrl();
+ m_requestedOutputLocation = location;
- if (formatMimeType.isEmpty() || formatMimeType.contains(QLatin1String("audio/x-wav"))) {
- wavFile = true;
- m_format.setCodec("audio/pcm");
- } else {
- wavFile = false;
- m_format.setCodec(formatMimeType);
- }
+ if (m_requestedOutputLocation.isEmpty())
+ return true;
+
+ if (m_requestedOutputLocation.isValid() && (m_requestedOutputLocation.isLocalFile()
+ || m_requestedOutputLocation.isRelative())) {
+ emit actualLocationChanged(m_requestedOutputLocation);
+ return true;
}
+
+ m_requestedOutputLocation = QUrl();
+ return false;
}
-QString AudioCaptureSession::containerFormat() const
+qint64 AudioCaptureSession::position() const
{
- if(wavFile)
- return QString("audio/x-wav");
-
- return QString("audio/pcm");
+ if (m_audioInput)
+ return m_audioInput->processedUSecs() / 1000;
+ return 0;
}
-QUrl AudioCaptureSession::outputLocation() const
+void AudioCaptureSession::setState(QMediaRecorder::State state)
{
- return m_actualSink;
+ if (m_state == state)
+ return;
+
+ m_state = state;
+ emit stateChanged(m_state);
+
+ switch (m_state) {
+ case QMediaRecorder::StoppedState:
+ stop();
+ break;
+ case QMediaRecorder::PausedState:
+ pause();
+ break;
+ case QMediaRecorder::RecordingState:
+ record();
+ break;
+ }
}
-bool AudioCaptureSession::setOutputLocation(const QUrl& sink)
+QMediaRecorder::State AudioCaptureSession::state() const
{
- m_sink = m_actualSink = sink;
- return true;
+ return m_state;
}
-qint64 AudioCaptureSession::position() const
+void AudioCaptureSession::setStatus(QMediaRecorder::Status status)
{
- return m_position;
+ if (m_status == status)
+ return;
+
+ m_status = status;
+ emit statusChanged(m_status);
}
-int AudioCaptureSession::state() const
+QMediaRecorder::Status AudioCaptureSession::status() const
{
- return int(m_state);
+ return m_status;
}
QDir AudioCaptureSession::defaultDir() const
@@ -258,9 +225,29 @@ QDir AudioCaptureSession::defaultDir() const
return QDir();
}
-QString AudioCaptureSession::generateFileName(const QDir &dir, const QString &ext) const
+QString AudioCaptureSession::generateFileName(const QString &requestedName,
+ const QString &extension) const
{
+ if (requestedName.isEmpty())
+ return generateFileName(defaultDir(), extension);
+
+ QString path = requestedName;
+
+ if (QFileInfo(path).isRelative())
+ path = defaultDir().absoluteFilePath(path);
+
+ if (QFileInfo(path).isDir())
+ return generateFileName(QDir(path), extension);
+ if (!path.endsWith(extension))
+ path.append(QString(".%1").arg(extension));
+
+ return path;
+}
+
+QString AudioCaptureSession::generateFileName(const QDir &dir,
+ const QString &ext) const
+{
int lastClip = 0;
foreach(QString fileName, dir.entryList(QStringList() << QString("clip_*.%1").arg(ext))) {
int imgNumber = fileName.mid(5, fileName.size()-6-ext.length()).toInt();
@@ -277,25 +264,45 @@ QString AudioCaptureSession::generateFileName(const QDir &dir, const QString &ex
void AudioCaptureSession::record()
{
- if(!m_audioInput) {
- setFormat(m_format);
- }
+ if (m_status == QMediaRecorder::PausedStatus) {
+ m_audioInput->resume();
+ } else {
+ if (m_deviceInfo.isNull()) {
+ emit error(QMediaRecorder::ResourceError,
+ QStringLiteral("No input device available."));
+ m_state = QMediaRecorder::StoppedState;
+ emit stateChanged(m_state);
+ setStatus(QMediaRecorder::UnavailableStatus);
+ return;
+ }
- m_actualSink = m_sink;
+ setStatus(QMediaRecorder::LoadingStatus);
- if (m_actualSink.isEmpty()) {
- QString ext = wavFile ? QLatin1String("wav") : QLatin1String("raw");
- m_actualSink = generateFileName(defaultDir(), ext);
- }
+ m_format = m_deviceInfo.nearestFormat(m_format);
+ m_audioInput = new QAudioInput(m_deviceInfo, m_format);
+ connect(m_audioInput, SIGNAL(stateChanged(QAudio::State)),
+ this, SLOT(audioInputStateChanged(QAudio::State)));
+ connect(m_audioInput, SIGNAL(notify()),
+ this, SLOT(notify()));
- if(m_actualSink.toLocalFile().length() > 0)
- file.setFileName(m_actualSink.toLocalFile());
- else
- file.setFileName(m_actualSink.toString());
- if(m_audioInput) {
- if(m_state == QMediaRecorder::StoppedState) {
- if(file.open(QIODevice::WriteOnly)) {
+ QString filePath = generateFileName(
+ m_requestedOutputLocation.isLocalFile() ? m_requestedOutputLocation.toLocalFile()
+ : m_requestedOutputLocation.toString(),
+ m_wavFile ? QLatin1String("wav")
+ : QLatin1String("raw"));
+
+ m_actualOutputLocation = QUrl::fromLocalFile(filePath);
+ if (m_actualOutputLocation != m_requestedOutputLocation)
+ emit actualLocationChanged(m_actualOutputLocation);
+
+ file.setFileName(filePath);
+
+ setStatus(QMediaRecorder::LoadedStatus);
+ setStatus(QMediaRecorder::StartingStatus);
+
+ if (file.open(QIODevice::WriteOnly)) {
+ if (m_wavFile) {
memset(&header,0,sizeof(CombinedHeader));
memcpy(header.riff.descriptor.id,"RIFF",4);
header.riff.descriptor.size = 0xFFFFFFFF; // This should be updated on stop(), filesize-8
@@ -310,28 +317,26 @@ void AudioCaptureSession::record()
header.wave.bitsPerSample = m_format.sampleSize();
memcpy(header.data.descriptor.id,"data",4);
header.data.descriptor.size = 0xFFFFFFFF; // This should be updated on stop(),samples*channels*sampleSize/8
- 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"));
- m_state = QMediaRecorder::StoppedState;
- emit stateChanged(m_state);
+ file.write((char*)&header,sizeof(CombinedHeader));
}
+
+ file.startProbes(m_format);
+ m_audioInput->start(qobject_cast<QIODevice*>(&file));
+ } else {
+ delete m_audioInput;
+ m_audioInput = 0;
+ emit error(QMediaRecorder::ResourceError,
+ QStringLiteral("Can't open output location"));
+ m_state = QMediaRecorder::StoppedState;
+ emit stateChanged(m_state);
+ setStatus(QMediaRecorder::UnloadedStatus);
}
}
-
- m_state = QMediaRecorder::RecordingState;
}
void AudioCaptureSession::pause()
{
- if(m_audioInput)
- m_audioInput->stop();
-
- m_state = QMediaRecorder::PausedState;
+ m_audioInput->suspend();
}
void AudioCaptureSession::stop()
@@ -340,7 +345,7 @@ void AudioCaptureSession::stop()
m_audioInput->stop();
file.stopProbes();
file.close();
- if (wavFile) {
+ if (m_wavFile) {
qint32 fileSize = file.size()-8;
file.open(QIODevice::ReadWrite | QIODevice::Unbuffered);
file.read((char*)&header,sizeof(CombinedHeader));
@@ -350,9 +355,10 @@ void AudioCaptureSession::stop()
file.write((char*)&header,sizeof(CombinedHeader));
file.close();
}
- m_position = 0;
+ delete m_audioInput;
+ m_audioInput = 0;
+ setStatus(QMediaRecorder::UnloadedStatus);
}
- m_state = QMediaRecorder::StoppedState;
}
void AudioCaptureSession::addProbe(AudioCaptureProbeControl *probe)
@@ -365,45 +371,41 @@ void AudioCaptureSession::removeProbe(AudioCaptureProbeControl *probe)
file.removeProbe(probe);
}
-void AudioCaptureSession::stateChanged(QAudio::State state)
+void AudioCaptureSession::audioInputStateChanged(QAudio::State state)
{
switch(state) {
- case QAudio::ActiveState:
- emit stateChanged(QMediaRecorder::RecordingState);
- break;
- default:
- if(!((m_state == QMediaRecorder::PausedState)||(m_state == QMediaRecorder::StoppedState)))
- m_state = QMediaRecorder::StoppedState;
-
- emit stateChanged(m_state);
- break;
+ case QAudio::ActiveState:
+ setStatus(QMediaRecorder::RecordingStatus);
+ break;
+ case QAudio::SuspendedState:
+ setStatus(QMediaRecorder::PausedStatus);
+ break;
+ case QAudio::StoppedState:
+ setStatus(QMediaRecorder::FinalizingStatus);
+ break;
+ default:
+ break;
}
}
void AudioCaptureSession::notify()
{
- m_position += m_audioInput->notifyInterval();
- emit positionChanged(m_position);
+ emit positionChanged(position());
}
void AudioCaptureSession::setCaptureDevice(const QString &deviceName)
{
m_captureDevice = deviceName;
- if(m_deviceInfo)
- delete m_deviceInfo;
-
- m_deviceInfo = 0;
QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
- for(int i = 0; i < devices.size(); i++) {
- if(qstrcmp(m_captureDevice.toLocal8Bit().constData(),
- devices.at(i).deviceName().toLocal8Bit().constData())==0){
- m_deviceInfo = new QAudioDeviceInfo(devices.at(i));
+ for (int i = 0; i < devices.size(); ++i) {
+ QAudioDeviceInfo info = devices.at(i);
+ if (m_captureDevice == info.deviceName()){
+ m_deviceInfo = info;
return;
}
}
- m_deviceInfo = new QAudioDeviceInfo(QAudioDeviceInfo::defaultInputDevice());
+ m_deviceInfo = QAudioDeviceInfo::defaultInputDevice();
}
-
-
+QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audiocapturesession.h b/src/plugins/audiocapture/audiocapturesession.h
index a6b7fa369..86f98db6c 100644
--- a/src/plugins/audiocapture/audiocapturesession.h
+++ b/src/plugins/audiocapture/audiocapturesession.h
@@ -55,7 +55,7 @@
#include <qaudioinput.h>
#include <qaudiodeviceinfo.h>
-QT_USE_NAMESPACE
+QT_BEGIN_NAMESPACE
class AudioCaptureProbeControl;
@@ -85,50 +85,58 @@ public:
~AudioCaptureSession();
QAudioFormat format() const;
- QAudioDeviceInfo* deviceInfo() const;
- bool isFormatSupported(const QAudioFormat &format) const;
- bool setFormat(const QAudioFormat &format);
- QStringList supportedContainers() const;
+ void setFormat(const QAudioFormat &format);
+
QString containerFormat() const;
void setContainerFormat(const QString &formatMimeType);
- QString containerDescription(const QString &formatMimeType) const;
QUrl outputLocation() const;
- bool setOutputLocation(const QUrl& sink);
+ bool setOutputLocation(const QUrl& location);
+
qint64 position() const;
- int state() const;
- void record();
- void pause();
- void stop();
+
+ void setState(QMediaRecorder::State state);
+ QMediaRecorder::State state() const;
+ QMediaRecorder::Status status() const;
+
void addProbe(AudioCaptureProbeControl *probe);
void removeProbe(AudioCaptureProbeControl *probe);
-public slots:
void setCaptureDevice(const QString &deviceName);
signals:
void stateChanged(QMediaRecorder::State state);
+ void statusChanged(QMediaRecorder::Status status);
void positionChanged(qint64 position);
+ void actualLocationChanged(const QUrl &location);
void error(int error, const QString &errorString);
private slots:
- void stateChanged(QAudio::State state);
+ void audioInputStateChanged(QAudio::State state);
void notify();
private:
+ void record();
+ void pause();
+ void stop();
+
+ void setStatus(QMediaRecorder::Status status);
+
QDir defaultDir() const;
- QString generateFileName(const QDir &dir, const QString &ext) const;
+ QString generateFileName(const QString &requestedName,
+ const QString &extension) const;
+ QString generateFileName(const QDir &dir, const QString &extension) const;
FileProbeProxy file;
QString m_captureDevice;
- QUrl m_sink;
- QUrl m_actualSink;
+ QUrl m_requestedOutputLocation;
+ QUrl m_actualOutputLocation;
QMediaRecorder::State m_state;
+ QMediaRecorder::Status m_status;
QAudioInput *m_audioInput;
- QAudioDeviceInfo *m_deviceInfo;
+ QAudioDeviceInfo m_deviceInfo;
QAudioFormat m_format;
- qint64 m_position;
- bool wavFile;
+ bool m_wavFile;
// WAV header stuff
@@ -171,4 +179,6 @@ private:
CombinedHeader header;
};
+QT_END_NAMESPACE
+
#endif
diff --git a/src/plugins/audiocapture/audiocontainercontrol.cpp b/src/plugins/audiocapture/audiocontainercontrol.cpp
index fec190e96..20f373b44 100644
--- a/src/plugins/audiocapture/audiocontainercontrol.cpp
+++ b/src/plugins/audiocapture/audiocontainercontrol.cpp
@@ -42,6 +42,8 @@
#include "audiocontainercontrol.h"
#include "audiocapturesession.h"
+QT_BEGIN_NAMESPACE
+
AudioContainerControl::AudioContainerControl(QObject *parent)
:QMediaContainerControl(parent)
{
@@ -54,7 +56,8 @@ AudioContainerControl::~AudioContainerControl()
QStringList AudioContainerControl::supportedContainers() const
{
- return m_session->supportedContainers();
+ return QStringList() << QStringLiteral("audio/x-wav")
+ << QStringLiteral("audio/x-raw");
}
QString AudioContainerControl::containerFormat() const
@@ -64,11 +67,18 @@ QString AudioContainerControl::containerFormat() const
void AudioContainerControl::setContainerFormat(const QString &formatMimeType)
{
- m_session->setContainerFormat(formatMimeType);
+ if (formatMimeType.isEmpty() || supportedContainers().contains(formatMimeType))
+ m_session->setContainerFormat(formatMimeType);
}
QString AudioContainerControl::containerDescription(const QString &formatMimeType) const
{
- return m_session->containerDescription(formatMimeType);
+ if (QString::compare(formatMimeType, QLatin1String("audio/x-raw")) == 0)
+ return tr("RAW (headerless) file format");
+ if (QString::compare(formatMimeType, QLatin1String("audio/x-wav")) == 0)
+ return tr("WAV file format");
+
+ return QString();
}
+QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audiocontainercontrol.h b/src/plugins/audiocapture/audiocontainercontrol.h
index 18a335702..8c0a67cb8 100644
--- a/src/plugins/audiocapture/audiocontainercontrol.h
+++ b/src/plugins/audiocapture/audiocontainercontrol.h
@@ -47,9 +47,9 @@
#include <QtCore/qstringlist.h>
#include <QtCore/qmap.h>
-class AudioCaptureSession;
+QT_BEGIN_NAMESPACE
-QT_USE_NAMESPACE
+class AudioCaptureSession;
class AudioContainerControl : public QMediaContainerControl
{
@@ -67,4 +67,6 @@ private:
AudioCaptureSession* m_session;
};
+QT_END_NAMESPACE
+
#endif
diff --git a/src/plugins/audiocapture/audioencodercontrol.cpp b/src/plugins/audiocapture/audioencodercontrol.cpp
index 09890f45c..6601cfbdc 100644
--- a/src/plugins/audiocapture/audioencodercontrol.cpp
+++ b/src/plugins/audiocapture/audioencodercontrol.cpp
@@ -46,26 +46,43 @@
#include <QtCore/qdebug.h>
+QT_BEGIN_NAMESPACE
+
+static QAudioFormat audioSettingsToAudioFormat(const QAudioEncoderSettings &settings)
+{
+ QAudioFormat fmt;
+ fmt.setCodec(settings.codec());
+ fmt.setChannelCount(settings.channelCount());
+ fmt.setSampleRate(settings.sampleRate());
+ if (settings.sampleRate() == 8000 && settings.bitRate() == 8000) {
+ fmt.setSampleType(QAudioFormat::UnSignedInt);
+ fmt.setSampleSize(8);
+ } else {
+ fmt.setSampleSize(16);
+ fmt.setSampleType(QAudioFormat::SignedInt);
+ }
+ fmt.setByteOrder(QAudioDeviceInfo::defaultInputDevice().preferredFormat().byteOrder());
+ return fmt;
+}
+
+static QAudioEncoderSettings audioFormatToAudioSettings(const QAudioFormat &format)
+{
+ QAudioEncoderSettings settings;
+ settings.setCodec(format.codec());
+ settings.setChannelCount(format.channelCount());
+ settings.setSampleRate(format.sampleRate());
+ settings.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
+ settings.setBitRate(format.channelCount()
+ * format.sampleSize()
+ * format.sampleRate());
+ return settings;
+}
+
AudioEncoderControl::AudioEncoderControl(QObject *parent)
:QAudioEncoderSettingsControl(parent)
{
m_session = qobject_cast<AudioCaptureSession*>(parent);
-
- QT_PREPEND_NAMESPACE(QAudioFormat) fmt;
- fmt.setSampleSize(8);
- fmt.setChannelCount(1);
- fmt.setSampleRate(8000);
- fmt.setSampleType(QT_PREPEND_NAMESPACE(QAudioFormat)::SignedInt);
- fmt.setCodec("audio/pcm");
- fmt.setByteOrder(QAudioFormat::LittleEndian);
- m_session->setFormat(fmt);
-
- m_settings.setEncodingMode(QMultimedia::ConstantQualityEncoding);
- m_settings.setCodec("audio/pcm");
- m_settings.setBitRate(8000);
- m_settings.setChannelCount(1);
- m_settings.setSampleRate(8000);
- m_settings.setQuality(QMultimedia::LowQuality);
+ update();
}
AudioEncoderControl::~AudioEncoderControl()
@@ -74,71 +91,85 @@ AudioEncoderControl::~AudioEncoderControl()
QStringList AudioEncoderControl::supportedAudioCodecs() const
{
- QStringList list;
- if (m_session->supportedContainers().size() > 0)
- list.append("audio/pcm");
-
- return list;
+ return QStringList() << QStringLiteral("audio/pcm");
}
QString AudioEncoderControl::codecDescription(const QString &codecName) const
{
- if (codecName.contains(QLatin1String("audio/pcm")))
- return tr("PCM audio data");
+ if (QString::compare(codecName, QLatin1String("audio/pcm")) == 0)
+ return tr("Linear PCM audio data");
return QString();
}
-QList<int> AudioEncoderControl::supportedSampleRates(const QAudioEncoderSettings &, bool *continuous) const
+QList<int> AudioEncoderControl::supportedSampleRates(const QAudioEncoderSettings &settings, bool *continuous) const
{
if (continuous)
*continuous = false;
- return m_session->deviceInfo()->supportedSampleRates();
+ if (settings.codec().isEmpty() || settings.codec() == QLatin1String("audio/pcm"))
+ return m_sampleRates;
+
+ return QList<int>();
}
QAudioEncoderSettings AudioEncoderControl::audioSettings() const
{
- return m_settings;
+ return audioFormatToAudioSettings(m_session->format());
}
void AudioEncoderControl::setAudioSettings(const QAudioEncoderSettings &settings)
{
- QAudioFormat fmt = m_session->format();
+ QAudioFormat fmt = audioSettingsToAudioFormat(settings);
if (settings.encodingMode() == QMultimedia::ConstantQualityEncoding) {
- if (settings.quality() == QMultimedia::LowQuality) {
+ fmt.setCodec("audio/pcm");
+ switch (settings.quality()) {
+ case QMultimedia::VeryLowQuality:
fmt.setSampleSize(8);
- fmt.setChannelCount(1);
fmt.setSampleRate(8000);
fmt.setSampleType(QAudioFormat::UnSignedInt);
-
- } else if (settings.quality() == QMultimedia::NormalQuality) {
- fmt.setSampleSize(16);
- fmt.setChannelCount(1);
+ break;
+ case QMultimedia::LowQuality:
+ fmt.setSampleSize(8);
fmt.setSampleRate(22050);
+ fmt.setSampleType(QAudioFormat::UnSignedInt);
+ break;
+ case QMultimedia::HighQuality:
+ fmt.setSampleSize(16);
+ fmt.setSampleRate(48000);
fmt.setSampleType(QAudioFormat::SignedInt);
-
- } else {
+ break;
+ case QMultimedia::VeryHighQuality:
fmt.setSampleSize(16);
- fmt.setChannelCount(1);
- fmt.setSampleRate(44100);
+ fmt.setSampleRate(96000);
fmt.setSampleType(QAudioFormat::SignedInt);
- }
-
- } else {
- fmt.setChannelCount(settings.channelCount());
- fmt.setSampleRate(settings.sampleRate());
- if (settings.sampleRate() == 8000 && settings.bitRate() == 8000) {
- fmt.setSampleType(QAudioFormat::UnSignedInt);
- fmt.setSampleSize(8);
- } else {
+ break;
+ case QMultimedia::NormalQuality:
+ default:
fmt.setSampleSize(16);
+ fmt.setSampleRate(44100);
fmt.setSampleType(QAudioFormat::SignedInt);
+ break;
}
}
- fmt.setCodec("audio/pcm");
m_session->setFormat(fmt);
- m_settings = settings;
}
+
+void AudioEncoderControl::update()
+{
+ m_sampleRates.clear();
+ QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
+ for (int i = 0; i < devices.size(); ++i) {
+ QList<int> rates = devices.at(i).supportedSampleRates();
+ for (int j = 0; j < rates.size(); ++j) {
+ int rate = rates.at(j);
+ if (!m_sampleRates.contains(rate))
+ m_sampleRates.append(rate);
+ }
+ }
+ qSort(m_sampleRates);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audioencodercontrol.h b/src/plugins/audiocapture/audioencodercontrol.h
index c27c9a45e..1508de205 100644
--- a/src/plugins/audiocapture/audioencodercontrol.h
+++ b/src/plugins/audiocapture/audioencodercontrol.h
@@ -49,9 +49,9 @@
#include <qaudioformat.h>
-class AudioCaptureSession;
+QT_BEGIN_NAMESPACE
-QT_USE_NAMESPACE
+class AudioCaptureSession;
class AudioEncoderControl : public QAudioEncoderSettingsControl
{
@@ -68,8 +68,12 @@ public:
void setAudioSettings(const QAudioEncoderSettings&);
private:
+ void update();
+
AudioCaptureSession* m_session;
- QAudioEncoderSettings m_settings;
+ QList<int> m_sampleRates;
};
+QT_END_NAMESPACE
+
#endif
diff --git a/src/plugins/audiocapture/audioinputselector.cpp b/src/plugins/audiocapture/audioinputselector.cpp
index e246b38d5..d88b05d9c 100644
--- a/src/plugins/audiocapture/audioinputselector.cpp
+++ b/src/plugins/audiocapture/audioinputselector.cpp
@@ -44,6 +44,7 @@
#include <qaudiodeviceinfo.h>
+QT_BEGIN_NAMESPACE
AudioInputSelector::AudioInputSelector(QObject *parent)
:QAudioInputSelectorControl(parent)
@@ -79,7 +80,7 @@ QString AudioInputSelector::inputDescription(const QString& name) const
QString AudioInputSelector::defaultInput() const
{
- return QAudioDeviceInfo(QAudioDeviceInfo::defaultInputDevice()).deviceName();
+ return QAudioDeviceInfo::defaultInputDevice().deviceName();
}
QString AudioInputSelector::activeInput() const
@@ -108,3 +109,5 @@ void AudioInputSelector::update()
m_descriptions.append(devices.at(i).deviceName());
}
}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audioinputselector.h b/src/plugins/audiocapture/audioinputselector.h
index 7a1b6419d..d28fefbe4 100644
--- a/src/plugins/audiocapture/audioinputselector.h
+++ b/src/plugins/audiocapture/audioinputselector.h
@@ -46,9 +46,9 @@
#include "qaudioinputselectorcontrol.h"
-class AudioCaptureSession;
+QT_BEGIN_NAMESPACE
-QT_USE_NAMESPACE
+class AudioCaptureSession;
class AudioInputSelector : public QAudioInputSelectorControl
{
@@ -74,4 +74,6 @@ private:
AudioCaptureSession* m_session;
};
+QT_END_NAMESPACE
+
#endif // AUDIOINPUTSELECTOR_H
diff --git a/src/plugins/audiocapture/audiomediarecordercontrol.cpp b/src/plugins/audiocapture/audiomediarecordercontrol.cpp
index c2b590fb3..9bc040246 100644
--- a/src/plugins/audiocapture/audiomediarecordercontrol.cpp
+++ b/src/plugins/audiocapture/audiomediarecordercontrol.cpp
@@ -44,15 +44,22 @@
#include <QtCore/qdebug.h>
+QT_BEGIN_NAMESPACE
+
AudioMediaRecorderControl::AudioMediaRecorderControl(QObject *parent)
- :QMediaRecorderControl(parent)
- , m_state(QMediaRecorder::StoppedState)
- , m_prevStatus(QMediaRecorder::UnloadedStatus)
+ : QMediaRecorderControl(parent)
{
m_session = qobject_cast<AudioCaptureSession*>(parent);
- connect(m_session,SIGNAL(positionChanged(qint64)),this,SIGNAL(durationChanged(qint64)));
- connect(m_session,SIGNAL(stateChanged(QMediaRecorder::State)), this,SLOT(updateStatus()));
- connect(m_session,SIGNAL(error(int,QString)),this,SLOT(handleSessionError(int,QString)));
+ connect(m_session, SIGNAL(positionChanged(qint64)),
+ this, SIGNAL(durationChanged(qint64)));
+ connect(m_session, SIGNAL(stateChanged(QMediaRecorder::State)),
+ this, SIGNAL(stateChanged(QMediaRecorder::State)));
+ connect(m_session, SIGNAL(statusChanged(QMediaRecorder::Status)),
+ this, SIGNAL(statusChanged(QMediaRecorder::Status)));
+ connect(m_session, SIGNAL(actualLocationChanged(QUrl)),
+ this, SIGNAL(actualLocationChanged(QUrl)));
+ connect(m_session, SIGNAL(error(int,QString)),
+ this, SIGNAL(error(int,QString)));
}
AudioMediaRecorderControl::~AudioMediaRecorderControl()
@@ -71,21 +78,12 @@ bool AudioMediaRecorderControl::setOutputLocation(const QUrl& sink)
QMediaRecorder::State AudioMediaRecorderControl::state() const
{
- return (QMediaRecorder::State)m_session->state();
+ return m_session->state();
}
QMediaRecorder::Status AudioMediaRecorderControl::status() const
{
- static QMediaRecorder::Status statusTable[3][3] = {
- //Stopped recorder state:
- { QMediaRecorder::LoadedStatus, QMediaRecorder::FinalizingStatus, QMediaRecorder::FinalizingStatus },
- //Recording recorder state:
- { QMediaRecorder::StartingStatus, QMediaRecorder::RecordingStatus, QMediaRecorder::PausedStatus },
- //Paused recorder state:
- { QMediaRecorder::StartingStatus, QMediaRecorder::RecordingStatus, QMediaRecorder::PausedStatus }
- };
-
- return statusTable[m_state][m_session->state()];
+ return m_session->status();
}
qint64 AudioMediaRecorderControl::duration() const
@@ -106,47 +104,19 @@ qreal AudioMediaRecorderControl::volume() const
void AudioMediaRecorderControl::setState(QMediaRecorder::State state)
{
- if (m_state == state)
- return;
-
- m_state = state;
-
- switch (state) {
- case QMediaRecorder::StoppedState:
- m_session->stop();
- break;
- case QMediaRecorder::PausedState:
- m_session->pause();
- break;
- case QMediaRecorder::RecordingState:
- m_session->record();
- break;
- }
-
- updateStatus();
+ m_session->setState(state);
}
-void AudioMediaRecorderControl::setMuted(bool)
+void AudioMediaRecorderControl::setMuted(bool muted)
{
+ if (muted)
+ qWarning("Muting the audio recording is not supported.");
}
void AudioMediaRecorderControl::setVolume(qreal volume)
{
if (!qFuzzyCompare(volume, qreal(1.0)))
- qWarning() << "Media service doesn't support recorder audio gain.";
-}
-
-void AudioMediaRecorderControl::updateStatus()
-{
- QMediaRecorder::Status newStatus = status();
- if (m_prevStatus != newStatus) {
- m_prevStatus = newStatus;
- emit statusChanged(m_prevStatus);
- }
+ qWarning("Changing the audio recording volume is not supported.");
}
-void AudioMediaRecorderControl::handleSessionError(int code, const QString &description)
-{
- emit error(code, description);
- setState(QMediaRecorder::StoppedState);
-}
+QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audiomediarecordercontrol.h b/src/plugins/audiocapture/audiomediarecordercontrol.h
index 9f029e28e..050d12198 100644
--- a/src/plugins/audiocapture/audiomediarecordercontrol.h
+++ b/src/plugins/audiocapture/audiomediarecordercontrol.h
@@ -47,9 +47,9 @@
#include "qmediarecorder.h"
#include "qmediarecordercontrol.h"
-class AudioCaptureSession;
+QT_BEGIN_NAMESPACE
-QT_USE_NAMESPACE
+class AudioCaptureSession;
class AudioMediaRecorderControl : public QMediaRecorderControl
{
@@ -59,7 +59,7 @@ public:
~AudioMediaRecorderControl();
QUrl outputLocation() const;
- bool setOutputLocation(const QUrl &sink);
+ bool setOutputLocation(const QUrl &location);
QMediaRecorder::State state() const;
QMediaRecorder::Status status() const;
@@ -71,19 +71,14 @@ public:
void applySettings() {}
-public slots:
void setState(QMediaRecorder::State state);
void setMuted(bool);
void setVolume(qreal volume);
-private slots:
- void updateStatus();
- void handleSessionError(int code, const QString &description);
-
private:
AudioCaptureSession* m_session;
- QMediaRecorder::State m_state;
- QMediaRecorder::Status m_prevStatus;
};
+QT_END_NAMESPACE
+
#endif