Initial copy of QtMultimediaKit.

Comes from original repo, with SHA1:
2c82d5611655e5967f5c5095af50c0991c4378b2
This commit is contained in:
Michael Goddard
2011-06-29 13:38:46 +10:00
commit 2a34e88c1e
1048 changed files with 206259 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
INCLUDEPATH += $$PWD \
$${SOURCE_DIR}/src/multimedia
INCLUDEPATH += camerabin
DEFINES += QMEDIA_GSTREAMER_CAMERABIN
LIBS += -lgstphotography-0.10
DEFINES += GST_USE_UNSTABLE_API #prevents warnings because of unstable photography API
HEADERS += \
$$PWD/camerabinservice.h \
$$PWD/camerabinsession.h \
$$PWD/camerabincontrol.h \
$$PWD/camerabinaudioencoder.h \
$$PWD/camerabinfocus.h \
$$PWD/camerabinimageencoder.h \
$$PWD/camerabinlocks.h \
$$PWD/camerabinrecorder.h \
$$PWD/camerabincontainer.h \
$$PWD/camerabinexposure.h \
$$PWD/camerabinflash.h \
$$PWD/camerabinimagecapture.h \
$$PWD/camerabinimageprocessing.h \
$$PWD/camerabinmetadata.h \
$$PWD/camerabinvideoencoder.h \
$$PWD/camerabinresourcepolicy.h \
$$PWD/camerabincapturedestination.h \
$$PWD/camerabincapturebufferformat.h
SOURCES += \
$$PWD/camerabinservice.cpp \
$$PWD/camerabinsession.cpp \
$$PWD/camerabincontrol.cpp \
$$PWD/camerabinaudioencoder.cpp \
$$PWD/camerabincontainer.cpp \
$$PWD/camerabinexposure.cpp \
$$PWD/camerabinflash.cpp \
$$PWD/camerabinfocus.cpp \
$$PWD/camerabinimagecapture.cpp \
$$PWD/camerabinimageencoder.cpp \
$$PWD/camerabinimageprocessing.cpp \
$$PWD/camerabinlocks.cpp \
$$PWD/camerabinmetadata.cpp \
$$PWD/camerabinrecorder.cpp \
$$PWD/camerabinvideoencoder.cpp \
$$PWD/camerabinresourcepolicy.cpp \
$$PWD/camerabincapturedestination.cpp \
$$PWD/camerabincapturebufferformat.cpp

View File

@@ -0,0 +1,293 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabinaudioencoder.h"
#include "camerabincontainer.h"
#include <QtCore/qdebug.h>
CameraBinAudioEncoder::CameraBinAudioEncoder(QObject *parent)
:QAudioEncoderControl(parent)
{
QList<QByteArray> codecCandidates;
#if defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
codecCandidates << "audio/AAC" << "audio/PCM" << "audio/AMR" << "audio/AMR-WB" << "audio/speex"
<< "audio/ADPCM" << "audio/iLBC" << "audio/vorbis" << "audio/mpeg" << "audio/FLAC";
m_elementNames["audio/AAC"] = "nokiaaacenc";
m_elementNames["audio/speex"] = "speexenc";
m_elementNames["audio/PCM"] = "audioresample";
m_elementNames["audio/AMR"] = "nokiaamrnbenc";
m_elementNames["audio/AMR-WB"] = "nokiaamrwbenc";
m_elementNames["audio/ADPCM"] = "nokiaadpcmenc";
m_elementNames["audio/iLBC"] = "nokiailbcenc";
m_elementNames["audio/vorbis"] = "vorbisenc";
m_elementNames["audio/FLAC"] = "flacenc";
m_elementNames["audio/mpeg"] = "ffenc_mp2";
#else
codecCandidates << "audio/mpeg" << "audio/vorbis" << "audio/speex" << "audio/GSM"
<< "audio/PCM" << "audio/AMR" << "audio/AMR-WB";
m_elementNames["audio/mpeg"] = "lamemp3enc";
m_elementNames["audio/vorbis"] = "vorbisenc";
m_elementNames["audio/speex"] = "speexenc";
m_elementNames["audio/GSM"] = "gsmenc";
m_elementNames["audio/PCM"] = "audioresample";
m_elementNames["audio/AMR"] = "amrnbenc";
m_elementNames["audio/AMR-WB"] = "amrwbenc";
m_codecOptions["audio/vorbis"] = QStringList() << "min-bitrate" << "max-bitrate";
m_codecOptions["audio/mpeg"] = QStringList() << "mode";
m_codecOptions["audio/speex"] = QStringList() << "mode" << "vbr" << "vad" << "dtx";
m_codecOptions["audio/GSM"] = QStringList();
m_codecOptions["audio/PCM"] = QStringList();
m_codecOptions["audio/AMR"] = QStringList();
m_codecOptions["audio/AMR-WB"] = QStringList();
#endif
foreach( const QByteArray& codecName, codecCandidates ) {
QByteArray elementName = m_elementNames[codecName];
GstElementFactory *factory = gst_element_factory_find(elementName.constData());
if (factory) {
m_codecs.append(codecName);
const gchar *descr = gst_element_factory_get_description(factory);
if (codecName == QByteArray("audio/PCM"))
m_codecDescriptions.insert(codecName, tr("Raw PCM audio"));
else
m_codecDescriptions.insert(codecName, QString::fromUtf8(descr));
m_streamTypes.insert(codecName,
CameraBinContainer::supportedStreamTypes(factory, GST_PAD_SRC));
gst_object_unref(GST_OBJECT(factory));
}
}
}
CameraBinAudioEncoder::~CameraBinAudioEncoder()
{
}
QStringList CameraBinAudioEncoder::supportedAudioCodecs() const
{
return m_codecs;
}
QString CameraBinAudioEncoder::codecDescription(const QString &codecName) const
{
return m_codecDescriptions.value(codecName);
}
QStringList CameraBinAudioEncoder::supportedEncodingOptions(const QString &codec) const
{
return m_codecOptions.value(codec);
}
QVariant CameraBinAudioEncoder::encodingOption(
const QString &codec, const QString &name) const
{
return m_options[codec].value(name);
}
void CameraBinAudioEncoder::setEncodingOption(
const QString &codec, const QString &name, const QVariant &value)
{
m_options[codec][name] = value;
}
QList<int> CameraBinAudioEncoder::supportedSampleRates(const QAudioEncoderSettings &, bool *) const
{
//TODO check element caps to find actual values
return QList<int>();
}
QAudioEncoderSettings CameraBinAudioEncoder::audioSettings() const
{
return m_audioSettings;
}
void CameraBinAudioEncoder::setAudioSettings(const QAudioEncoderSettings &settings)
{
m_userSettings = settings;
m_audioSettings = settings;
emit settingsChanged();
}
void CameraBinAudioEncoder::setActualAudioSettings(const QAudioEncoderSettings &settings)
{
m_audioSettings = settings;
}
void CameraBinAudioEncoder::resetActualSettings()
{
m_audioSettings = m_userSettings;
}
GstElement *CameraBinAudioEncoder::createEncoder()
{
QString codec = m_audioSettings.codec();
QByteArray encoderElementName = m_elementNames.value(codec);
GstElement *encoderElement = gst_element_factory_make(encoderElementName.constData(), NULL);
if (!encoderElement)
return 0;
GstBin * encoderBin = GST_BIN(gst_bin_new("audio-encoder-bin"));
GstElement *capsFilter = gst_element_factory_make("capsfilter", NULL);
gst_bin_add(encoderBin, capsFilter);
gst_bin_add(encoderBin, encoderElement);
gst_element_link(capsFilter, encoderElement);
// add ghostpads
GstPad *pad = gst_element_get_static_pad(capsFilter, "sink");
gst_element_add_pad(GST_ELEMENT(encoderBin), gst_ghost_pad_new("sink", pad));
gst_object_unref(GST_OBJECT(pad));
pad = gst_element_get_static_pad(encoderElement, "src");
gst_element_add_pad(GST_ELEMENT(encoderBin), gst_ghost_pad_new("src", pad));
gst_object_unref(GST_OBJECT(pad));
if (m_audioSettings.sampleRate() > 0 || m_audioSettings.channelCount() > 0) {
GstCaps *caps = gst_caps_new_empty();
GstStructure *structure = gst_structure_new("audio/x-raw-int", NULL);
if (m_audioSettings.sampleRate() > 0)
gst_structure_set(structure, "rate", G_TYPE_INT, m_audioSettings.sampleRate(), NULL );
if (m_audioSettings.channelCount() > 0)
gst_structure_set(structure, "channels", G_TYPE_INT, m_audioSettings.channelCount(), NULL );
gst_caps_append_structure(caps,structure);
g_object_set(G_OBJECT(capsFilter), "caps", caps, NULL);
}
if (encoderElement) {
if (m_audioSettings.encodingMode() == QtMultimediaKit::ConstantQualityEncoding) {
QtMultimediaKit::EncodingQuality qualityValue = m_audioSettings.quality();
if (encoderElementName == "lamemp3enc") {
g_object_set(G_OBJECT(encoderElement), "target", 0, NULL); //constant quality mode
qreal quality[] = {
10.0, //VeryLow
6.0, //Low
4.0, //Normal
2.0, //High
0.0 //VeryHigh
};
g_object_set(G_OBJECT(encoderElement), "quality", quality[qualityValue], NULL);
} else if (encoderElementName == "ffenc_mp2") {
int quality[] = {
8000, //VeryLow
64000, //Low
128000, //Normal
192000, //High
320000 //VeryHigh
};
g_object_set(G_OBJECT(encoderElement), "bitrate", quality[qualityValue], NULL);
} else if (codec == QLatin1String("audio/speex")) {
//0-10 range with default 8
double qualityTable[] = {
2, //VeryLow
5, //Low
8, //Normal
9, //High
10 //VeryHigh
};
g_object_set(G_OBJECT(encoderElement), "quality", qualityTable[qualityValue], NULL);
} else if (codec.startsWith("audio/AMR")) {
int band[] = {
0, //VeryLow
2, //Low
4, //Normal
6, //High
7 //VeryHigh
};
g_object_set(G_OBJECT(encoderElement), "band-mode", band[qualityValue], NULL);
}
} else {
int bitrate = m_audioSettings.bitRate();
if (bitrate > 0) {
g_object_set(G_OBJECT(encoderElement), "bitrate", bitrate, NULL);
}
}
QMap<QString, QVariant> options = m_options.value(codec);
QMapIterator<QString,QVariant> it(options);
while (it.hasNext()) {
it.next();
QString option = it.key();
QVariant value = it.value();
switch (value.type()) {
case QVariant::Int:
g_object_set(G_OBJECT(encoderElement), option.toAscii(), value.toInt(), NULL);
break;
case QVariant::Bool:
g_object_set(G_OBJECT(encoderElement), option.toAscii(), value.toBool(), NULL);
break;
case QVariant::Double:
g_object_set(G_OBJECT(encoderElement), option.toAscii(), value.toDouble(), NULL);
break;
case QVariant::String:
g_object_set(G_OBJECT(encoderElement), option.toAscii(), value.toString().toUtf8().constData(), NULL);
break;
default:
qWarning() << "unsupported option type:" << option << value;
break;
}
}
}
return GST_ELEMENT(encoderBin);
}
QSet<QString> CameraBinAudioEncoder::supportedStreamTypes(const QString &codecName) const
{
return m_streamTypes.value(codecName);
}

View File

@@ -0,0 +1,105 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINAUDIOENCODE_H
#define CAMERABINAUDIOENCODE_H
#include <qaudioencodercontrol.h>
class CameraBinSession;
#include <QtCore/qstringlist.h>
#include <QtCore/qmap.h>
#include <QtCore/qset.h>
#include <gst/gst.h>
#include <qaudioformat.h>
QT_USE_NAMESPACE
class CameraBinAudioEncoder : public QAudioEncoderControl
{
Q_OBJECT
public:
CameraBinAudioEncoder(QObject *parent);
virtual ~CameraBinAudioEncoder();
QStringList supportedAudioCodecs() const;
QString codecDescription(const QString &codecName) const;
QStringList supportedEncodingOptions(const QString &codec) const;
QVariant encodingOption(const QString &codec, const QString &name) const;
void setEncodingOption(const QString &codec, const QString &name, const QVariant &value);
QList<int> supportedSampleRates(const QAudioEncoderSettings &settings = QAudioEncoderSettings(),
bool *isContinuous = 0) const;
QList<int> supportedChannelCounts(const QAudioEncoderSettings &settings = QAudioEncoderSettings()) const;
QList<int> supportedSampleSizes(const QAudioEncoderSettings &settings = QAudioEncoderSettings()) const;
QAudioEncoderSettings audioSettings() const;
void setAudioSettings(const QAudioEncoderSettings&);
GstElement *createEncoder();
QSet<QString> supportedStreamTypes(const QString &codecName) const;
void setActualAudioSettings(const QAudioEncoderSettings&);
void resetActualSettings();
Q_SIGNALS:
void settingsChanged();
private:
QStringList m_codecs;
QMap<QString,QByteArray> m_elementNames;
QMap<QString,QString> m_codecDescriptions;
QMap<QString,QStringList> m_codecOptions;
QMap<QString, QMap<QString, QVariant> > m_options;
QMap<QString, QSet<QString> > m_streamTypes;
QAudioEncoderSettings m_audioSettings;
QAudioEncoderSettings m_userSettings;
};
#endif

View File

@@ -0,0 +1,78 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabincapturebufferformat.h"
#include "camerabinsession.h"
CameraBinCaptureBufferFormat::CameraBinCaptureBufferFormat(CameraBinSession *session)
:QCameraCaptureBufferFormatControl(session)
, m_session(session)
, m_format(QVideoFrame::Format_Jpeg)
{
}
CameraBinCaptureBufferFormat::~CameraBinCaptureBufferFormat()
{
}
QList<QVideoFrame::PixelFormat> CameraBinCaptureBufferFormat::supportedBufferFormats() const
{
//the exact YUV format is unknown with camerabin until the first capture is requested
return QList<QVideoFrame::PixelFormat>()
<< QVideoFrame::Format_Jpeg
#ifdef Q_WS_MAEMO_6
<< QVideoFrame::Format_UYVY
#endif
;
}
QVideoFrame::PixelFormat CameraBinCaptureBufferFormat::bufferFormat() const
{
return m_format;
}
void CameraBinCaptureBufferFormat::setBufferFormat(QVideoFrame::PixelFormat format)
{
if (m_format != format) {
m_format = format;
emit bufferFormatChanged(format);
}
}

View File

@@ -0,0 +1,72 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINCAPTUREBUFFERFORMAT_H
#define CAMERABINCAPTUREBUFFERFORMAT_H
#include <qcamera.h>
#include <qcameracapturebufferformatcontrol.h>
#include <gst/gst.h>
#include <glib.h>
class CameraBinSession;
QT_USE_NAMESPACE
class Q_MULTIMEDIA_EXPORT CameraBinCaptureBufferFormat : public QCameraCaptureBufferFormatControl
{
Q_OBJECT
public:
CameraBinCaptureBufferFormat(CameraBinSession *session);
virtual ~CameraBinCaptureBufferFormat();
QList<QVideoFrame::PixelFormat> supportedBufferFormats() const;
QVideoFrame::PixelFormat bufferFormat() const;
void setBufferFormat(QVideoFrame::PixelFormat format);
private:
CameraBinSession *m_session;
QVideoFrame::PixelFormat m_format;
};
#endif

View File

