Replaced QAudioCaptureSource with QAudioRecorder.

QAudioCaptureSource name is confusing, it's essentially an audio
recording service but it's not evident from API.

QAudioRecorder replaces QAudioCaptureSource+QMediaRecorder combination.

Change-Id: I0082d766fc0d1b8d5ecbfc527f13e715add730c8
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
This commit is contained in:
Dmytro Poplavskiy
2012-01-18 14:46:58 +10:00
committed by Qt by Nokia
parent 8c74e5e7e7
commit 69cef0c24c
16 changed files with 462 additions and 449 deletions

View File

@@ -1,264 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** 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 "qmediaobject_p.h"
#include <qaudiocapturesource.h>
#include "qaudioendpointselector.h"
QT_BEGIN_NAMESPACE
/*!
\class QAudioCaptureSource
\brief The QAudioCaptureSource class provides an interface to query and select an audio input endpoint.
\inmodule QtMultimedia
\ingroup multimedia
\ingroup multimedia_recording
QAudioCaptureSource provides access to the audio inputs available on your system.
You can query these inputs and select one to use.
A typical implementation example:
\snippet doc/src/snippets/multimedia-snippets/media.cpp Audio capture source
The audiocapturesource interface is then used to:
- Get and Set the audio input to use.
The capture interface is then used to:
- Set the destination using setOutputLocation()
- Set the format parameters using setAudioCodec(),
- Control the recording using record(),stop()
\sa QMediaRecorder
*/
class QAudioCaptureSourcePrivate : public QMediaObjectPrivate
{
public:
Q_DECLARE_PUBLIC(QAudioCaptureSource)
void initControls()
{
Q_Q(QAudioCaptureSource);
if (service != 0)
audioEndpointSelector = qobject_cast<QAudioEndpointSelector*>(service->requestControl(QAudioEndpointSelector_iid));
if (audioEndpointSelector) {
q->connect(audioEndpointSelector, SIGNAL(activeEndpointChanged(const QString&)),
SIGNAL(activeAudioInputChanged(const QString&)));
q->connect(audioEndpointSelector, SIGNAL(availableEndpointsChanged()),
SIGNAL(availableAudioInputsChanged()));
q->connect(audioEndpointSelector, SIGNAL(availableEndpointsChanged()),
SLOT(statusChanged()));
errorState = QtMultimedia::NoError;
}
}
QAudioCaptureSourcePrivate():provider(0), audioEndpointSelector(0), errorState(QtMultimedia::ServiceMissingError) {}
QMediaServiceProvider *provider;
QAudioEndpointSelector *audioEndpointSelector;
QtMultimedia::AvailabilityError errorState;
};
/*!
Construct a QAudioCaptureSource using the QMediaService from \a provider, with \a parent.
*/
QAudioCaptureSource::QAudioCaptureSource(QObject *parent, QMediaServiceProvider *provider):
QMediaObject(*new QAudioCaptureSourcePrivate, parent, provider->requestService(Q_MEDIASERVICE_AUDIOSOURCE))
{
Q_D(QAudioCaptureSource);
d->provider = provider;
d->initControls();
}
/*!
Destroys the audiocapturesource object.
*/
QAudioCaptureSource::~QAudioCaptureSource()
{
Q_D(QAudioCaptureSource);
if (d->service && d->audioEndpointSelector)
d->service->releaseControl(d->audioEndpointSelector);
if (d->provider)
d->provider->releaseService(d->service);
}
/*!
Returns the error state of the audio capture service.
*/
QtMultimedia::AvailabilityError QAudioCaptureSource::availabilityError() const
{
Q_D(const QAudioCaptureSource);
return d->errorState;
}
/*!
Returns true if the audio capture service is available, otherwise returns false.
*/
bool QAudioCaptureSource::isAvailable() const
{
Q_D(const QAudioCaptureSource);
if (d->service != NULL) {
if (d->audioEndpointSelector && d->audioEndpointSelector->availableEndpoints().size() > 0)
return true;
}
return false;
}
/*!
Returns a list of available audio inputs
*/
QList<QString> QAudioCaptureSource::audioInputs() const
{
Q_D(const QAudioCaptureSource);
QList<QString> list;
if (d && d->audioEndpointSelector)
list <<d->audioEndpointSelector->availableEndpoints();
return list;
}
/*!
Returns the description of the audio input device with \a name.
*/
QString QAudioCaptureSource::audioDescription(const QString& name) const
{
Q_D(const QAudioCaptureSource);
if(d->audioEndpointSelector)
return d->audioEndpointSelector->endpointDescription(name);
else
return QString();
}
/*!
Returns the default audio input name.
*/
QString QAudioCaptureSource::defaultAudioInput() const
{
Q_D(const QAudioCaptureSource);
if(d->audioEndpointSelector)
return d->audioEndpointSelector->defaultEndpoint();
else
return QString();
}
/*!
Returns the active audio input name.
*/
QString QAudioCaptureSource::activeAudioInput() const
{
Q_D(const QAudioCaptureSource);
if(d->audioEndpointSelector)
return d->audioEndpointSelector->activeEndpoint();
else
return QString();
}
/*!
Set the active audio input to \a name.
*/
void QAudioCaptureSource::setAudioInput(const QString& name)
{
Q_D(const QAudioCaptureSource);
if(d->audioEndpointSelector)
return d->audioEndpointSelector->setActiveEndpoint(name);
}
/*!
\fn QAudioCaptureSource::activeAudioInputChanged(const QString& name)
Signal emitted when active audio input changes to \a name.
*/
/*!
\fn QAudioCaptureSource::availableAudioInputsChanged()
Signal is emitted when the available audio inputs change.
*/
/*!
\internal
*/
void QAudioCaptureSource::statusChanged()
{
Q_D(QAudioCaptureSource);
if (d->audioEndpointSelector) {
if (d->audioEndpointSelector->availableEndpoints().size() > 0) {
d->errorState = QtMultimedia::NoError;
emit availabilityChanged(true);
} else {
d->errorState = QtMultimedia::BusyError;
emit availabilityChanged(false);
}
} else {
d->errorState = QtMultimedia::ServiceMissingError;
emit availabilityChanged(false);
}
}
#include "moc_qaudiocapturesource.cpp"
QT_END_NAMESPACE