@@ -0,0 +1,74 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabincapturedestination.h"
#include "camerabinsession.h"
CameraBinCaptureDestination::CameraBinCaptureDestination(CameraBinSession *session)
:QCameraCaptureDestinationControl(session)
, m_session(session)
, m_destination(QCameraImageCapture::CaptureToFile)
{
}
CameraBinCaptureDestination::~CameraBinCaptureDestination()
{
}
bool CameraBinCaptureDestination::isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const
{
//capture to buffer, file and both are supported.
return destination & (QCameraImageCapture::CaptureToFile | QCameraImageCapture::CaptureToBuffer);
}
QCameraImageCapture::CaptureDestinations CameraBinCaptureDestination::captureDestination() const
{
return m_destination;
}
void CameraBinCaptureDestination::setCaptureDestination(QCameraImageCapture::CaptureDestinations destination)
{
if (m_destination != destination) {
m_destination = destination;
emit captureDestinationChanged(m_destination);
}
}

View File

@@ -0,0 +1,69 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINCAPTUREDESTINATION_H
#define CAMERABINCAPTUREDESTINATION_H
#include <qcameraimagecapture.h>
#include <qcameracapturedestinationcontrol.h>
class CameraBinSession;
QT_USE_NAMESPACE
class Q_MULTIMEDIA_EXPORT CameraBinCaptureDestination : public QCameraCaptureDestinationControl
{
Q_OBJECT
public:
CameraBinCaptureDestination(CameraBinSession *session);
virtual ~CameraBinCaptureDestination();
bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const;
QCameraImageCapture::CaptureDestinations captureDestination() const;
void setCaptureDestination(QCameraImageCapture::CaptureDestinations destination);
private:
CameraBinSession *m_session;
QCameraImageCapture::CaptureDestinations m_destination;
};
#endif // CAMERABINFLASHCONTROL_H

View File

@@ -0,0 +1,122 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabincontainer.h"
#include <QtCore/qdebug.h>
CameraBinContainer::CameraBinContainer(QObject *parent)
:QMediaContainerControl(parent)
{
QList<QByteArray> formatCandidates;
formatCandidates << "mp4" << "ogg" << "wav" << "amr" << "mkv"
<< "avi" << "3gp" << "3gp2" << "webm" << "mjpeg" << "asf" << "mov";
QMap<QString,QByteArray> elementNames;
elementNames.insertMulti("mp4", "ffmux_mp4");
elementNames.insertMulti("mp4", "hantromp4mux");
elementNames.insertMulti("mp4", "mp4mux");
elementNames.insert("ogg", "oggmux");
elementNames["wav"] = "wavenc";
elementNames["amr"] = "ffmux_amr";
elementNames["mkv"] = "matroskamux";
elementNames["avi"] = "avimux";
elementNames["3gp"] = "ffmux_3gp";
elementNames["3gp2"] = "ffmux_3g2";
elementNames["webm"] = "webmmux";
elementNames["mjpeg"] = "ffmux_mjpeg";
elementNames["asf"] = "ffmux_asf";
elementNames["mov"] = "qtmux";
QSet<QString> allTypes;
foreach(const QByteArray &formatName, formatCandidates) {
foreach(const QByteArray &elementName, elementNames.values(formatName)) {
GstElementFactory *factory = gst_element_factory_find(elementName.constData());
if (factory) {
m_supportedContainers.append(formatName);
const gchar *descr = gst_element_factory_get_description(factory);
m_containerDescriptions.insert(formatName, QString::fromUtf8(descr));
if (formatName == QByteArray("raw")) {
m_streamTypes.insert(formatName, allTypes);
} else {
QSet<QString> types = supportedStreamTypes(factory, GST_PAD_SINK);
m_streamTypes.insert(formatName, types);
allTypes.unite(types);
}
gst_object_unref(GST_OBJECT(factory));
m_elementNames.insert(formatName, elementName);
break;
}
}
}
}
QSet<QString> CameraBinContainer::supportedStreamTypes(GstElementFactory *factory, GstPadDirection direction)
{
QSet<QString> types;
const GList *pads = gst_element_factory_get_static_pad_templates(factory);
for (const GList *pad = pads; pad; pad = g_list_next(pad)) {
GstStaticPadTemplate *templ = (GstStaticPadTemplate*)pad->data;
if (templ->direction == direction) {
GstCaps *caps = gst_static_caps_get(&templ->static_caps);
for (uint i=0; i<gst_caps_get_size(caps); i++) {
GstStructure *structure = gst_caps_get_structure(caps, i);
types.insert( QString::fromUtf8(gst_structure_get_name(structure)) );
}
gst_caps_unref(caps);
}
}
return types;
}
QSet<QString> CameraBinContainer::supportedStreamTypes(const QString &container) const
{
return m_streamTypes.value(container);
}

View File

@@ -0,0 +1,103 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINMEDIACONTAINERCONTROL_H
#define CAMERABINMEDIACONTAINERCONTROL_H
#include <qmediacontainercontrol.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qset.h>
#include <gst/gst.h>
QT_USE_NAMESPACE
class CameraBinContainer : public QMediaContainerControl
{
Q_OBJECT
public:
CameraBinContainer(QObject *parent);
virtual ~CameraBinContainer() {}
virtual QStringList supportedContainers() const { return m_supportedContainers; }
virtual QString containerMimeType() const { return m_format; }
virtual void setContainerMimeType(const QString &formatMimeType)
{
m_format = formatMimeType;
if (m_userFormat != formatMimeType) {
m_userFormat = formatMimeType;
emit settingsChanged();
}
}
void setActualContainer(const QString &formatMimeType)
{
m_format = formatMimeType;
}
void resetActualContainer()
{
m_format = m_userFormat;
}
virtual QString containerDescription(const QString &formatMimeType) const { return m_containerDescriptions.value(formatMimeType); }
QByteArray formatElementName() const { return m_elementNames.value(containerMimeType()); }
QSet<QString> supportedStreamTypes(const QString &container) const;
static QSet<QString> supportedStreamTypes(GstElementFactory *factory, GstPadDirection direction);
Q_SIGNALS:
void settingsChanged();
private:
QString m_format; // backend selected format, using m_userFormat
QString m_userFormat;
QStringList m_supportedContainers;
QMap<QString,QByteArray> m_elementNames;
QMap<QString, QString> m_containerDescriptions;
QMap<QString, QSet<QString> > m_streamTypes;
};
#endif // CAMERABINMEDIACONTAINERCONTROL_H

View File

@@ -0,0 +1,356 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabincontrol.h"
#include "camerabincontainer.h"
#include "camerabinaudioencoder.h"
#include "camerabinvideoencoder.h"
#include "camerabinimageencoder.h"
#include "camerabinresourcepolicy.h"
#include <QtCore/qdebug.h>
#include <QtCore/qfile.h>
#include <QtCore/qmetaobject.h>
#include <linux/types.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <linux/videodev2.h>
//#define CAMEABIN_DEBUG 1
#define ENUM_NAME(c,e,v) (c::staticMetaObject.enumerator(c::staticMetaObject.indexOfEnumerator(e)).valueToKey((v)))
CameraBinControl::CameraBinControl(CameraBinSession *session)
:QCameraControl(session),
m_session(session),
m_state(QCamera::UnloadedState),
m_status(QCamera::UnloadedStatus),
m_reloadPending(false)
{
connect(m_session, SIGNAL(stateChanged(QCamera::State)),
this, SLOT(updateStatus()));
connect(m_session->audioEncodeControl(), SIGNAL(settingsChanged()),
SLOT(reloadLater()));
connect(m_session->videoEncodeControl(), SIGNAL(settingsChanged()),
SLOT(reloadLater()));
connect(m_session->mediaContainerControl(), SIGNAL(settingsChanged()),
SLOT(reloadLater()));
connect(m_session->imageEncodeControl(), SIGNAL(settingsChanged()),
SLOT(reloadLater()));
connect(m_session, SIGNAL(viewfinderChanged()),
SLOT(reloadLater()));
connect(m_session, SIGNAL(readyChanged(bool)),
SLOT(reloadLater()));
connect(m_session, SIGNAL(error(int,QString)),
SLOT(handleCameraError(int,QString)));
m_resourcePolicy = new CamerabinResourcePolicy(this);
connect(m_resourcePolicy, SIGNAL(resourcesGranted()),
SLOT(handleResourcesGranted()));
connect(m_resourcePolicy, SIGNAL(resourcesDenied()),
SLOT(handleResourcesLost()));
connect(m_resourcePolicy, SIGNAL(resourcesLost()),
SLOT(handleResourcesLost()));
connect(m_session, SIGNAL(busyChanged(bool)),
SLOT(handleBusyChanged(bool)));
}
CameraBinControl::~CameraBinControl()
{
}
QCamera::CaptureMode CameraBinControl::captureMode() const
{
return m_session->captureMode();
}
void CameraBinControl::setCaptureMode(QCamera::CaptureMode mode)
{
if (m_session->captureMode() != mode) {
m_session->setCaptureMode(mode);
reloadLater();
if (m_state == QCamera::ActiveState) {
m_resourcePolicy->setResourceSet(
captureMode() == QCamera::CaptureStillImage ?
CamerabinResourcePolicy::ImageCaptureResources :
CamerabinResourcePolicy::VideoCaptureResources);
}
emit captureModeChanged(mode);
}
}
bool CameraBinControl::isCaptureModeSupported(QCamera::CaptureMode mode) const
{
#ifdef Q_WS_MAEMO_5
//Front camera on N900 supports only video capture
if (m_session->cameraRole() == CameraBinSession::FrontCamera)
return mode == QCamera::CaptureVideo;
#endif
return mode == QCamera::CaptureStillImage || mode == QCamera::CaptureVideo;
}
void CameraBinControl::setState(QCamera::State state)
{
#ifdef CAMEABIN_DEBUG
qDebug() << Q_FUNC_INFO << ENUM_NAME(QCamera, "State", state);
#endif
if (m_state != state) {
m_state = state;
//special case for stopping the camera while it's busy,
//it should be delayed until the camera is idle
if (state == QCamera::LoadedState &&
m_session->state() == QCamera::ActiveState &&
m_session->isBusy()) {
#ifdef CAMEABIN_DEBUG
qDebug() << Q_FUNC_INFO << "Camera is busy, QCamera::stop() is delayed";
#endif
emit stateChanged(m_state);
return;
}
CamerabinResourcePolicy::ResourceSet resourceSet;
switch (state) {
case QCamera::UnloadedState:
resourceSet = CamerabinResourcePolicy::NoResources;
break;
case QCamera::LoadedState:
resourceSet = CamerabinResourcePolicy::LoadedResources;
break;
case QCamera::ActiveState:
resourceSet = captureMode() == QCamera::CaptureStillImage ?
CamerabinResourcePolicy::ImageCaptureResources :
CamerabinResourcePolicy::VideoCaptureResources;
break;
}
m_resourcePolicy->setResourceSet(resourceSet);
if (m_resourcePolicy->isResourcesGranted()) {
//postpone changing to Active if the session is nor ready yet
if (state == QCamera::ActiveState) {
if (m_session->isReady()) {
m_session->setState(state);
} else {
#ifdef CAMEABIN_DEBUG
qDebug() << "Camera session is not ready yet, postpone activating";
#endif
}
} else
m_session->setState(state);
}
emit stateChanged(m_state);
}
}
QCamera::State CameraBinControl::state() const
{
return m_state;
}
void CameraBinControl::updateStatus()
{
QCamera::State sessionState = m_session->state();
QCamera::Status oldStatus = m_status;
switch (m_state) {
case QCamera::UnloadedState:
m_status = QCamera::UnloadedStatus;
break;
case QCamera::LoadedState:
switch (sessionState) {
case QCamera::UnloadedState:
m_status = QCamera::LoadingStatus;
break;
case QCamera::LoadedState:
m_status = QCamera::LoadedStatus;
break;
case QCamera::ActiveState:
m_status = QCamera::ActiveStatus;
break;
}
break;
case QCamera::ActiveState:
switch (sessionState) {
case QCamera::UnloadedState:
m_status = QCamera::LoadingStatus;
break;
case QCamera::LoadedState:
m_status = QCamera::StartingStatus;
break;
case QCamera::ActiveState:
m_status = QCamera::ActiveStatus;
break;
}
}
if (m_status != oldStatus) {
#ifdef CAMEABIN_DEBUG
qDebug() << "Camera status changed" << ENUM_NAME(QCamera, "Status", m_status);
#endif
emit statusChanged(m_status);
}
}
void CameraBinControl::reloadLater()
{
#ifdef CAMEABIN_DEBUG
qDebug() << "CameraBinControl: reload pipeline requested" << ENUM_NAME(QCamera, "State", m_state);
#endif
if (!m_reloadPending && m_state == QCamera::ActiveState) {
m_reloadPending = true;
if (!m_session->isBusy()) {
m_session->setState(QCamera::LoadedState);
QMetaObject::invokeMethod(this, "delayedReload", Qt::QueuedConnection);
}
}
}
void CameraBinControl::handleResourcesLost()
{
#ifdef CAMEABIN_DEBUG
qDebug() << Q_FUNC_INFO << ENUM_NAME(QCamera, "State", m_state);
#endif
m_session->setState(QCamera::UnloadedState);
}
void CameraBinControl::handleResourcesGranted()
{
#ifdef CAMEABIN_DEBUG
qDebug() << Q_FUNC_INFO << ENUM_NAME(QCamera, "State", m_state);
#endif
//camera will be started soon by delayedReload()
if (m_reloadPending && m_state == QCamera::ActiveState)
return;
if (m_state == QCamera::ActiveState && m_session->isReady())
m_session->setState(QCamera::ActiveState);
else if (m_state == QCamera::LoadedState)
m_session->setState(QCamera::LoadedState);
}
void CameraBinControl::handleBusyChanged(bool busy)
{
if (!busy && m_session->state() == QCamera::ActiveState) {
if (m_state == QCamera::LoadedState) {
//handle delayed stop() because of busy camera
m_resourcePolicy->setResourceSet(CamerabinResourcePolicy::LoadedResources);
m_session->setState(QCamera::LoadedState);
} else if (m_state == QCamera::ActiveState && m_reloadPending) {
//handle delayed reload because of busy camera
m_session->setState(QCamera::LoadedState);
QMetaObject::invokeMethod(this, "delayedReload", Qt::QueuedConnection);
}
}
}
void CameraBinControl::handleCameraError(int errorCode, const QString &errorString)
{
emit error(errorCode, errorString);
setState(QCamera::UnloadedState);
}
void CameraBinControl::delayedReload()
{
#ifdef CAMEABIN_DEBUG
qDebug() << "CameraBinControl: reload pipeline";
#endif
if (m_reloadPending) {
m_reloadPending = false;
if (m_state == QCamera::ActiveState &&
m_session->isReady() &&
m_resourcePolicy->isResourcesGranted()) {
m_session->setState(QCamera::ActiveState);
}
}
}
bool CameraBinControl::canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const
{
Q_UNUSED(status);
switch (changeType) {
case QCameraControl::CaptureMode:
case QCameraControl::ImageEncodingSettings:
case QCameraControl::VideoEncodingSettings:
case QCameraControl::Viewfinder:
return true;
default:
return false;
}
}
#define VIEWFINDER_COLORSPACE_CONVERSION 0x00000004
bool CameraBinControl::viewfinderColorSpaceConversion() const
{
gint flags = 0;
g_object_get(G_OBJECT(m_session->cameraBin()), "flags", &flags, NULL);
return flags & VIEWFINDER_COLORSPACE_CONVERSION;
}
void CameraBinControl::setViewfinderColorSpaceConversion(bool enabled)
{
gint flags = 0;
g_object_get(G_OBJECT(m_session->cameraBin()), "flags", &flags, NULL);
if (enabled)
flags |= VIEWFINDER_COLORSPACE_CONVERSION;
else
flags &= ~VIEWFINDER_COLORSPACE_CONVERSION;
g_object_set(G_OBJECT(m_session->cameraBin()), "flags", flags, NULL);
}