View File

@@ -0,0 +1,231 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** 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 "qaudiorecorder.h"
#include "qaudioendpointselector.h"
#include "qmediaobject_p.h"
#include "qmediarecorder_p.h"
#include <qmediaservice.h>
#include <qmediaserviceprovider.h>
#include <QtCore/qdebug.h>
#include <QtCore/qurl.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qmetaobject.h>
#include <qaudioformat.h>
QT_BEGIN_NAMESPACE
/*!
\class QAudioRecorder
\inmodule QtMultimedia
\ingroup multimedia
\ingroup multimedia_recording
\brief The QAudioRecorder class is used for the recording of media content.
The QAudioRecorder class is a high level media recording class.
*/
class QAudioRecorderObject : public QMediaObject
{
public:
QAudioRecorderObject(QObject *parent, QMediaService *service)
:QMediaObject(parent, service)
{
}
~QAudioRecorderObject()
{
}
};
class QAudioRecorderPrivate : public QMediaRecorderPrivate
{
Q_DECLARE_NON_CONST_PUBLIC(QAudioRecorder)
public:
void initControls()
{
Q_Q(QAudioRecorder);
audioEndpointSelector = 0;
QMediaService *service = mediaObject ? mediaObject->service() : 0;
if (service != 0)
audioEndpointSelector = qobject_cast<QAudioEndpointSelector*>(service->requestControl(QAudioEndpointSelector_iid));
if (audioEndpointSelector) {
q->connect(audioEndpointSelector, SIGNAL(activeEndpointChanged(QString)),
SIGNAL(audioInputChanged(QString)));
q->connect(audioEndpointSelector, SIGNAL(availableEndpointsChanged()),
SIGNAL(availableAudioInputsChanged()));
}
}
QAudioRecorderPrivate():
QMediaRecorderPrivate(),
provider(0),
audioEndpointSelector(0) {}
QMediaServiceProvider *provider;
QAudioEndpointSelector *audioEndpointSelector;
};
/*!
Constructs an audio recorder.
The \a parent is passed to QMediaObject.
*/
QAudioRecorder::QAudioRecorder(QObject *parent, QMediaServiceProvider *serviceProvider):
QMediaRecorder(*new QAudioRecorderPrivate, 0, parent)
{
Q_D(QAudioRecorder);
d->provider = serviceProvider;
QMediaService *service = d->provider->requestService(Q_MEDIASERVICE_AUDIOSOURCE);
setMediaObject(new QAudioRecorderObject(this, service));
d->initControls();
}
/*!
Destroys an audio recorder object.
*/
QAudioRecorder::~QAudioRecorder()
{
Q_D(QAudioRecorder);
QMediaService *service = d->mediaObject ? d->mediaObject->service() : 0;
QMediaObject *mediaObject = d->mediaObject;
setMediaObject(0);
if (service && d->audioEndpointSelector)
service->releaseControl(d->audioEndpointSelector);
if (d->provider && service)
d->provider->releaseService(service);
delete mediaObject;
}
/*!
Returns a list of available audio inputs
*/
QStringList QAudioRecorder::audioInputs() const
{
return d_func()->audioEndpointSelector->availableEndpoints();
}
/*!
Returns the readable translated description of the audio input device with \a name.
*/
QString QAudioRecorder::audioInputDescription(const QString& name) const
{
Q_D(const QAudioRecorder);
if (d->audioEndpointSelector)
return d->audioEndpointSelector->endpointDescription(name);
else
return QString();
}
/*!
Returns the default audio input name.
*/
QString QAudioRecorder::defaultAudioInput() const
{
Q_D(const QAudioRecorder);
if (d->audioEndpointSelector)
return d->audioEndpointSelector->defaultEndpoint();
else
return QString();
}
/*!
Returns the active audio input name.
*/
QString QAudioRecorder::audioInput() const
{
Q_D(const QAudioRecorder);
if (d->audioEndpointSelector)
return d->audioEndpointSelector->activeEndpoint();
else
return QString();
}
/*!
Set the active audio input to \a name.
*/
void QAudioRecorder::setAudioInput(const QString& name)
{
Q_D(const QAudioRecorder);
if (d->audioEndpointSelector)
return d->audioEndpointSelector->setActiveEndpoint(name);
}
/*!
\fn QAudioRecorder::activeAudioInputChanged(const QString& name)
Signal emitted when active audio input changes to \a name.
*/
/*!
\fn QAudioRecorder::availableAudioInputsChanged()
Signal is emitted when the available audio inputs change.
*/
#include "moc_qaudiorecorder.cpp"
QT_END_NAMESPACE