View File

@@ -0,0 +1,101 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINCONTROL_H
#define CAMERABINCONTROL_H
#include <QHash>
#include <qcameracontrol.h>
#include "camerabinsession.h"
QT_USE_NAMESPACE
class CamerabinResourcePolicy;
class CameraBinControl : public QCameraControl
{
Q_OBJECT
Q_PROPERTY(bool viewfinderColorSpaceConversion READ viewfinderColorSpaceConversion WRITE setViewfinderColorSpaceConversion)
public:
CameraBinControl( CameraBinSession *session );
virtual ~CameraBinControl();
bool isValid() const { return true; }
QCamera::State state() const;
void setState(QCamera::State state);
QCamera::Status status() const { return m_status; }
QCamera::CaptureMode captureMode() const;
void setCaptureMode(QCamera::CaptureMode mode);
bool isCaptureModeSupported(QCamera::CaptureMode mode) const;
bool canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const;
bool viewfinderColorSpaceConversion() const;
public slots:
void reloadLater();
void setViewfinderColorSpaceConversion(bool enabled);
private slots:
void updateStatus();
void delayedReload();
void handleResourcesGranted();
void handleResourcesLost();
void handleBusyChanged(bool);
void handleCameraError(int error, const QString &errorString);
private:
void updateSupportedResolutions(const QString &device);
CameraBinSession *m_session;
QCamera::State m_state;
QCamera::Status m_status;
CamerabinResourcePolicy *m_resourcePolicy;
bool m_reloadPending;
};
#endif // CAMERABINCONTROL_H

View File

@@ -0,0 +1,232 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabinexposure.h"
#include "camerabinsession.h"
#include <gst/interfaces/photography.h>
#include <QDebug>
CameraBinExposure::CameraBinExposure(CameraBinSession *session)
:QCameraExposureControl(session),
m_session(session)
{
}
CameraBinExposure::~CameraBinExposure()
{
}
QCameraExposure::ExposureMode CameraBinExposure::exposureMode() const
{
GstSceneMode sceneMode;
gst_photography_get_scene_mode(m_session->photography(), &sceneMode);
switch (sceneMode) {
case GST_PHOTOGRAPHY_SCENE_MODE_PORTRAIT: return QCameraExposure::ExposurePortrait;
case GST_PHOTOGRAPHY_SCENE_MODE_SPORT: return QCameraExposure::ExposureSports;
case GST_PHOTOGRAPHY_SCENE_MODE_NIGHT: return QCameraExposure::ExposureNight;
case GST_PHOTOGRAPHY_SCENE_MODE_MANUAL: return QCameraExposure::ExposureManual;
case GST_PHOTOGRAPHY_SCENE_MODE_CLOSEUP: //no direct mapping available so mapping to auto mode
case GST_PHOTOGRAPHY_SCENE_MODE_LANDSCAPE: //no direct mapping available so mapping to auto mode
case GST_PHOTOGRAPHY_SCENE_MODE_AUTO:
default:
return QCameraExposure::ExposureAuto;
}
}
void CameraBinExposure::setExposureMode(QCameraExposure::ExposureMode mode)
{
GstSceneMode sceneMode;
gst_photography_get_scene_mode(m_session->photography(), &sceneMode);
switch (mode) {
case QCameraExposure::ExposureManual: sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_MANUAL; break;
case QCameraExposure::ExposurePortrait: sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_PORTRAIT; break;
case QCameraExposure::ExposureSports: sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_SPORT; break;
case QCameraExposure::ExposureNight: sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_NIGHT; break;
case QCameraExposure::ExposureAuto: sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_AUTO; break;
default:
break;
}
gst_photography_set_scene_mode(m_session->photography(), sceneMode);
}
bool CameraBinExposure::isExposureModeSupported(QCameraExposure::ExposureMode mode) const
{
//Similar mode names can be found in gst as GstSceneMode
return mode == QCameraExposure::ExposureAuto ||
mode == QCameraExposure::ExposurePortrait ||
mode == QCameraExposure::ExposureSports ||
mode == QCameraExposure::ExposureNight;
//No direct mapping available for GST_PHOTOGRAPHY_SCENE_MODE_CLOSEUP and
//GST_PHOTOGRAPHY_SCENE_MODE_LANDSCAPE
}
QCameraExposure::MeteringMode CameraBinExposure::meteringMode() const
{
return QCameraExposure::MeteringMatrix;
}
void CameraBinExposure::setMeteringMode(QCameraExposure::MeteringMode mode)
{
Q_UNUSED(mode);
}
bool CameraBinExposure::isMeteringModeSupported(QCameraExposure::MeteringMode mode) const
{
return mode == QCameraExposure::MeteringMatrix;
}
bool CameraBinExposure::isParameterSupported(ExposureParameter parameter) const
{
switch (parameter) {
case QCameraExposureControl::ExposureCompensation:
case QCameraExposureControl::ISO:
case QCameraExposureControl::Aperture:
case QCameraExposureControl::ShutterSpeed:
return true;
default:
return false;
}
}
QVariant CameraBinExposure::exposureParameter(ExposureParameter parameter) const
{
switch (parameter) {
case QCameraExposureControl::ExposureCompensation:
{
gfloat ev;
gst_photography_get_ev_compensation(m_session->photography(), &ev);
return QVariant(ev);
}
case QCameraExposureControl::ISO:
{
guint isoSpeed = 0;
gst_photography_get_iso_speed(m_session->photography(), &isoSpeed);
return QVariant(isoSpeed);
}
case QCameraExposureControl::Aperture:
return QVariant(2.8);
case QCameraExposureControl::ShutterSpeed:
{
guint32 shutterSpeed = 0;
gst_photography_get_exposure(m_session->photography(), &shutterSpeed);
return QVariant(shutterSpeed/1000000.0);
}
default:
return QVariant();
}
}
QCameraExposureControl::ParameterFlags CameraBinExposure::exposureParameterFlags(ExposureParameter parameter) const
{
QCameraExposureControl::ParameterFlags flags = 0;
switch (parameter) {
case QCameraExposureControl::ExposureCompensation:
flags |= ContinuousRange;
break;
case QCameraExposureControl::Aperture:
flags |= ReadOnly;
break;
default:
break;
}
return flags;
}
QVariantList CameraBinExposure::supportedParameterRange(ExposureParameter parameter) const
{
QVariantList res;
switch (parameter) {
case QCameraExposureControl::ExposureCompensation:
res << -2.0 << 2.0;
break;
case QCameraExposureControl::ISO:
res << 100 << 200 << 400;
break;
case QCameraExposureControl::Aperture:
res << 2.8;
break;
default:
break;
}
return res;
}
bool CameraBinExposure::setExposureParameter(ExposureParameter parameter, const QVariant& value)
{
QVariant oldValue = exposureParameter(parameter);
switch (parameter) {
case QCameraExposureControl::ExposureCompensation:
gst_photography_set_ev_compensation(m_session->photography(), value.toReal());
break;
case QCameraExposureControl::ISO:
gst_photography_set_iso_speed(m_session->photography(), value.toInt());
break;
case QCameraExposureControl::Aperture:
gst_photography_set_aperture(m_session->photography(), guint(value.toReal()*1000000));
break;
case QCameraExposureControl::ShutterSpeed:
gst_photography_set_exposure(m_session->photography(), guint(value.toReal()*1000000));
break;
default:
return false;
}
QVariant newValue = exposureParameter(parameter);
if (!qFuzzyCompare(oldValue.toReal(), newValue.toReal()))
emit exposureParameterChanged(parameter);
return true;
}
QString CameraBinExposure::extendedParameterName(ExposureParameter)
{
return QString();
}

View File

@@ -0,0 +1,83 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINEXPOSURECONTROL_MAEMO_H
#define CAMERABINEXPOSURECONTROL_MAEMO_H
#include <qcamera.h>
#include <qcameraexposurecontrol.h>
#include <gst/gst.h>
#include <glib.h>
class CameraBinSession;
QT_USE_NAMESPACE
class Q_MULTIMEDIA_EXPORT CameraBinExposure : public QCameraExposureControl
{
Q_OBJECT
public:
CameraBinExposure(CameraBinSession *session);
virtual ~CameraBinExposure();
QCameraExposure::ExposureMode exposureMode() const;
void setExposureMode(QCameraExposure::ExposureMode mode);
bool isExposureModeSupported(QCameraExposure::ExposureMode mode) const;
QCameraExposure::MeteringMode meteringMode() const;
void setMeteringMode(QCameraExposure::MeteringMode mode);
bool isMeteringModeSupported(QCameraExposure::MeteringMode mode) const;
bool isParameterSupported(ExposureParameter parameter) const;
QVariant exposureParameter(ExposureParameter parameter) const;
ParameterFlags exposureParameterFlags(ExposureParameter parameter) const;
QVariantList supportedParameterRange(ExposureParameter parameter) const;
bool setExposureParameter(ExposureParameter parameter, const QVariant& value);
QString extendedParameterName(ExposureParameter parameter);
private:
CameraBinSession *m_session;
};
#endif // CAMERABINEXPOSURECONTROL_MAEMO_H

View File

@@ -0,0 +1,104 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabinflash.h"
#include "camerabinsession.h"
#include <gst/interfaces/photography.h>
#include <QDebug>
CameraBinFlash::CameraBinFlash(CameraBinSession *session)
:QCameraFlashControl(session),
m_session(session)
{
}
CameraBinFlash::~CameraBinFlash()
{
}
QCameraExposure::FlashModes CameraBinFlash::flashMode() const
{
GstFlashMode flashMode;
gst_photography_get_flash_mode(m_session->photography(), &flashMode);
QCameraExposure::FlashModes modes;
switch (flashMode) {
case GST_PHOTOGRAPHY_FLASH_MODE_AUTO: modes |= QCameraExposure::FlashAuto; break;
case GST_PHOTOGRAPHY_FLASH_MODE_OFF: modes |= QCameraExposure::FlashOff; break;
case GST_PHOTOGRAPHY_FLASH_MODE_ON: modes |= QCameraExposure::FlashOn; break;
case GST_PHOTOGRAPHY_FLASH_MODE_FILL_IN: modes |= QCameraExposure::FlashFill; break;
case GST_PHOTOGRAPHY_FLASH_MODE_RED_EYE: modes |= QCameraExposure::FlashRedEyeReduction; break;
default:
modes |= QCameraExposure::FlashAuto;
break;
}
return modes;
}
void CameraBinFlash::setFlashMode(QCameraExposure::FlashModes mode)
{
GstFlashMode flashMode;
gst_photography_get_flash_mode(m_session->photography(), &flashMode);
if (mode.testFlag(QCameraExposure::FlashAuto)) flashMode = GST_PHOTOGRAPHY_FLASH_MODE_AUTO;
else if (mode.testFlag(QCameraExposure::FlashOff)) flashMode = GST_PHOTOGRAPHY_FLASH_MODE_OFF;
else if (mode.testFlag(QCameraExposure::FlashOn)) flashMode = GST_PHOTOGRAPHY_FLASH_MODE_ON;
else if (mode.testFlag(QCameraExposure::FlashFill)) flashMode = GST_PHOTOGRAPHY_FLASH_MODE_FILL_IN;
else if (mode.testFlag(QCameraExposure::FlashRedEyeReduction)) flashMode = GST_PHOTOGRAPHY_FLASH_MODE_RED_EYE;
gst_photography_set_flash_mode(m_session->photography(), flashMode);
}
bool CameraBinFlash::isFlashModeSupported(QCameraExposure::FlashModes mode) const
{
return mode == QCameraExposure::FlashOff ||
mode == QCameraExposure::FlashOn ||
mode == QCameraExposure::FlashAuto ||
mode == QCameraExposure::FlashRedEyeReduction ||
mode == QCameraExposure::FlashFill;
}
bool CameraBinFlash::isFlashReady() const
{
return true;
}

View File

@@ -0,0 +1,73 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINFLASHCONTROL_H
#define CAMERABINFLASHCONTROL_H
#include <qcamera.h>
#include <qcameraflashcontrol.h>
#include <gst/gst.h>
#include <glib.h>
class CameraBinSession;
QT_USE_NAMESPACE
class Q_MULTIMEDIA_EXPORT CameraBinFlash : public QCameraFlashControl
{
Q_OBJECT
public:
CameraBinFlash(CameraBinSession *session);
virtual ~CameraBinFlash();
QCameraExposure::FlashModes flashMode() const;
void setFlashMode(QCameraExposure::FlashModes mode);
bool isFlashModeSupported(QCameraExposure::FlashModes mode) const;
bool isFlashReady() const;
private:
CameraBinSession *m_session;
};
#endif // CAMERABINFLASHCONTROL_H

View File