View File

@@ -39,21 +39,15 @@
**
****************************************************************************/
#ifndef QAUDIOCAPTURESOURCE_H
#define QAUDIOCAPTURESOURCE_H
#ifndef QAUDIORECORDER_H
#define QAUDIORECORDER_H
#include <qmediarecorder.h>
#include <qmediaobject.h>
#include <qmediaencodersettings.h>
#include <qmediaenumdebug.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qpair.h>
#include <QtCore/qsize.h>
#include <qaudioformat.h>
#include "qmediarecorder.h"
#include "qmediacontrol.h"
#include "qmediaobject.h"
#include "qmediaservice.h"
#include "qmediaserviceprovider.h"
QT_BEGIN_HEADER
@@ -61,43 +55,42 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Multimedia)
class QString;
class QSize;
class QAudioFormat;
QT_END_NAMESPACE
class QAudioCaptureSourcePrivate;
QT_BEGIN_NAMESPACE
class Q_MULTIMEDIA_EXPORT QAudioCaptureSource : public QMediaObject
class QAudioRecorderPrivate;
class Q_MULTIMEDIA_EXPORT QAudioRecorder : public QMediaRecorder
{
Q_OBJECT
Q_PROPERTY(QString audioInput READ audioInput WRITE setAudioInput NOTIFY audioInputChanged)
public:
QAudioCaptureSource(QObject *parent = 0, QMediaServiceProvider *service = QMediaServiceProvider::defaultServiceProvider());
~QAudioCaptureSource();
QAudioRecorder(QObject *parent = 0, QMediaServiceProvider *serviceProvider = QMediaServiceProvider::defaultServiceProvider());
~QAudioRecorder();
bool isAvailable() const;
QtMultimedia::AvailabilityError availabilityError() const;
QList<QString> audioInputs() const;
QString audioDescription(const QString& name) const;
QStringList audioInputs() const;
QString defaultAudioInput() const;
QString activeAudioInput() const;
QString audioInputDescription(const QString& name) const;
QString audioInput() const;
public Q_SLOTS:
void setAudioInput(const QString& name);
Q_SIGNALS:
void activeAudioInputChanged(const QString& name);
void audioInputChanged(const QString& name);
void availableAudioInputsChanged();
private Q_SLOTS:
void statusChanged();
private:
Q_DECLARE_PRIVATE(QAudioCaptureSource)
Q_DISABLE_COPY(QAudioRecorder)
Q_DECLARE_PRIVATE(QAudioRecorder)
};
QT_END_NAMESPACE
QT_END_HEADER
#endif // QAUDIOCAPTURESOURCE_H
#endif // QAUDIORECORDER_H