@@ -0,0 +1,245 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabinfocus.h"
#include "camerabinsession.h"
#include <gst/interfaces/photography.h>
#include <QDebug>
#include <QtCore/qmetaobject.h>
//#define CAMERABIN_DEBUG 1
#define ENUM_NAME(c,e,v) (c::staticMetaObject.enumerator(c::staticMetaObject.indexOfEnumerator(e)).valueToKey((v)))
CameraBinFocus::CameraBinFocus(CameraBinSession *session)
:QCameraFocusControl(session),
m_session(session),
m_focusMode(QCameraFocus::AutoFocus),
m_focusStatus(QCamera::Unlocked),
m_focusZoneStatus(QCameraFocusZone::Selected)
{
connect(m_session, SIGNAL(stateChanged(QCamera::State)),
this, SLOT(_q_handleCameraStateChange(QCamera::State)));
connect(m_session, SIGNAL(imageCaptured(int,QImage)),
this, SLOT(_q_handleCapturedImage()));
}
CameraBinFocus::~CameraBinFocus()
{
}
QCameraFocus::FocusMode CameraBinFocus::focusMode() const
{
return m_focusMode;
}
void CameraBinFocus::setFocusMode(QCameraFocus::FocusMode mode)
{
if (isFocusModeSupported(mode)) {
m_focusMode = mode;
}
}
bool CameraBinFocus::isFocusModeSupported(QCameraFocus::FocusMode mode) const
{
return mode & QCameraFocus::AutoFocus;
}
qreal CameraBinFocus::maximumOpticalZoom() const
{
return 1.0;
}
qreal CameraBinFocus::maximumDigitalZoom() const
{
return 10;
}
qreal CameraBinFocus::opticalZoom() const
{
return 1.0;
}
qreal CameraBinFocus::digitalZoom() const
{
#ifdef Q_WS_MAEMO_5
gint zoomFactor = 0;
g_object_get(GST_BIN(m_session->cameraBin()), "zoom", &zoomFactor, NULL);
return zoomFactor/100.0;
#else
gfloat zoomFactor = 1.0;
g_object_get(GST_BIN(m_session->cameraBin()), "zoom", &zoomFactor, NULL);
return zoomFactor;
#endif
}
void CameraBinFocus::zoomTo(qreal optical, qreal digital)
{
Q_UNUSED(optical);
digital = qBound(qreal(1.0), digital, qreal(10.0));
#ifdef Q_WS_MAEMO_5
g_object_set(GST_BIN(m_session->cameraBin()), "zoom", qRound(digital*100.0), NULL);
#else
g_object_set(GST_BIN(m_session->cameraBin()), "zoom", digital, NULL);
#endif
emit digitalZoomChanged(digital);
}
QCameraFocus::FocusPointMode CameraBinFocus::focusPointMode() const
{
return QCameraFocus::FocusPointAuto;
}
void CameraBinFocus::setFocusPointMode(QCameraFocus::FocusPointMode mode)
{
Q_UNUSED(mode);
}
bool CameraBinFocus::isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const
{
return mode == QCameraFocus::FocusPointAuto;
}
QPointF CameraBinFocus::customFocusPoint() const
{
return QPointF(0.5, 0.5);
}
void CameraBinFocus::setCustomFocusPoint(const QPointF &point)
{
Q_UNUSED(point);
}
QCameraFocusZoneList CameraBinFocus::focusZones() const
{
return QCameraFocusZoneList() << QCameraFocusZone(QRectF(0.35, 0.35, 0.3, 0.3), m_focusZoneStatus);
}
void CameraBinFocus::handleFocusMessage(GstMessage *gm)
{
//it's a sync message, so it's called from non main thread
if (gst_structure_has_name(gm->structure, GST_PHOTOGRAPHY_AUTOFOCUS_DONE)) {
gint status = GST_PHOTOGRAPHY_FOCUS_STATUS_NONE;
gst_structure_get_int (gm->structure, "status", &status);
QCamera::LockStatus focusStatus = m_focusStatus;
QCamera::LockChangeReason reason = QCamera::UserRequest;
switch (status) {
case GST_PHOTOGRAPHY_FOCUS_STATUS_FAIL:
focusStatus = QCamera::Unlocked;
reason = QCamera::LockFailed;
break;
case GST_PHOTOGRAPHY_FOCUS_STATUS_SUCCESS:
focusStatus = QCamera::Locked;
break;
case GST_PHOTOGRAPHY_FOCUS_STATUS_NONE:
break;
case GST_PHOTOGRAPHY_FOCUS_STATUS_RUNNING:
focusStatus = QCamera::Searching;
break;
default:
break;
}
static int signalIndex = metaObject()->indexOfSlot(
"_q_setFocusStatus(QCamera::LockStatus,QCamera::LockChangeReason)");
metaObject()->method(signalIndex).invoke(this,
Qt::QueuedConnection,
Q_ARG(QCamera::LockStatus,focusStatus),
Q_ARG(QCamera::LockChangeReason,reason));
}
}
void CameraBinFocus::_q_setFocusStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason)
{
#ifdef CAMERABIN_DEBUG
qDebug() << Q_FUNC_INFO << "Current:"
<< ENUM_NAME(QCamera, "LockStatus", m_focusStatus)
<< "New:"
<< ENUM_NAME(QCamera, "LockStatus", status) << ENUM_NAME(QCamera, "LockChangeReason", reason);
#endif
if (m_focusStatus != status) {
m_focusStatus = status;
QCameraFocusZone::FocusZoneStatus zonesStatus =
m_focusStatus == QCamera::Locked ?
QCameraFocusZone::Focused : QCameraFocusZone::Selected;
if (m_focusZoneStatus != zonesStatus) {
m_focusZoneStatus = zonesStatus;
emit focusZonesChanged();
}
emit _q_focusStatusChanged(m_focusStatus, reason);
}
}
void CameraBinFocus::_q_handleCameraStateChange(QCamera::State state)
{
if (state != QCamera::ActiveState)
_q_setFocusStatus(QCamera::Unlocked, QCamera::LockLost);
}
void CameraBinFocus::_q_handleCapturedImage()
{
#ifdef Q_WS_MAEMO_5
//N900 lost focus after image capture
if (m_focusStatus != QCamera::Unlocked) {
m_focusStatus = QCamera::Unlocked;
emit _q_focusStatusChanged(QCamera::Unlocked, QCamera::LockLost);
}
#endif
}
void CameraBinFocus::_q_startFocusing()
{
_q_setFocusStatus(QCamera::Searching, QCamera::UserRequest);
gst_photography_set_autofocus(m_session->photography(), TRUE);
}
void CameraBinFocus::_q_stopFocusing()
{
gst_photography_set_autofocus(m_session->photography(), FALSE);
_q_setFocusStatus(QCamera::Unlocked, QCamera::UserRequest);
}

View File

@@ -0,0 +1,104 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINFOCUSCONTROL_H
#define CAMERABINFOCUSCONTROL_H
#include <qcamera.h>
#include <qcamerafocuscontrol.h>
#include <gst/gst.h>
#include <glib.h>
class CameraBinSession;
QT_USE_NAMESPACE
class CameraBinFocus : public QCameraFocusControl
{
Q_OBJECT
public:
CameraBinFocus(CameraBinSession *session);
virtual ~CameraBinFocus();
QCameraFocus::FocusMode focusMode() const;
void setFocusMode(QCameraFocus::FocusMode mode);
bool isFocusModeSupported(QCameraFocus::FocusMode mode) const;
qreal maximumOpticalZoom() const;
qreal maximumDigitalZoom() const;
qreal opticalZoom() const;
qreal digitalZoom() const;
void zoomTo(qreal optical, qreal digital) ;
QCameraFocus::FocusPointMode focusPointMode() const;
void setFocusPointMode(QCameraFocus::FocusPointMode mode) ;
bool isFocusPointModeSupported(QCameraFocus::FocusPointMode) const;
QPointF customFocusPoint() const;
void setCustomFocusPoint(const QPointF &point);
QCameraFocusZoneList focusZones() const;
void handleFocusMessage(GstMessage*);
QCamera::LockStatus focusStatus() const { return m_focusStatus; }
Q_SIGNALS:
void _q_focusStatusChanged(QCamera::LockStatus status, QCamera::LockChangeReason reason);
public Q_SLOTS:
void _q_startFocusing();
void _q_stopFocusing();
private Q_SLOTS:
void _q_setFocusStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason);
void _q_handleCameraStateChange(QCamera::State state);
void _q_handleCapturedImage();
private:
CameraBinSession *m_session;
QCameraFocus::FocusMode m_focusMode;
QCamera::LockStatus m_focusStatus;
QCameraFocusZone::FocusZoneStatus m_focusZoneStatus;
};
#endif // CAMERABINFOCUSCONTROL_H

View File

@@ -0,0 +1,347 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabinimagecapture.h"
#include "camerabincapturedestination.h"
#include "camerabincapturebufferformat.h"
#include "camerabinsession.h"
#include "qgstvideobuffer.h"
#include "qvideosurfacegstsink.h"
#include "qgstutils.h"
#include <QtCore/qdebug.h>
#include <QtCore/qbuffer.h>
#include <QtGui/qimagereader.h>
//#define DEBUG_CAPTURE
#ifdef Q_WS_MAEMO_5
#define IMAGE_DONE_SIGNAL "img-done"
#else
#define IMAGE_DONE_SIGNAL "image-done"
#endif
Q_DECLARE_METATYPE(QVideoFrame)
Q_DECLARE_METATYPE(QtMultimediaKit::MetaData)
namespace
{
class CameraRegisterMetaTypes
{
public:
CameraRegisterMetaTypes()
{
qRegisterMetaType<QVideoFrame>("QVideoFrame");
qRegisterMetaType<QtMultimediaKit::MetaData>("QtMultimediaKit::MetaData");
}
} _registerCameraMetaTypes;
}
CameraBinImageCapture::CameraBinImageCapture(CameraBinSession *session)
:QCameraImageCaptureControl(session)
, m_session(session)
, m_ready(false)
, m_requestId(0)
, m_jpegEncoderElement(0)
, m_metadataMuxerElement(0)
{
connect(m_session, SIGNAL(stateChanged(QCamera::State)), SLOT(updateState()));
connect(m_session, SIGNAL(imageExposed(int)), this, SIGNAL(imageExposed(int)));
connect(m_session, SIGNAL(imageCaptured(int,QImage)), this, SIGNAL(imageCaptured(int,QImage)));
connect(m_session, SIGNAL(busMessage(QGstreamerMessage)), SLOT(handleBusMessage(QGstreamerMessage)));
g_signal_connect(G_OBJECT(m_session->cameraBin()), IMAGE_DONE_SIGNAL, G_CALLBACK(handleImageSaved), this);
}
CameraBinImageCapture::~CameraBinImageCapture()
{
}
bool CameraBinImageCapture::isReadyForCapture() const
{
return m_ready;
}
int CameraBinImageCapture::capture(const QString &fileName)
{
m_requestId++;
if (!m_ready) {
emit error(m_requestId, QCameraImageCapture::NotReadyError, tr("Camera not ready"));
return m_requestId;
}
#ifdef DEBUG_CAPTURE
qDebug() << Q_FUNC_INFO << m_requestId << fileName;
#endif
m_session->captureImage(m_requestId, fileName);
return m_requestId;
}
void CameraBinImageCapture::cancelCapture()
{
}
void CameraBinImageCapture::updateState()
{
bool ready = m_session->state() == QCamera::ActiveState;
if (m_ready != ready) {
#ifdef DEBUG_CAPTURE
qDebug() << "readyForCaptureChanged" << ready;
#endif
emit readyForCaptureChanged(m_ready = ready);
}
}
gboolean CameraBinImageCapture::handleImageSaved(GstElement *camera,
const gchar *filename,
CameraBinImageCapture *self)
{
#ifdef DEBUG_CAPTURE
qDebug() << "Image saved" << filename;
#endif
Q_UNUSED(camera);
if (self->m_session->captureDestinationControl()->captureDestination() & QCameraImageCapture::CaptureToFile) {
QMetaObject::invokeMethod(self, "imageSaved",
Qt::QueuedConnection,
Q_ARG(int, self->m_requestId),
Q_ARG(QString, QString::fromUtf8(filename)));
} else {
#ifdef DEBUG_CAPTURE
qDebug() << Q_FUNC_INFO << "Dropped saving file" << filename;
#endif
//camerabin creates an empty file when captured buffer is dropped,
//let's remove it
QFileInfo info(QString::fromUtf8(filename));
if (info.isFile() &&
info.filePath().startsWith("/home") &&
info.size() == 0) {
QFile(info.absoluteFilePath()).remove();
}
}
return true;
}
gboolean CameraBinImageCapture::metadataEventProbe(GstPad *pad, GstEvent *event, CameraBinImageCapture *self)
{
if (GST_EVENT_TYPE(event) == GST_EVENT_TAG) {
GstTagList *gstTags;
gst_event_parse_tag(event, &gstTags);
QMap<QByteArray, QVariant> extendedTags = QGstUtils::gstTagListToMap(gstTags);
#ifdef DEBUG_CAPTURE
qDebug() << QString(gst_structure_to_string(gst_event_get_structure(event))).right(768);
qDebug() << "Capture event probe" << extendedTags;
#endif
QMap<QtMultimediaKit::MetaData, QVariant> tags;
tags[QtMultimediaKit::ISOSpeedRatings] = extendedTags.value("capturing-iso-speed");
tags[QtMultimediaKit::DigitalZoomRatio] = extendedTags.value("capturing-digital-zoom-ratio");
tags[QtMultimediaKit::ExposureTime] = extendedTags.value("capturing-shutter-speed");
tags[QtMultimediaKit::WhiteBalance] = extendedTags.value("capturing-white-balance");
tags[QtMultimediaKit::Flash] = extendedTags.value("capturing-flash-fired");
tags[QtMultimediaKit::FocalLengthIn35mmFilm] = extendedTags.value("capturing-focal-length");
tags[QtMultimediaKit::MeteringMode] = extendedTags.value("capturing-metering-mode");
tags[QtMultimediaKit::ExposureMode] = extendedTags.value("capturing-exposure-mode");
tags[QtMultimediaKit::FNumber] = extendedTags.value("capturing-focal-ratio");
tags[QtMultimediaKit::ExposureMode] = extendedTags.value("capturing-exposure-mode");
QMapIterator<QtMultimediaKit::MetaData, QVariant> i(tags);
while (i.hasNext()) {
i.next();
if (i.value().isValid()) {
QMetaObject::invokeMethod(self, "imageMetadataAvailable",
Qt::QueuedConnection,
Q_ARG(int, self->m_requestId),
Q_ARG(QtMultimediaKit::MetaData, i.key()),
Q_ARG(QVariant, i.value()));
}
}
}
return true;
}
gboolean CameraBinImageCapture::uncompressedBufferProbe(GstPad *pad, GstBuffer *buffer, CameraBinImageCapture *self)
{
Q_UNUSED(pad);
CameraBinSession *session = self->m_session;
#ifdef DEBUG_CAPTURE
qDebug() << "Uncompressed buffer probe" << gst_caps_to_string(GST_BUFFER_CAPS(buffer));
#endif
QCameraImageCapture::CaptureDestinations destination =
session->captureDestinationControl()->captureDestination();
QVideoFrame::PixelFormat format = session->captureBufferFormatControl()->bufferFormat();
if (destination & QCameraImageCapture::CaptureToBuffer) {
if (format != QVideoFrame::Format_Jpeg) {
GstCaps *caps = GST_BUFFER_CAPS(buffer);
int bytesPerLine = -1;
QVideoSurfaceFormat format = QVideoSurfaceGstSink::formatForCaps(caps, &bytesPerLine);
#ifdef DEBUG_CAPTURE
qDebug() << "imageAvailable(uncompressed):" << format;
#endif
QGstVideoBuffer *videoBuffer = new QGstVideoBuffer(buffer, bytesPerLine);
QVideoFrame frame(videoBuffer,
format.frameSize(),
format.pixelFormat());
QMetaObject::invokeMethod(self, "imageAvailable",
Qt::QueuedConnection,
Q_ARG(int, self->m_requestId),
Q_ARG(QVideoFrame, frame));
}
}
//keep the buffer if capture to file or jpeg buffer capture was reuqsted
bool keepBuffer = (destination & QCameraImageCapture::CaptureToFile) ||
((destination & QCameraImageCapture::CaptureToBuffer) &&
format == QVideoFrame::Format_Jpeg);
return keepBuffer;
}
gboolean CameraBinImageCapture::jpegBufferProbe(GstPad *pad, GstBuffer *buffer, CameraBinImageCapture *self)
{
Q_UNUSED(pad);
CameraBinSession *session = self->m_session;
#ifdef DEBUG_CAPTURE
qDebug() << "Jpeg buffer probe" << gst_caps_to_string(GST_BUFFER_CAPS(buffer));
#endif
QCameraImageCapture::CaptureDestinations destination =
session->captureDestinationControl()->captureDestination();
if ((destination & QCameraImageCapture::CaptureToBuffer) &&
session->captureBufferFormatControl()->bufferFormat() == QVideoFrame::Format_Jpeg) {
QGstVideoBuffer *videoBuffer = new QGstVideoBuffer(buffer,
-1); //bytesPerLine is not available for jpegs
QSize resolution = QGstUtils::capsCorrectedResolution(GST_BUFFER_CAPS(buffer));
//if resolution is not presented in caps, try to find it from encoded jpeg data:
if (resolution.isEmpty()) {
QBuffer data;
data.setData(reinterpret_cast<const char*>(GST_BUFFER_DATA(buffer)), GST_BUFFER_SIZE(buffer));
QImageReader reader(&data, "JPEG");
resolution = reader.size();
}
QVideoFrame frame(videoBuffer,
resolution,
QVideoFrame::Format_Jpeg);
QMetaObject::invokeMethod(self, "imageAvailable",
Qt::QueuedConnection,
Q_ARG(int, self->m_requestId),
Q_ARG(QVideoFrame, frame));
}
//drop the buffer if capture to file was disabled
return destination & QCameraImageCapture::CaptureToFile;
}
void CameraBinImageCapture::handleBusMessage(const QGstreamerMessage &message)
{
//Install metadata event and buffer probes
//The image capture pipiline is built dynamically,
//it's necessary to wait until jpeg encoder is added to pipeline
GstMessage *gm = message.rawMessage();
if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_STATE_CHANGED) {
GstState oldState;
GstState newState;
GstState pending;
gst_message_parse_state_changed(gm, &oldState, &newState, &pending);
if (newState == GST_STATE_READY) {
GstElement *element = GST_ELEMENT(GST_MESSAGE_SRC(gm));
if (!element)
return;
QString elementName = QString::fromLatin1(gst_element_get_name(element));
if (elementName.contains("jpegenc") && element != m_jpegEncoderElement) {
m_jpegEncoderElement = element;
GstPad *sinkpad = gst_element_get_static_pad(element, "sink");
//metadata event probe is installed before jpeg encoder
//to emit metadata available signal as soon as possible.
#ifdef DEBUG_CAPTURE
qDebug() << "install metadata probe";
#endif
gst_pad_add_event_probe(sinkpad,
G_CALLBACK(CameraBinImageCapture::metadataEventProbe),
this);
#ifdef DEBUG_CAPTURE
qDebug() << "install uncompressed buffer probe";
#endif
gst_pad_add_buffer_probe(sinkpad,
G_CALLBACK(CameraBinImageCapture::uncompressedBufferProbe),
this);
gst_object_unref(sinkpad);
} else if ((elementName.contains("jifmux") || elementName.startsWith("metadatamux"))
&& element != m_metadataMuxerElement) {
//Jpeg encoded buffer probe is added after jifmux/metadatamux
//element to ensure the resulting jpeg buffer contains capture metadata
m_metadataMuxerElement = element;
GstPad *srcpad = gst_element_get_static_pad(element, "src");
#ifdef DEBUG_CAPTURE
qDebug() << "install jpeg buffer probe";
#endif
gst_pad_add_buffer_probe(srcpad,
G_CALLBACK(CameraBinImageCapture::jpegBufferProbe),
this);
gst_object_unref(srcpad);
}
}
}
}

View File

@@ -0,0 +1,82 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINIMAGECAPTURECONTROL_H
#define CAMERABINIMAGECAPTURECONTROL_H
#include <qcameraimagecapturecontrol.h>
#include "camerabinsession.h"
QT_USE_NAMESPACE
class CameraBinImageCapture : public QCameraImageCaptureControl
{
Q_OBJECT
public:
CameraBinImageCapture(CameraBinSession *session);
virtual ~CameraBinImageCapture();
QCameraImageCapture::DriveMode driveMode() const { return QCameraImageCapture::SingleImageCapture; }
void setDriveMode(QCameraImageCapture::DriveMode) {}
bool isReadyForCapture() const;
int capture(const QString &fileName);
void cancelCapture();
private slots:
void updateState();
void handleBusMessage(const QGstreamerMessage &message);
private:
static gboolean metadataEventProbe(GstPad *pad, GstEvent *event, CameraBinImageCapture *);
static gboolean uncompressedBufferProbe(GstPad *pad, GstBuffer *buffer, CameraBinImageCapture *);
static gboolean jpegBufferProbe(GstPad *pad, GstBuffer *buffer, CameraBinImageCapture *);
static gboolean handleImageSaved(GstElement *camera, const gchar *filename, CameraBinImageCapture *);
CameraBinSession *m_session;
bool m_ready;
int m_requestId;
GstElement *m_jpegEncoderElement;
GstElement *m_metadataMuxerElement;
};
#endif // CAMERABINCAPTURECORNTROL_H

View File

@@ -0,0 +1,87 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabinimageencoder.h"
#include "camerabinsession.h"
#include <QtCore/qdebug.h>
CameraBinImageEncoder::CameraBinImageEncoder(CameraBinSession *session)
:QImageEncoderControl(session), m_session(session)
{
}
CameraBinImageEncoder::~CameraBinImageEncoder()
{
}
QList<QSize> CameraBinImageEncoder::supportedResolutions(const QImageEncoderSettings &, bool *continuous) const
{
qDebug() << "CameraBinImageEncoder::supportedResolutions()";
if (continuous)
*continuous = false;
return m_session->supportedResolutions(qMakePair<int,int>(0,0), continuous, QCamera::CaptureStillImage);
}
QStringList CameraBinImageEncoder::supportedImageCodecs() const
{
return QStringList() << "jpeg";
}
QString CameraBinImageEncoder::imageCodecDescription(const QString &codecName) const
{
if (codecName == "jpeg")
return tr("JPEG image");
return QString();
}
QImageEncoderSettings CameraBinImageEncoder::imageSettings() const
{
return m_settings;
}
void CameraBinImageEncoder::setImageSettings(const QImageEncoderSettings &settings)
{
m_settings = settings;
emit settingsChanged();
}

View File

@@ -0,0 +1,86 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINIMAGEENCODE_H
#define CAMERABINIMAGEENCODE_H
class CameraBinSession;
#include <qimageencodercontrol.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qmap.h>
#include <gst/gst.h>
QT_USE_NAMESPACE
class CameraBinImageEncoder : public QImageEncoderControl
{
Q_OBJECT
public:
CameraBinImageEncoder(CameraBinSession *session);
virtual ~CameraBinImageEncoder();
QList<QSize> supportedResolutions(const QImageEncoderSettings &settings = QImageEncoderSettings(),
bool *continuous = 0) const;
QStringList supportedImageCodecs() const;
QString imageCodecDescription(const QString &formatName) const;
QImageEncoderSettings imageSettings() const;
void setImageSettings(const QImageEncoderSettings &settings);
Q_SIGNALS:
void settingsChanged();
private:
QImageEncoderSettings m_settings;
CameraBinSession *m_session;
// Added
QStringList m_codecs;
QMap<QString,QByteArray> m_elementNames;
QMap<QString,QString> m_codecDescriptions;
QMap<QString,QStringList> m_codecOptions;
};
#endif

View File

@@ -0,0 +1,171 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabinimageprocessing.h"
#include "camerabinsession.h"
CameraBinImageProcessing::CameraBinImageProcessing(CameraBinSession *session)
:QCameraImageProcessingControl(session),
m_session(session)
{
m_mappedWbValues[GST_PHOTOGRAPHY_WB_MODE_AUTO] = QCameraImageProcessing::WhiteBalanceAuto;
m_mappedWbValues[GST_PHOTOGRAPHY_WB_MODE_DAYLIGHT] = QCameraImageProcessing::WhiteBalanceSunlight;
m_mappedWbValues[GST_PHOTOGRAPHY_WB_MODE_CLOUDY] = QCameraImageProcessing::WhiteBalanceCloudy;
m_mappedWbValues[GST_PHOTOGRAPHY_WB_MODE_SUNSET] = QCameraImageProcessing::WhiteBalanceSunset;
m_mappedWbValues[GST_PHOTOGRAPHY_WB_MODE_TUNGSTEN] = QCameraImageProcessing::WhiteBalanceTungsten;
m_mappedWbValues[GST_PHOTOGRAPHY_WB_MODE_FLUORESCENT] = QCameraImageProcessing::WhiteBalanceFluorescent;
updateColorBalanceValues();
}
CameraBinImageProcessing::~CameraBinImageProcessing()
{
}
void CameraBinImageProcessing::updateColorBalanceValues()
{
if (!GST_IS_COLOR_BALANCE(m_session->cameraBin())) {
// Camerabin doesn't implement gstcolorbalance interface
return;
}
GstColorBalance *balance = GST_COLOR_BALANCE(m_session->cameraBin());
const GList *controls = gst_color_balance_list_channels(balance);
const GList *item;
GstColorBalanceChannel *channel;
gint cur_value;
for (item = controls; item; item = g_list_next (item)) {
channel = (GstColorBalanceChannel *)item->data;
cur_value = gst_color_balance_get_value (balance, channel);
if (!g_ascii_strcasecmp (channel->label, "brightness")) {
m_values[QCameraImageProcessingControl::Brightness] = cur_value;
} else if (!g_ascii_strcasecmp (channel->label, "contrast")) {
m_values[QCameraImageProcessingControl::Contrast] = cur_value;
} else if (!g_ascii_strcasecmp (channel->label, "saturation")) {
m_values[QCameraImageProcessingControl::Saturation] = cur_value;
}
}
}
bool CameraBinImageProcessing::setColorBalanceValue(const QString& channel, int value)
{
if (!GST_IS_COLOR_BALANCE(m_session->cameraBin())) {
// Camerabin doesn't implement gstcolorbalance interface
return false;
}
GstColorBalance *balance = GST_COLOR_BALANCE(m_session->cameraBin());
const GList *controls = gst_color_balance_list_channels(balance);
const GList *item;
GstColorBalanceChannel *colorBalanceChannel;
for (item = controls; item; item = g_list_next (item)) {
colorBalanceChannel = (GstColorBalanceChannel *)item->data;
if (!g_ascii_strcasecmp (colorBalanceChannel->label, channel.toAscii())) {
gst_color_balance_set_value (balance, colorBalanceChannel, value);
return true;
}
}
return false;
}
QCameraImageProcessing::WhiteBalanceMode CameraBinImageProcessing::whiteBalanceMode() const
{
GstWhiteBalanceMode wbMode;
gst_photography_get_white_balance_mode(m_session->photography(), &wbMode);
return m_mappedWbValues[wbMode];
}
void CameraBinImageProcessing::setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceMode mode)
{
if (isWhiteBalanceModeSupported(mode))
gst_photography_set_white_balance_mode(m_session->photography(), m_mappedWbValues.key(mode));
}
bool CameraBinImageProcessing::isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceMode mode) const
{
return m_mappedWbValues.values().contains(mode);
}
bool CameraBinImageProcessing::isProcessingParameterSupported(QCameraImageProcessingControl::ProcessingParameter parameter) const
{
return parameter == QCameraImageProcessingControl::Contrast
|| parameter == QCameraImageProcessingControl::Brightness
|| parameter == QCameraImageProcessingControl::Saturation;
}
QVariant CameraBinImageProcessing::processingParameter(
QCameraImageProcessingControl::ProcessingParameter parameter) const
{
if (m_values.contains(parameter))
return m_values.value(parameter);
else
return QVariant();
}
void CameraBinImageProcessing::setProcessingParameter(
QCameraImageProcessingControl::ProcessingParameter parameter,
QVariant value)
{
switch (parameter) {
case Contrast:
setColorBalanceValue("contrast", value.toInt());
break;
case Brightness:
setColorBalanceValue("brightness", value.toInt());
break;
case Saturation:
setColorBalanceValue("saturation", value.toInt());
break;
default:
break;
}
updateColorBalanceValues();
}

View File

@@ -0,0 +1,84 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINIMAGEPROCESSINGCONTROL_H
#define CAMERABINIMAGEPROCESSINGCONTROL_H
#include <qcamera.h>
#include <qcameraimageprocessingcontrol.h>
#include <gst/gst.h>
#include <glib.h>
#include <gst/interfaces/photography.h>
#include <gst/interfaces/colorbalance.h>
class CameraBinSession;
QT_USE_NAMESPACE
class CameraBinImageProcessing : public QCameraImageProcessingControl
{
Q_OBJECT
public:
CameraBinImageProcessing(CameraBinSession *session);
virtual ~CameraBinImageProcessing();
QCameraImageProcessing::WhiteBalanceMode whiteBalanceMode() const;
void setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceMode mode);
bool isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceMode mode) const;
bool isProcessingParameterSupported(ProcessingParameter) const;
QVariant processingParameter(ProcessingParameter parameter) const;
void setProcessingParameter(ProcessingParameter parameter, QVariant value);
private:
bool setColorBalanceValue(const QString& channel, int value);
void updateColorBalanceValues();
private:
CameraBinSession *m_session;
QMap<QCameraImageProcessingControl::ProcessingParameter, int> m_values;
QMap<GstWhiteBalanceMode, QCameraImageProcessing::WhiteBalanceMode> m_mappedWbValues;
};
#endif // CAMERABINIMAGEPROCESSINGCONTROL_H

View File

@@ -0,0 +1,88 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabinlocks.h"
#include "camerabinsession.h"
#include "camerabinfocus.h"
#include <gst/interfaces/photography.h>
#include <QDebug>
CameraBinLocks::CameraBinLocks(CameraBinSession *session)
:QCameraLocksControl(session),
m_session(session),
m_focus(m_session->cameraFocusControl())
{
connect(m_focus, SIGNAL(_q_focusStatusChanged(QCamera::LockStatus, QCamera::LockChangeReason)),
this, SLOT(updateFocusStatus(QCamera::LockStatus, QCamera::LockChangeReason)));
}
CameraBinLocks::~CameraBinLocks()
{
}
QCamera::LockTypes CameraBinLocks::supportedLocks() const
{
return QCamera::LockFocus;
}
QCamera::LockStatus CameraBinLocks::lockStatus(QCamera::LockType lock) const
{
return lock == QCamera::LockFocus ? m_focus->focusStatus() : QCamera::Unlocked;
}
void CameraBinLocks::searchAndLock(QCamera::LockTypes locks)
{
if (locks & QCamera::LockFocus)
m_focus->_q_startFocusing();
}
void CameraBinLocks::unlock(QCamera::LockTypes locks)
{
if (locks & QCamera::LockFocus)
m_focus->_q_stopFocusing();
}
void CameraBinLocks::updateFocusStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason)
{
emit lockStatusChanged(QCamera::LockFocus, status, reason);
}

View File

@@ -0,0 +1,79 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINLOCKSCONTROL_H
#define CAMERABINLOCKSCONTROL_H
#include <qcamera.h>
#include <qcameralockscontrol.h>
#include <gst/gst.h>
#include <glib.h>
class CameraBinSession;
class CameraBinFocus;
QT_USE_NAMESPACE
class CameraBinLocks : public QCameraLocksControl
{
Q_OBJECT
public:
CameraBinLocks(CameraBinSession *session);
virtual ~CameraBinLocks();
QCamera::LockTypes supportedLocks() const;
QCamera::LockStatus lockStatus(QCamera::LockType lock) const;
void searchAndLock(QCamera::LockTypes locks);
void unlock(QCamera::LockTypes locks);
private slots:
void updateFocusStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason);
private:
CameraBinSession *m_session;
CameraBinFocus *m_focus;
};
#endif

View File