View File

@@ -40,6 +40,7 @@
****************************************************************************/
#include "qmediarecorder.h"
#include "qmediarecorder_p.h"
#include <qmediarecordercontrol.h>
#include "qmediaobject_p.h"
@@ -71,11 +72,11 @@ QT_BEGIN_NAMESPACE
The QMediaRecorder class is a high level media recording class. It's not
intended to be used alone but for accessing the media recording functions
of other media objects, like QRadioTuner, or QAudioCaptureSource.
of other media objects, like QRadioTuner, or QCamera.
\snippet doc/src/snippets/multimedia-snippets/media.cpp Media recorder
\sa QAudioCaptureSource
\sa QAudioRecorder
*/
namespace
@@ -91,37 +92,6 @@ public:
} _registerRecorderMetaTypes;
}
class QMediaRecorderPrivate
{
Q_DECLARE_NON_CONST_PUBLIC(QMediaRecorder)
public:
QMediaRecorderPrivate();
QMediaObject *mediaObject;
QMediaRecorderControl *control;
QMediaContainerControl *formatControl;
QAudioEncoderControl *audioControl;
QVideoEncoderControl *videoControl;
QMetaDataWriterControl *metaDataControl;
QTimer* notifyTimer;
QMediaRecorder::State state;
QMediaRecorder::Error error;
QString errorString;
void _q_stateChanged(QMediaRecorder::State state);
void _q_error(int error, const QString &errorString);
void _q_serviceDestroyed();
void _q_notify();
void _q_updateNotifyInterval(int ms);
QMediaRecorder *q_ptr;
};
QMediaRecorderPrivate::QMediaRecorderPrivate():
mediaObject(0),
control(0),
@@ -198,12 +168,27 @@ QMediaRecorder::QMediaRecorder(QMediaObject *mediaObject, QObject *parent):
{
Q_D(QMediaRecorder);
d->q_ptr = this;
setMediaObject(mediaObject);
d->notifyTimer = new QTimer(this);
d->notifyTimer->setInterval(mediaObject->notifyInterval());
connect(d->notifyTimer, SIGNAL(timeout()), SLOT(_q_notify()));
connect(mediaObject, SIGNAL(notifyIntervalChanged(int)), SLOT(_q_updateNotifyInterval(int)));
setMediaObject(mediaObject);
}
/*!
\internal
*/
QMediaRecorder::QMediaRecorder(QMediaRecorderPrivate &dd, QMediaObject *mediaObject, QObject *parent):
QObject(parent),
d_ptr(&dd)
{
Q_D(QMediaRecorder);
d->q_ptr = this;
d->notifyTimer = new QTimer(this);
connect(d->notifyTimer, SIGNAL(timeout()), SLOT(_q_notify()));
setMediaObject(mediaObject);
}
/*!
@@ -248,6 +233,8 @@ bool QMediaRecorder::setMediaObject(QMediaObject *object)
this, SLOT(_q_error(int,QString)));
}
disconnect(d->mediaObject, SIGNAL(notifyIntervalChanged(int)), this, SLOT(_q_updateNotifyInterval(int)));
QMediaService *service = d->mediaObject->service();
if (service) {
@@ -285,6 +272,9 @@ bool QMediaRecorder::setMediaObject(QMediaObject *object)
if (d->mediaObject) {
QMediaService *service = d->mediaObject->service();
d->notifyTimer->setInterval(d->mediaObject->notifyInterval());
connect(d->mediaObject, SIGNAL(notifyIntervalChanged(int)), SLOT(_q_updateNotifyInterval(int)));
if (service) {
d->control = qobject_cast<QMediaRecorderControl*>(service->requestControl(QMediaRecorderControl_iid));

View File

@@ -171,10 +171,11 @@ Q_SIGNALS:
void metaDataChanged();
protected:
QMediaRecorder(QMediaRecorderPrivate &dd, QMediaObject *mediaObject, QObject *parent = 0);
bool setMediaObject(QMediaObject *object);
private:
QMediaRecorderPrivate *d_ptr;
private:
Q_DISABLE_COPY(QMediaRecorder)
Q_DECLARE_PRIVATE(QMediaRecorder)
Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QMediaRecorder::State))

View File

@@ -0,0 +1,91 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** 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 QMEDIARECORDER_P_H
#define QMEDIARECORDER_P_H
#include "qmediarecorder.h"
#include "qmediaobject_p.h"
QT_BEGIN_NAMESPACE
class QMediaRecorderControl;
class QMediaContainerControl;
class QAudioEncoderControl;
class QVideoEncoderControl;
class QMetaDataWriterControl;
class QTimer;
class QMediaRecorderPrivate
{
Q_DECLARE_NON_CONST_PUBLIC(QMediaRecorder)
public:
QMediaRecorderPrivate();
virtual ~QMediaRecorderPrivate() {}
QMediaObject *mediaObject;
QMediaRecorderControl *control;
QMediaContainerControl *formatControl;
QAudioEncoderControl *audioControl;
QVideoEncoderControl *videoControl;
QMetaDataWriterControl *metaDataControl;
QTimer* notifyTimer;
QMediaRecorder::State state;
QMediaRecorder::Error error;
QString errorString;
void _q_stateChanged(QMediaRecorder::State state);
void _q_error(int error, const QString &errorString);
void _q_serviceDestroyed();
void _q_notify();
void _q_updateNotifyInterval(int ms);
QMediaRecorder *q_ptr;
};
QT_END_NAMESPACE
#endif

View File

@@ -1,11 +1,14 @@
INCLUDEPATH += recording
PUBLIC_HEADERS += \
recording/qaudiocapturesource.h \
recording/qaudiorecorder.h \
recording/qmediaencodersettings.h \
recording/qmediarecorder.h \
PRIVATE_HEADERS += \
recording/qmediarecorder_p.h \
SOURCES += \
recording/qaudiocapturesource.cpp \
recording/qaudiorecorder.cpp \
recording/qmediaencodersettings.cpp \
recording/qmediarecorder.cpp