@@ -0,0 +1,198 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabinmetadata.h"
#include <gst/gst.h>
#include <gst/gstversion.h>
struct QGstreamerMetaDataKeyLookup
{
QtMultimediaKit::MetaData key;
const char *token;
};
static const QGstreamerMetaDataKeyLookup qt_gstreamerMetaDataKeys[] =
{
{ QtMultimediaKit::Title, GST_TAG_TITLE },
//{ QtMultimediaKit::SubTitle, 0 },
//{ QtMultimediaKit::Author, 0 },
{ QtMultimediaKit::Comment, GST_TAG_COMMENT },
{ QtMultimediaKit::Description, GST_TAG_DESCRIPTION },
//{ QtMultimediaKit::Category, 0 },
{ QtMultimediaKit::Genre, GST_TAG_GENRE },
//{ QtMultimediaKit::Year, 0 },
//{ QtMultimediaKit::UserRating, 0 },
{ QtMultimediaKit::Language, GST_TAG_LANGUAGE_CODE },
{ QtMultimediaKit::Publisher, GST_TAG_ORGANIZATION },
{ QtMultimediaKit::Copyright, GST_TAG_COPYRIGHT },
//{ QtMultimediaKit::ParentalRating, 0 },
//{ QtMultimediaKit::RatingOrganisation, 0 },
// Media
//{ QtMultimediaKit::Size, 0 },
//{ QtMultimediaKit::MediaType, 0 },
{ QtMultimediaKit::Duration, GST_TAG_DURATION },
// Audio
{ QtMultimediaKit::AudioBitRate, GST_TAG_BITRATE },
{ QtMultimediaKit::AudioCodec, GST_TAG_AUDIO_CODEC },
//{ QtMultimediaKit::ChannelCount, 0 },
//{ QtMultimediaKit::SampleRate, 0 },
// Music
{ QtMultimediaKit::AlbumTitle, GST_TAG_ALBUM },
{ QtMultimediaKit::AlbumArtist, GST_TAG_ARTIST},
{ QtMultimediaKit::ContributingArtist, GST_TAG_PERFORMER },
#if (GST_VERSION_MAJOR >= 0) && (GST_VERSION_MINOR >= 10) && (GST_VERSION_MICRO >= 19)
{ QtMultimediaKit::Composer, GST_TAG_COMPOSER },
#endif
//{ QtMultimediaKit::Conductor, 0 },
//{ QtMultimediaKit::Lyrics, 0 },
//{ QtMultimediaKit::Mood, 0 },
{ QtMultimediaKit::TrackNumber, GST_TAG_TRACK_NUMBER },
//{ QtMultimediaKit::CoverArtUrlSmall, 0 },
//{ QtMultimediaKit::CoverArtUrlLarge, 0 },
// Image/Video
//{ QtMultimediaKit::Resolution, 0 },
//{ QtMultimediaKit::PixelAspectRatio, 0 },
// Video
//{ QtMultimediaKit::VideoFrameRate, 0 },
//{ QtMultimediaKit::VideoBitRate, 0 },
{ QtMultimediaKit::VideoCodec, GST_TAG_VIDEO_CODEC },
//{ QtMultimediaKit::PosterUrl, 0 },
// Movie
//{ QtMultimediaKit::ChapterNumber, 0 },
//{ QtMultimediaKit::Director, 0 },
{ QtMultimediaKit::LeadPerformer, GST_TAG_PERFORMER },
//{ QtMultimediaKit::Writer, 0 },
// Photos
//{ QtMultimediaKit::CameraManufacturer, 0 },
//{ QtMultimediaKit::CameraModel, 0 },
//{ QtMultimediaKit::Event, 0 },
//{ QtMultimediaKit::Subject, 0 }
};
CameraBinMetaData::CameraBinMetaData(QObject *parent)
:QMetaDataWriterControl(parent)
{
}
QVariant CameraBinMetaData::metaData(QtMultimediaKit::MetaData key) const
{
static const int count = sizeof(qt_gstreamerMetaDataKeys) / sizeof(QGstreamerMetaDataKeyLookup);
for (int i = 0; i < count; ++i) {
if (qt_gstreamerMetaDataKeys[i].key == key) {
const char *name = qt_gstreamerMetaDataKeys[i].token;
return m_values.value(QByteArray::fromRawData(name, qstrlen(name)));
}
}
return QVariant();
}
void CameraBinMetaData::setMetaData(QtMultimediaKit::MetaData key, const QVariant &value)
{
static const int count = sizeof(qt_gstreamerMetaDataKeys) / sizeof(QGstreamerMetaDataKeyLookup);
for (int i = 0; i < count; ++i) {
if (qt_gstreamerMetaDataKeys[i].key == key) {
const char *name = qt_gstreamerMetaDataKeys[i].token;
m_values.insert(QByteArray::fromRawData(name, qstrlen(name)), value);
emit QMetaDataWriterControl::metaDataChanged();
emit metaDataChanged(m_values);
return;
}
}
}
QList<QtMultimediaKit::MetaData> CameraBinMetaData::availableMetaData() const
{
static QMap<QByteArray, QtMultimediaKit::MetaData> keysMap;
if (keysMap.isEmpty()) {
const int count = sizeof(qt_gstreamerMetaDataKeys) / sizeof(QGstreamerMetaDataKeyLookup);
for (int i = 0; i < count; ++i) {
keysMap[QByteArray(qt_gstreamerMetaDataKeys[i].token)] = qt_gstreamerMetaDataKeys[i].key;
}
}
QList<QtMultimediaKit::MetaData> res;
foreach (const QByteArray &key, m_values.keys()) {
QtMultimediaKit::MetaData tag = keysMap.value(key, QtMultimediaKit::MetaData(-1));
if (tag != -1)
res.append(tag);
}
return res;
}
QVariant CameraBinMetaData::extendedMetaData(QString const &name) const
{
return m_values.value(name.toLatin1());
}
void CameraBinMetaData::setExtendedMetaData(QString const &name, QVariant const &value)
{
m_values.insert(name.toLatin1(), value);
emit QMetaDataWriterControl::metaDataChanged();
emit metaDataChanged(m_values);
}
QStringList CameraBinMetaData::availableExtendedMetaData() const
{
QStringList res;
foreach (const QByteArray &key, m_values.keys())
res.append(QString(key));
return res;
}

View File

@@ -0,0 +1,75 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINCAPTUREMETADATACONTROL_H
#define CAMERABINCAPTUREMETADATACONTROL_H
#include <qmetadatawritercontrol.h>
QT_USE_NAMESPACE
class CameraBinMetaData : public QMetaDataWriterControl
{
Q_OBJECT
public:
CameraBinMetaData(QObject *parent);
virtual ~CameraBinMetaData() {}
bool isMetaDataAvailable() const { return true; }
bool isWritable() const { return true; }
QVariant metaData(QtMultimediaKit::MetaData key) const;
void setMetaData(QtMultimediaKit::MetaData key, const QVariant &value);
QList<QtMultimediaKit::MetaData> availableMetaData() const;
QVariant extendedMetaData(QString const &name) const;
void setExtendedMetaData(QString const &name, QVariant const &value);
QStringList availableExtendedMetaData() const;
Q_SIGNALS:
void metaDataChanged(const QMap<QByteArray, QVariant>&);
private:
QMap<QByteArray, QVariant> m_values;
};
#endif // CAMERABINCAPTUREMETADATACONTROL_H

View File

@@ -0,0 +1,225 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabinrecorder.h"
#include "camerabinaudioencoder.h"
#include "camerabinvideoencoder.h"
#include "camerabincontainer.h"
#include <QtCore/QDebug>
CameraBinRecorder::CameraBinRecorder(CameraBinSession *session)
:QMediaRecorderControl(session),
m_session(session),
m_state(QMediaRecorder::StoppedState)
{
connect(m_session, SIGNAL(stateChanged(QCamera::State)), SLOT(updateState()));
connect(m_session, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged(qint64)));
connect(m_session, SIGNAL(mutedChanged(bool)), this, SIGNAL(mutedChanged(bool)));
}
CameraBinRecorder::~CameraBinRecorder()
{
}
QUrl CameraBinRecorder::outputLocation() const
{
return m_session->outputLocation();
}
bool CameraBinRecorder::setOutputLocation(const QUrl &sink)
{
m_session->setOutputLocation(sink);
return true;
}
QMediaRecorder::State CameraBinRecorder::state() const
{
return m_state;
}
void CameraBinRecorder::updateState()
{
if (m_session->state() != QCamera::ActiveState &&
m_state != QMediaRecorder::StoppedState) {
m_session->stopVideoRecording();
emit stateChanged(m_state = QMediaRecorder::StoppedState);
}
}
qint64 CameraBinRecorder::duration() const
{
return m_session->duration();
}
void CameraBinRecorder::record()
{
if (m_session->state() == QCamera::ActiveState) {
if (m_state == QMediaRecorder::PausedState)
m_session->resumeVideoRecording();
else
m_session->recordVideo();
emit stateChanged(m_state = QMediaRecorder::RecordingState);
} else
emit error(QMediaRecorder::ResourceError, tr("Service has not been started"));
}
void CameraBinRecorder::pause()
{
if (m_session->state() == QCamera::ActiveState) {
m_session->pauseVideoRecording();
emit stateChanged(m_state = QMediaRecorder::PausedState);
} else
emit error(QMediaRecorder::ResourceError, tr("Service has not been started"));
}
void CameraBinRecorder::stop()
{
if (m_session->state() == QCamera::ActiveState) {
m_session->stopVideoRecording();
emit stateChanged(m_state = QMediaRecorder::StoppedState);
}
}
bool CameraBinRecorder::findCodecs()
{
//Check the codecs are compatible with container,
//and choose the compatible codecs/container if omitted
CameraBinAudioEncoder *audioEncodeControl = m_session->audioEncodeControl();
CameraBinVideoEncoder *videoEncodeControl = m_session->videoEncodeControl();
CameraBinContainer *mediaContainerControl = m_session->mediaContainerControl();
audioEncodeControl->resetActualSettings();
videoEncodeControl->resetActualSettings();
mediaContainerControl->resetActualContainer();
QStringList containerCandidates;
if (mediaContainerControl->containerMimeType().isEmpty())
containerCandidates = mediaContainerControl->supportedContainers();
else
containerCandidates << mediaContainerControl->containerMimeType();
QStringList audioCandidates;
QAudioEncoderSettings audioSettings = audioEncodeControl->audioSettings();
if (audioSettings.codec().isEmpty())
audioCandidates = audioEncodeControl->supportedAudioCodecs();
else
audioCandidates << audioSettings.codec();
QStringList videoCandidates;
QVideoEncoderSettings videoSettings = videoEncodeControl->videoSettings();
if (videoSettings.codec().isEmpty())
videoCandidates = videoEncodeControl->supportedVideoCodecs();
else
videoCandidates << videoSettings.codec();
QString container;
QString audioCodec;
QString videoCodec;
foreach (const QString &containerCandidate, containerCandidates) {
QSet<QString> supportedTypes = mediaContainerControl->supportedStreamTypes(containerCandidate);
audioCodec.clear();
videoCodec.clear();
bool found = false;
foreach (const QString &audioCandidate, audioCandidates) {
QSet<QString> audioTypes = audioEncodeControl->supportedStreamTypes(audioCandidate);
if (!audioTypes.intersect(supportedTypes).isEmpty()) {
found = true;
audioCodec = audioCandidate;
break;
}
}
if (!found)
continue;
found = false;
foreach (const QString &videoCandidate, videoCandidates) {
QSet<QString> videoTypes = videoEncodeControl->supportedStreamTypes(videoCandidate);
if (!videoTypes.intersect(supportedTypes).isEmpty()) {
found = true;
videoCodec = videoCandidate;
break;
}
}
if (!found)
continue;
container = containerCandidate;
break;
}
if (container.isEmpty()) {
qWarning() << "Camera error: Not compatible codecs and container format.";
emit error(QMediaRecorder::FormatError, tr("Not compatible codecs and container format."));
return false;
} else {
mediaContainerControl->setActualContainer(container);
QAudioEncoderSettings audioSettings = audioEncodeControl->audioSettings();
audioSettings.setCodec(audioCodec);
audioEncodeControl->setActualAudioSettings(audioSettings);
QVideoEncoderSettings videoSettings = videoEncodeControl->videoSettings();
videoSettings.setCodec(videoCodec);
videoEncodeControl->setActualVideoSettings(videoSettings);
}
return true;
}
void CameraBinRecorder::applySettings()
{
findCodecs();
}
bool CameraBinRecorder::isMuted() const
{
return m_session->isMuted();
}
void CameraBinRecorder::setMuted(bool muted)
{
m_session->setMuted(muted);
}

View File

@@ -0,0 +1,85 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINRECORDERCONTROL_H
#define CAMERABINRECORDERCONTROL_H
#include <qmediarecordercontrol.h>
#include "camerabinsession.h"
QT_USE_NAMESPACE
class CameraBinRecorder : public QMediaRecorderControl
{
Q_OBJECT
public:
CameraBinRecorder(CameraBinSession *session);
virtual ~CameraBinRecorder();
QUrl outputLocation() const;
bool setOutputLocation(const QUrl &sink);
QMediaRecorder::State state() const;
qint64 duration() const;
bool isMuted() const;
bool findCodecs();
void applySettings();
public slots:
void record();
void pause();
void stop();
void setMuted(bool);
private slots:
void updateState();
private:
CameraBinSession *m_session;
QMediaRecorder::State m_state;
};
#endif // CAMERABINCAPTURECORNTROL_H

View File

@@ -0,0 +1,188 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabinresourcepolicy.h"
#ifdef Q_WS_MAEMO_6
#define HAVE_RESOURCE_POLICY
#endif
//#define DEBUG_RESOURCE_POLICY
#include <QtCore/qdebug.h>
#include <QtCore/qset.h>
#ifdef HAVE_RESOURCE_POLICY
#include <policy/resource.h>
#include <policy/resources.h>
#include <policy/resource-set.h>
#endif
CamerabinResourcePolicy::CamerabinResourcePolicy(QObject *parent) :
QObject(parent),
m_resourceSet(NoResources),
m_releasingResources(false)
{
#ifdef HAVE_RESOURCE_POLICY
//loaded resource set is also kept requested for image and video capture sets
m_resource = new ResourcePolicy::ResourceSet("camera");
m_resource->setAlwaysReply();
m_resource->initAndConnect();
connect(m_resource, SIGNAL(resourcesGranted(const QList<ResourcePolicy::ResourceType>)),
SIGNAL(resourcesGranted()));
connect(m_resource, SIGNAL(resourcesDenied()), SIGNAL(resourcesDenied()));
connect(m_resource, SIGNAL(lostResources()), SIGNAL(resourcesLost()));
connect(m_resource, SIGNAL(resourcesReleased()), SLOT(handleResourcesReleased()));
#endif
}
CamerabinResourcePolicy::~CamerabinResourcePolicy()
{
#ifdef HAVE_RESOURCE_POLICY
//ensure the resources are released
if (m_resourceSet != NoResources)
setResourceSet(NoResources);
//don't delete the resource set until resources are released
if (m_releasingResources) {
m_resource->connect(m_resource, SIGNAL(resourcesReleased()),
SLOT(deleteLater()));
} else {
delete m_resource;
m_resource = 0;
}
#endif
}
CamerabinResourcePolicy::ResourceSet CamerabinResourcePolicy::resourceSet() const
{
return m_resourceSet;
}
void CamerabinResourcePolicy::setResourceSet(CamerabinResourcePolicy::ResourceSet set)
{
CamerabinResourcePolicy::ResourceSet oldSet = m_resourceSet;
m_resourceSet = set;
#ifdef DEBUG_RESOURCE_POLICY
qDebug() << Q_FUNC_INFO << set;
#endif
#ifdef HAVE_RESOURCE_POLICY
QSet<ResourcePolicy::ResourceType> requestedTypes;
switch (set) {
case NoResources:
break;
case LoadedResources:
requestedTypes << ResourcePolicy::LensCoverType //to detect lens cover is opened/closed
<< ResourcePolicy::VideoRecorderType //to open camera device
<< ResourcePolicy::SnapButtonType; //to detect capture button events
break;
case ImageCaptureResources:
requestedTypes << ResourcePolicy::LensCoverType
<< ResourcePolicy::VideoPlaybackType
<< ResourcePolicy::VideoRecorderType
<< ResourcePolicy::AudioPlaybackType
<< ResourcePolicy::ScaleButtonType
<< ResourcePolicy::LedsType
<< ResourcePolicy::SnapButtonType;
break;
case VideoCaptureResources:
requestedTypes << ResourcePolicy::LensCoverType
<< ResourcePolicy::VideoPlaybackType
<< ResourcePolicy::VideoRecorderType
<< ResourcePolicy::AudioPlaybackType
<< ResourcePolicy::AudioRecorderType
<< ResourcePolicy::ScaleButtonType
<< ResourcePolicy::LedsType
<< ResourcePolicy::SnapButtonType;
break;
}
QSet<ResourcePolicy::ResourceType> currentTypes;
foreach (ResourcePolicy::Resource *resource, m_resource->resources())
currentTypes << resource->type();
foreach (ResourcePolicy::ResourceType resourceType, currentTypes - requestedTypes)
m_resource->deleteResource(resourceType);
foreach (ResourcePolicy::ResourceType resourceType, requestedTypes - currentTypes) {
if (resourceType == ResourcePolicy::LensCoverType) {
ResourcePolicy::LensCoverResource *lensCoverResource = new ResourcePolicy::LensCoverResource;
lensCoverResource->setOptional(true);
m_resource->addResourceObject(lensCoverResource);
} else {
m_resource->addResource(resourceType);
}
}
m_resource->update();
if (set != NoResources) {
m_resource->acquire();
} else {
if (oldSet != NoResources) {
m_releasingResources = true;
m_resource->release();
}
}
#endif
}
bool CamerabinResourcePolicy::isResourcesGranted() const
{
#ifdef HAVE_RESOURCE_POLICY
foreach (ResourcePolicy::Resource *resource, m_resource->resources())
if (!resource->isOptional() && !resource->isGranted())
return false;
#endif
return true;
}
void CamerabinResourcePolicy::handleResourcesReleased()
{
#ifdef HAVE_RESOURCE_POLICY
#ifdef DEBUG_RESOURCE_POLICY
qDebug() << Q_FUNC_INFO;
#endif
m_releasingResources = false;
#endif
}

View File

@@ -0,0 +1,84 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERARESOURCEPOLICY_H
#define CAMERARESOURCEPOLICY_H
#include <QtCore/qobject.h>
namespace ResourcePolicy {
class ResourceSet;
};
class CamerabinResourcePolicy : public QObject
{
Q_OBJECT
public:
enum ResourceSet {
NoResources,
LoadedResources,
ImageCaptureResources,
VideoCaptureResources
};
CamerabinResourcePolicy(QObject *parent);
~CamerabinResourcePolicy();
ResourceSet resourceSet() const;
void setResourceSet(ResourceSet set);
bool isResourcesGranted() const;
Q_SIGNALS:
void resourcesDenied();
void resourcesGranted();
void resourcesLost();
private Q_SLOTS:
void handleResourcesReleased();
private:
ResourceSet m_resourceSet;
ResourcePolicy::ResourceSet *m_resource;
bool m_releasingResources;
};
#endif

View File

@@ -0,0 +1,261 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabinservice.h"
#include "camerabinsession.h"
#include "camerabinrecorder.h"
#include "camerabincontainer.h"
#include "camerabinaudioencoder.h"
#include "camerabinvideoencoder.h"
#include "camerabinimageencoder.h"
#include "qgstreamerbushelper.h"
#include "camerabincontrol.h"
#include "camerabinlocks.h"
#include "camerabinmetadata.h"
#include "camerabinexposure.h"
#include "camerabinflash.h"
#include "camerabinfocus.h"
#include "camerabinimagecapture.h"
#include "camerabinimageprocessing.h"
#include "camerabincapturebufferformat.h"
#include "camerabincapturedestination.h"
#include "qgstreameraudioinputendpointselector.h"
#include "qgstreamervideoinputdevicecontrol.h"
#include "qgstreamervideooverlay.h"
#include "qgstreamervideowindow.h"
#include "qgstreamervideorenderer.h"
#if defined(Q_WS_MAEMO_6) && defined(__arm__)
#include "qgstreamergltexturerenderer.h"
#endif
#include "qgstreamervideowidget.h"
#include <qmediaserviceprovider.h>
#include <QtCore/qdebug.h>
#include <QtCore/qprocess.h>
#if defined(Q_WS_MAEMO_5)
#include "camerabuttonlistener_maemo.h"
#endif
#if defined(Q_WS_MAEMO_6)
#include "camerabuttonlistener_meego.h"
#endif
CameraBinService::CameraBinService(const QString &service, QObject *parent):
QMediaService(parent)
{
m_captureSession = 0;
m_cameraControl = 0;
m_metaDataControl = 0;
m_audioInputEndpointSelector = 0;
m_videoInputDevice = 0;
m_videoOutput = 0;
m_videoRenderer = 0;
m_videoWindow = 0;
m_videoWidgetControl = 0;
m_imageCaptureControl = 0;
if (service == Q_MEDIASERVICE_CAMERA) {
m_captureSession = new CameraBinSession(this);
m_cameraControl = new CameraBinControl(m_captureSession);
m_videoInputDevice = new QGstreamerVideoInputDeviceControl(m_captureSession);
m_imageCaptureControl = new CameraBinImageCapture(m_captureSession);
connect(m_videoInputDevice, SIGNAL(selectedDeviceChanged(QString)),
m_captureSession, SLOT(setDevice(QString)));
if (m_videoInputDevice->deviceCount())
m_captureSession->setDevice(m_videoInputDevice->deviceName(m_videoInputDevice->selectedDevice()));
#if defined(Q_WS_MAEMO_6) && defined(__arm__)
m_videoRenderer = new QGstreamerGLTextureRenderer(this);
#else
m_videoRenderer = new QGstreamerVideoRenderer(this);
#endif
#ifdef Q_WS_MAEMO_6
m_videoWindow = new QGstreamerVideoWindow(this, "omapxvsink");
//m_videoWindow = new QGstreamerVideoWindow(this);
#else
m_videoWindow = new QGstreamerVideoOverlay(this);
#endif
m_videoWidgetControl = new QGstreamerVideoWidgetControl(this);
}
if (!m_captureSession) {
qWarning() << Q_FUNC_INFO << "Service type is not supported:" << service;
return;
}
m_audioInputEndpointSelector = new QGstreamerAudioInputEndpointSelector(this);
connect(m_audioInputEndpointSelector, SIGNAL(activeEndpointChanged(QString)), m_captureSession, SLOT(setCaptureDevice(QString)));
if (m_captureSession && m_audioInputEndpointSelector->availableEndpoints().size() > 0)
m_captureSession->setCaptureDevice(m_audioInputEndpointSelector->defaultEndpoint());
m_metaDataControl = new CameraBinMetaData(this);
connect(m_metaDataControl, SIGNAL(metaDataChanged(QMap<QByteArray,QVariant>)),
m_captureSession, SLOT(setMetaData(QMap<QByteArray,QVariant>)));
#if defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
new CameraButtonListener(this);
#endif
#if defined(Q_WS_MAEMO_5)
//disable the system camera application
QProcess::execute("/usr/sbin/dsmetool -k /usr/bin/camera-ui");
#endif
}
CameraBinService::~CameraBinService()
{
#if defined(Q_WS_MAEMO_5)
//restore the system camera application
QProcess::execute("/usr/sbin/dsmetool -U user -o /usr/bin/camera-ui");
#endif
}
QMediaControl *CameraBinService::requestControl(const char *name)
{
if (!m_captureSession)
return 0;
//qDebug() << "Request control" << name;
if (!m_videoOutput) {
if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
m_videoOutput = m_videoRenderer;
m_captureSession->setViewfinder(m_videoRenderer);
} else if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
m_videoOutput = m_videoWindow;
m_captureSession->setViewfinder(m_videoWindow);
} else if (qstrcmp(name, QVideoWidgetControl_iid) == 0) {
m_captureSession->setViewfinder(m_videoWidgetControl);
m_videoOutput = m_videoWidgetControl;
}
if (m_videoOutput)
return m_videoOutput;
}
if (qstrcmp(name,QAudioEndpointSelector_iid) == 0)
return m_audioInputEndpointSelector;
if (qstrcmp(name,QVideoDeviceControl_iid) == 0)
return m_videoInputDevice;
if (qstrcmp(name,QMediaRecorderControl_iid) == 0)
return m_captureSession->recorderControl();
if (qstrcmp(name,QAudioEncoderControl_iid) == 0)
return m_captureSession->audioEncodeControl();
if (qstrcmp(name,QVideoEncoderControl_iid) == 0)
return m_captureSession->videoEncodeControl();
if (qstrcmp(name,QImageEncoderControl_iid) == 0)
return m_captureSession->imageEncodeControl();
if (qstrcmp(name,QMediaContainerControl_iid) == 0)
return m_captureSession->mediaContainerControl();
if (qstrcmp(name,QCameraControl_iid) == 0)
return m_cameraControl;
if (qstrcmp(name,QMetaDataWriterControl_iid) == 0)
return m_metaDataControl;
if (qstrcmp(name, QCameraImageCaptureControl_iid) == 0)
return m_imageCaptureControl;
if (qstrcmp(name, QCameraExposureControl_iid) == 0)
return m_captureSession->cameraExposureControl();
if (qstrcmp(name, QCameraFlashControl_iid) == 0)
return m_captureSession->cameraFlashControl();
if (qstrcmp(name, QCameraFocusControl_iid) == 0)
return m_captureSession->cameraFocusControl();
if (qstrcmp(name, QCameraImageProcessingControl_iid) == 0)
return m_captureSession->imageProcessingControl();
if (qstrcmp(name, QCameraLocksControl_iid) == 0)
return m_captureSession->cameraLocksControl();
if (qstrcmp(name, QCameraCaptureDestinationControl_iid) == 0)
return m_captureSession->captureDestinationControl();
if (qstrcmp(name, QCameraCaptureBufferFormatControl_iid) == 0)
return m_captureSession->captureBufferFormatControl();
return 0;
}
void CameraBinService::releaseControl(QMediaControl *control)
{
if (control && control == m_videoOutput) {
m_videoOutput = 0;
m_captureSession->setViewfinder(0);
}
}
bool CameraBinService::isCameraBinAvailable()
{
GstElementFactory *factory = gst_element_factory_find("camerabin");
if (factory) {
gst_object_unref(GST_OBJECT(factory));
return true;
}
return false;
}

View File

@@ -0,0 +1,96 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINCAPTURESERVICE_H
#define CAMERABINCAPTURESERVICE_H
#include <qmediaservice.h>
#include <gst/gst.h>
QT_BEGIN_NAMESPACE
class QAudioEndpointSelector;
class QVideoDeviceControl;
QT_END_NAMESPACE
class CameraBinSession;
class CameraBinControl;
class QGstreamerMessage;
class QGstreamerBusHelper;
class QGstreamerVideoRenderer;
class QGstreamerVideoOverlay;
class QGstreamerVideoWidgetControl;
class QGstreamerElementFactory;
class CameraBinMetaData;
class CameraBinImageCapture;
class CameraBinMetaData;
class CameraBinService : public QMediaService
{
Q_OBJECT
public:
CameraBinService(const QString &service, QObject *parent = 0);
virtual ~CameraBinService();
QMediaControl *requestControl(const char *name);
void releaseControl(QMediaControl *);
static bool isCameraBinAvailable();
private:
void setAudioPreview(GstElement*);
CameraBinSession *m_captureSession;
CameraBinControl *m_cameraControl;
CameraBinMetaData *m_metaDataControl;
QAudioEndpointSelector *m_audioInputEndpointSelector;
QVideoDeviceControl *m_videoInputDevice;
QMediaControl *m_videoOutput;
QMediaControl *m_videoRenderer;
QMediaControl *m_videoWindow;
QGstreamerVideoWidgetControl *m_videoWidgetControl;
CameraBinImageCapture *m_imageCaptureControl;
};
#endif // CAMERABINCAPTURESERVICE_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,234 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINCAPTURESESSION_MAEMO_H
#define CAMERABINCAPTURESESSION_MAEMO_H
#include <qmediarecordercontrol.h>
#include <QtCore/qurl.h>
#include <QtCore/qdir.h>
#include <gst/gst.h>
#include <gst/interfaces/photography.h>
#include "qgstreamerbushelper.h"
#include "qcamera.h"
class QGstreamerMessage;
class QGstreamerBusHelper;
class CameraBinAudioEncoder;
class CameraBinVideoEncoder;
class CameraBinImageEncoder;
class CameraBinRecorder;
class CameraBinContainer;
class CameraBinExposure;
class CameraBinFlash;
class CameraBinFocus;
class CameraBinImageProcessing;
class CameraBinLocks;
class CameraBinCaptureDestination;
class CameraBinCaptureBufferFormat;
class QGstreamerVideoRendererInterface;
class QGstreamerElementFactory
{
public:
virtual GstElement *buildElement() = 0;
};
class CameraBinSession : public QObject, public QGstreamerSyncEventFilter
{
Q_OBJECT
Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
public:
enum CameraRole {
FrontCamera, // Secondary camera
BackCamera // Main photo camera
};
CameraBinSession(QObject *parent);
~CameraBinSession();
GstPhotography *photography();
GstElement *cameraBin() { return m_pipeline; }
CameraRole cameraRole() const;
QList< QPair<int,int> > supportedFrameRates(const QSize &frameSize, bool *continuous) const;
QList<QSize> supportedResolutions( QPair<int,int> rate, bool *continuous, QCamera::CaptureMode mode) const;
QCamera::CaptureMode captureMode() { return m_captureMode; }
void setCaptureMode(QCamera::CaptureMode mode);
QUrl outputLocation() const;
bool setOutputLocation(const QUrl& sink);
QDir defaultDir(QCamera::CaptureMode mode) const;
QString generateFileName(const QString &prefix, const QDir &dir, const QString &ext) const;
CameraBinAudioEncoder *audioEncodeControl() const { return m_audioEncodeControl; }
CameraBinVideoEncoder *videoEncodeControl() const { return m_videoEncodeControl; }
CameraBinImageEncoder *imageEncodeControl() const { return m_imageEncodeControl; }
CameraBinExposure *cameraExposureControl() const { return m_cameraExposureControl; }
CameraBinFlash *cameraFlashControl() const { return m_cameraFlashControl; }
CameraBinFocus *cameraFocusControl() const { return m_cameraFocusControl; }
CameraBinImageProcessing *imageProcessingControl() const { return m_imageProcessingControl; }
CameraBinLocks *cameraLocksControl() const { return m_cameraLocksControl; }
CameraBinCaptureDestination *captureDestinationControl() const { return m_captureDestinationControl; }
CameraBinCaptureBufferFormat *captureBufferFormatControl() const { return m_captureBufferFormatControl; }
CameraBinRecorder *recorderControl() const { return m_recorderControl; }
CameraBinContainer *mediaContainerControl() const { return m_mediaContainerControl; }
QGstreamerElementFactory *audioInput() const { return m_audioInputFactory; }
void setAudioInput(QGstreamerElementFactory *audioInput);
QGstreamerElementFactory *videoInput() const { return m_videoInputFactory; }
void setVideoInput(QGstreamerElementFactory *videoInput);
bool isReady() const;
QObject *viewfinder() const { return m_viewfinder; }
void setViewfinder(QObject *viewfinder);
void captureImage(int requestId, const QString &fileName);
QCamera::State state() const;
bool isBusy() const;
qint64 duration() const;
void recordVideo();
void pauseVideoRecording();
void resumeVideoRecording();
void stopVideoRecording();
bool isMuted() const;
bool processSyncMessage(const QGstreamerMessage &message);
signals:
void stateChanged(QCamera::State state);
void durationChanged(qint64 duration);
void error(int error, const QString &errorString);
void imageExposed(int requestId);
void imageCaptured(int requestId, const QImage &img);
void mutedChanged(bool);
void viewfinderChanged();
void readyChanged(bool);
void busyChanged(bool);
void busMessage(const QGstreamerMessage &message);
public slots:
void setDevice(const QString &device);
void setState(QCamera::State);
void setCaptureDevice(const QString &deviceName);
void setMetaData(const QMap<QByteArray, QVariant>&);
void setMuted(bool);
private slots:
void handleBusMessage(const QGstreamerMessage &message);
void handleViewfinderChange();
private:
bool setupCameraBin();
void setupCaptureResolution();
void updateVideoSourceCaps();
GstElement *buildVideoSrc();
static void updateBusyStatus(GObject *o, GParamSpec *p, gpointer d);
QUrl m_sink;
QUrl m_actualSink;
bool m_recordingActive;
QString m_captureDevice;
QCamera::State m_state;
QCamera::State m_pendingState;
QString m_inputDevice;
bool m_pendingResolutionUpdate;
bool m_muted;
bool m_busy;
QCamera::CaptureMode m_captureMode;
QMap<QByteArray, QVariant> m_metaData;
QGstreamerElementFactory *m_audioInputFactory;
QGstreamerElementFactory *m_videoInputFactory;
QObject *m_viewfinder;
QGstreamerVideoRendererInterface *m_viewfinderInterface;
CameraBinAudioEncoder *m_audioEncodeControl;
CameraBinVideoEncoder *m_videoEncodeControl;
CameraBinImageEncoder *m_imageEncodeControl;
CameraBinRecorder *m_recorderControl;
CameraBinContainer *m_mediaContainerControl;
CameraBinExposure *m_cameraExposureControl;
CameraBinFlash *m_cameraFlashControl;
CameraBinFocus *m_cameraFocusControl;
CameraBinImageProcessing *m_imageProcessingControl;
CameraBinLocks *m_cameraLocksControl;
CameraBinCaptureDestination *m_captureDestinationControl;
CameraBinCaptureBufferFormat *m_captureBufferFormatControl;
QGstreamerBusHelper *m_busHelper;
GstBus* m_bus;
GstElement *m_pipeline;
GstElement *m_videoSrc;
GstElement *m_viewfinderElement;
bool m_viewfinderHasChanged;
bool m_videoInputHasChanged;
GstCaps *m_sourceCaps;
GstElement *m_audioSrc;
GstElement *m_audioConvert;
GstElement *m_capsFilter;
GstElement *m_fileSink;
GstElement *m_audioEncoder;
GstElement *m_muxer;
public:
QString m_imageFileName;
int m_requestId;
};
#endif // CAMERABINCAPTURESESSION_MAEMO_H

View File

@@ -0,0 +1,346 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "camerabinvideoencoder.h"
#include "camerabinsession.h"
#include "camerabincontainer.h"
#include <QtCore/qdebug.h>
CameraBinVideoEncoder::CameraBinVideoEncoder(CameraBinSession *session)
:QVideoEncoderControl(session), m_session(session)
{
QList<QByteArray> codecCandidates;
#if defined(Q_WS_MAEMO_5)
codecCandidates << "video/mpeg4" << "video/h264" << "video/h263" << "video/theora"
<< "video/mpeg2" << "video/mpeg1" << "video/mjpeg" << "video/VP8" << "video/h261";
m_elementNames["video/h264"] = "dsph264enc";
m_elementNames["video/mpeg4"] = "dspmp4venc";
m_elementNames["video/h263"] = "dsph263enc";
m_elementNames["video/theora"] = "theoraenc";
m_elementNames["video/mpeg2"] = "ffenc_mpeg2video";
m_elementNames["video/mpeg1"] = "ffenc_mpeg1video";
m_elementNames["video/mjpeg"] = "ffenc_mjpeg";
m_elementNames["video/VP8"] = "vp8enc";
m_elementNames["video/h261"] = "ffenc_h261";
m_codecOptions["video/mpeg4"] = QStringList() << "mode" << "keyframe-interval";
#elif defined(Q_WS_MAEMO_6)
codecCandidates << "video/mpeg4" << "video/h264" << "video/h263";
m_elementNames["video/h264"] = "dsph264enc";
m_elementNames["video/mpeg4"] = "dsphdmp4venc";
m_elementNames["video/h263"] = "dsph263enc";
QStringList options = QStringList() << "mode" << "keyframe-interval" << "max-bitrate" << "intra-refresh";
m_codecOptions["video/h264"] = options;
m_codecOptions["video/mpeg4"] = options;
m_codecOptions["video/h263"] = options;
#else
codecCandidates << "video/h264" << "video/xvid" << "video/mpeg4"
<< "video/mpeg1" << "video/mpeg2" << "video/theora"
<< "video/VP8" << "video/h261" << "video/mjpeg";
m_elementNames["video/h264"] = "x264enc";
m_elementNames["video/xvid"] = "xvidenc";
m_elementNames["video/mpeg4"] = "ffenc_mpeg4";
m_elementNames["video/mpeg1"] = "ffenc_mpeg1video";
m_elementNames["video/mpeg2"] = "ffenc_mpeg2video";
m_elementNames["video/theora"] = "theoraenc";
m_elementNames["video/mjpeg"] = "ffenc_mjpeg";
m_elementNames["video/VP8"] = "vp8enc";
m_elementNames["video/h261"] = "ffenc_h261";
m_codecOptions["video/h264"] = QStringList() << "quantizer";
m_codecOptions["video/xvid"] = QStringList() << "quantizer" << "profile";
m_codecOptions["video/mpeg4"] = QStringList() << "quantizer";
m_codecOptions["video/mpeg1"] = QStringList() << "quantizer";
m_codecOptions["video/mpeg2"] = QStringList() << "quantizer";
m_codecOptions["video/theora"] = QStringList();
#endif
foreach( const QByteArray& codecName, codecCandidates ) {
QByteArray elementName = m_elementNames[codecName];
GstElementFactory *factory = gst_element_factory_find(elementName.constData());
if (factory) {
m_codecs.append(codecName);
const gchar *descr = gst_element_factory_get_description(factory);
m_codecDescriptions.insert(codecName, QString::fromUtf8(descr));
m_streamTypes.insert(codecName,
CameraBinContainer::supportedStreamTypes(factory, GST_PAD_SRC));
gst_object_unref(GST_OBJECT(factory));
}
}
}
CameraBinVideoEncoder::~CameraBinVideoEncoder()
{
}
QList<QSize> CameraBinVideoEncoder::supportedResolutions(const QVideoEncoderSettings &settings, bool *continuous) const
{
if (continuous)
*continuous = false;
QPair<int,int> rate = rateAsRational(settings.frameRate());
//select the closest supported rational rate to settings.frameRate()
return m_session->supportedResolutions(rate, continuous, QCamera::CaptureVideo);
}
QList< qreal > CameraBinVideoEncoder::supportedFrameRates(const QVideoEncoderSettings &settings, bool *continuous) const
{
if (continuous)
*continuous = false;
QList< qreal > res;
QPair<int,int> rate;
foreach(rate, m_session->supportedFrameRates(settings.resolution(), continuous)) {
if (rate.second > 0)
res << qreal(rate.first)/rate.second;
}
return res;
}
QStringList CameraBinVideoEncoder::supportedVideoCodecs() const
{
return m_codecs;
}
QString CameraBinVideoEncoder::videoCodecDescription(const QString &codecName) const
{
return m_codecDescriptions.value(codecName);
}
QStringList CameraBinVideoEncoder::supportedEncodingOptions(const QString &codec) const
{
return m_codecOptions.value(codec);
}
QVariant CameraBinVideoEncoder::encodingOption(const QString &codec, const QString &name) const
{
return m_options[codec].value(name);
}
void CameraBinVideoEncoder::setEncodingOption(
const QString &codec, const QString &name, const QVariant &value)
{
m_options[codec][name] = value;
}
QVideoEncoderSettings CameraBinVideoEncoder::videoSettings() const
{
return m_videoSettings;
}
void CameraBinVideoEncoder::setVideoSettings(const QVideoEncoderSettings &settings)
{
m_videoSettings = settings;
m_userSettings = settings;
emit settingsChanged();
}
void CameraBinVideoEncoder::setActualVideoSettings(const QVideoEncoderSettings &settings)
{
m_videoSettings = settings;
}
void CameraBinVideoEncoder::resetActualSettings()
{
m_videoSettings = m_userSettings;
}
GstElement *CameraBinVideoEncoder::createEncoder()
{
QString codec = m_videoSettings.codec();
QByteArray elementName = m_elementNames.value(codec);
GstElement *encoderElement = gst_element_factory_make( elementName.constData(), "video-encoder");
if (encoderElement) {
if (m_videoSettings.encodingMode() == QtMultimediaKit::ConstantQualityEncoding) {
QtMultimediaKit::EncodingQuality qualityValue = m_videoSettings.quality();
if (elementName == "x264enc") {
//constant quantizer mode
g_object_set(G_OBJECT(encoderElement), "pass", 4, NULL);
int qualityTable[] = {
50, //VeryLow
35, //Low
21, //Normal
15, //High
8 //VeryHigh
};
g_object_set(G_OBJECT(encoderElement), "quantizer", qualityTable[qualityValue], NULL);
} else if (elementName == "xvidenc") {
//constant quantizer mode
g_object_set(G_OBJECT(encoderElement), "pass", 3, NULL);
int qualityTable[] = {
32, //VeryLow
12, //Low
5, //Normal
3, //High
2 //VeryHigh
};
int quant = qualityTable[qualityValue];
g_object_set(G_OBJECT(encoderElement), "quantizer", quant, NULL);
} else if (elementName == "ffenc_mpeg4" ||
elementName == "ffenc_mpeg1video" ||
elementName == "ffenc_mpeg2video" ) {
//constant quantizer mode
g_object_set(G_OBJECT(encoderElement), "pass", 2, NULL);
//quant from 1 to 30, default ~3
double qualityTable[] = {
20, //VeryLow
8.0, //Low
3.0, //Normal
2.5, //High
2.0 //VeryHigh
};
double quant = qualityTable[qualityValue];
g_object_set(G_OBJECT(encoderElement), "quantizer", quant, NULL);
} else if (elementName == "theoraenc") {
int qualityTable[] = {
8, //VeryLow
16, //Low
32, //Normal
45, //High
60 //VeryHigh
};
//quality from 0 to 63
int quality = qualityTable[qualityValue];
g_object_set(G_OBJECT(encoderElement), "quality", quality, NULL);
} else if (elementName == "dsph264enc" ||
elementName == "dspmp4venc" ||
elementName == "dsphdmp4venc" ||
elementName == "dsph263enc") {
//only bitrate parameter is supported
int qualityTable[] = {
1000000, //VeryLow
2000000, //Low
4000000, //Normal
8000000, //High
16000000 //VeryHigh
};
int bitrate = qualityTable[qualityValue];
g_object_set(G_OBJECT(encoderElement), "bitrate", bitrate, NULL);
}
} else {
int bitrate = m_videoSettings.bitRate();
if (bitrate > 0) {
g_object_set(G_OBJECT(encoderElement), "bitrate", bitrate, NULL);
}
}
QMap<QString,QVariant> options = m_options.value(codec);
QMapIterator<QString,QVariant> it(options);
while (it.hasNext()) {
it.next();
QString option = it.key();
QVariant value = it.value();
switch (value.type()) {
case QVariant::Int:
g_object_set(G_OBJECT(encoderElement), option.toAscii(), value.toInt(), NULL);
break;
case QVariant::Bool:
g_object_set(G_OBJECT(encoderElement), option.toAscii(), value.toBool(), NULL);
break;
case QVariant::Double:
g_object_set(G_OBJECT(encoderElement), option.toAscii(), value.toDouble(), NULL);
break;
case QVariant::String:
g_object_set(G_OBJECT(encoderElement), option.toAscii(), value.toString().toUtf8().constData(), NULL);
break;
default:
qWarning() << "unsupported option type:" << option << value;
break;
}
}
}
return encoderElement;
}
QPair<int,int> CameraBinVideoEncoder::rateAsRational(qreal frameRate) const
{
if (frameRate > 0.001) {
//convert to rational number
QList<int> denumCandidates;
denumCandidates << 1 << 2 << 3 << 5 << 10 << 25 << 30 << 50 << 100 << 1001 << 1000;
qreal error = 1.0;
int num = 1;
int denum = 1;
foreach (int curDenum, denumCandidates) {
int curNum = qRound(frameRate*curDenum);
qreal curError = qAbs(qreal(curNum)/curDenum - frameRate);
if (curError < error) {
error = curError;
num = curNum;
denum = curDenum;
}
if (curError < 1e-8)
break;
}
return QPair<int,int>(num,denum);
}
return QPair<int,int>();
}
QSet<QString> CameraBinVideoEncoder::supportedStreamTypes(const QString &codecName) const
{
return m_streamTypes.value(codecName);
}

View File

@@ -0,0 +1,106 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef CAMERABINVIDEOENCODE_H
#define CAMERABINVIDEOENCODE_H
#include <qvideoencodercontrol.h>
class CameraBinSession;
#include <QtCore/qstringlist.h>
#include <QtCore/qmap.h>
#include <QtCore/qset.h>
#include <gst/gst.h>
QT_USE_NAMESPACE
class CameraBinVideoEncoder : public QVideoEncoderControl
{
Q_OBJECT
public:
CameraBinVideoEncoder(CameraBinSession *session);
virtual ~CameraBinVideoEncoder();
QList<QSize> supportedResolutions(const QVideoEncoderSettings &settings = QVideoEncoderSettings(),
bool *continuous = 0) const;
QList< qreal > supportedFrameRates(const QVideoEncoderSettings &settings = QVideoEncoderSettings(),
bool *continuous = 0) const;
QPair<int,int> rateAsRational(qreal) const;
QStringList supportedVideoCodecs() const;
QString videoCodecDescription(const QString &codecName) const;
QVideoEncoderSettings videoSettings() const;
void setVideoSettings(const QVideoEncoderSettings &settings);
QStringList supportedEncodingOptions(const QString &codec) const;
QVariant encodingOption(const QString &codec, const QString &name) const;
void setEncodingOption(const QString &codec, const QString &name, const QVariant &value);
GstElement *createEncoder();
QSet<QString> supportedStreamTypes(const QString &codecName) const;
void setActualVideoSettings(const QVideoEncoderSettings&);
void resetActualSettings();
Q_SIGNALS:
void settingsChanged();
private:
CameraBinSession *m_session;
QStringList m_codecs;
QMap<QString,QString> m_codecDescriptions;
QMap<QString,QByteArray> m_elementNames;
QMap<QString,QStringList> m_codecOptions;
QVideoEncoderSettings m_videoSettings; // backend selected settings, using m_userSettings
QVideoEncoderSettings m_userSettings;
QMap<QString, QMap<QString, QVariant> > m_options;
QMap<QString, QSet<QString> > m_streamTypes;
};
#endif