diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2011-11-09 20:42:00 +0100 |
---|---|---|
committer | Michael Goddard <michael.goddard@nokia.com> | 2011-11-10 04:15:38 +0100 |
commit | 1d76e399c5d9277895786c6edc2cec76f99d0531 (patch) | |
tree | f56640988d767202cc8f449ff78ad26ff739d314 /src/plugins | |
parent | 1e542df82fbcc4e3a8f75537af204f83827a4587 (diff) |
Change-Id: Id6de29b7c1e96aed16be8251195c744f68a2d46b
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
Diffstat (limited to 'src/plugins')
268 files changed, 0 insertions, 50303 deletions
diff --git a/src/plugins/audiocapture/audiocapture.pro b/src/plugins/audiocapture/audiocapture.pro deleted file mode 100644 index 8b30b2a..0000000 --- a/src/plugins/audiocapture/audiocapture.pro +++ /dev/null @@ -1,28 +0,0 @@ -load(qt_module) - -TARGET = qtmedia_audioengine -QT += multimedia-private -PLUGIN_TYPE=mediaservice - -load(qt_plugin) -DESTDIR = $$QT.multimedia.plugins/$${PLUGIN_TYPE} - -# Input -HEADERS += audioencodercontrol.h \ - audiocontainercontrol.h \ - audiomediarecordercontrol.h \ - audioendpointselector.h \ - audiocaptureservice.h \ - audiocaptureserviceplugin.h \ - audiocapturesession.h - -SOURCES += audioencodercontrol.cpp \ - audiocontainercontrol.cpp \ - audiomediarecordercontrol.cpp \ - audioendpointselector.cpp \ - audiocaptureservice.cpp \ - audiocaptureserviceplugin.cpp \ - audiocapturesession.cpp - -target.path += $$[QT_INSTALL_PLUGINS]/$${PLUGIN_TYPE} -INSTALLS += target diff --git a/src/plugins/audiocapture/audiocaptureservice.cpp b/src/plugins/audiocapture/audiocaptureservice.cpp deleted file mode 100644 index 6dff4c5..0000000 --- a/src/plugins/audiocapture/audiocaptureservice.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "audiocaptureservice.h" -#include "audiocapturesession.h" -#include "audioendpointselector.h" -#include "audioencodercontrol.h" -#include "audiocontainercontrol.h" -#include "audiomediarecordercontrol.h" - -AudioCaptureService::AudioCaptureService(QObject *parent): - QMediaService(parent) -{ - m_session = new AudioCaptureSession(this); - m_encoderControl = new AudioEncoderControl(m_session); - m_containerControl = new AudioContainerControl(m_session); - m_mediaControl = new AudioMediaRecorderControl(m_session); - m_endpointSelector = new AudioEndpointSelector(m_session); -} - -AudioCaptureService::~AudioCaptureService() -{ - delete m_encoderControl; - delete m_containerControl; - delete m_endpointSelector; - delete m_mediaControl; - delete m_session; -} - -QMediaControl *AudioCaptureService::requestControl(const char *name) -{ - if (qstrcmp(name,QMediaRecorderControl_iid) == 0) - return m_mediaControl; - - if (qstrcmp(name,QAudioEncoderControl_iid) == 0) - return m_encoderControl; - - if (qstrcmp(name,QAudioEndpointSelector_iid) == 0) - return m_endpointSelector; - - if (qstrcmp(name,QMediaContainerControl_iid) == 0) - return m_containerControl; - - return 0; -} - -void AudioCaptureService::releaseControl(QMediaControl *control) -{ - Q_UNUSED(control) -} - - diff --git a/src/plugins/audiocapture/audiocaptureservice.h b/src/plugins/audiocapture/audiocaptureservice.h deleted file mode 100644 index 26a39d4..0000000 --- a/src/plugins/audiocapture/audiocaptureservice.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef AUDIOCAPTURESERVICE_H -#define AUDIOCAPTURESERVICE_H - -#include <QtCore/qobject.h> - -#include "qmediaservice.h" - -class AudioCaptureSession; -class AudioEncoderControl; -class AudioContainerControl; -class AudioMediaRecorderControl; -class AudioEndpointSelector; - -QT_USE_NAMESPACE - -class AudioCaptureService : public QMediaService -{ - Q_OBJECT -public: - AudioCaptureService(QObject *parent = 0); - ~AudioCaptureService(); - - QMediaControl *requestControl(const char *interface); - void releaseControl(QMediaControl *control); -private: - AudioCaptureSession *m_session; - AudioEncoderControl *m_encoderControl; - AudioContainerControl *m_containerControl; - AudioEndpointSelector *m_endpointSelector; - AudioMediaRecorderControl *m_mediaControl; -}; - -#endif diff --git a/src/plugins/audiocapture/audiocaptureserviceplugin.cpp b/src/plugins/audiocapture/audiocaptureserviceplugin.cpp deleted file mode 100644 index cfa2ab9..0000000 --- a/src/plugins/audiocapture/audiocaptureserviceplugin.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qstring.h> - -#include "audiocaptureserviceplugin.h" -#include "audiocaptureservice.h" - -#include "qmediaserviceprovider.h" - - -QStringList AudioCaptureServicePlugin::keys() const -{ - return QStringList() << QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE); -} - -QMediaService* AudioCaptureServicePlugin::create(QString const& key) -{ - if (key == QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE)) - return new AudioCaptureService; - - return 0; -} - -void AudioCaptureServicePlugin::release(QMediaService *service) -{ - delete service; -} - -Q_EXPORT_PLUGIN2(qtmedia_audioengine, AudioCaptureServicePlugin); - diff --git a/src/plugins/audiocapture/audiocaptureserviceplugin.h b/src/plugins/audiocapture/audiocaptureserviceplugin.h deleted file mode 100644 index 16b4643..0000000 --- a/src/plugins/audiocapture/audiocaptureserviceplugin.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef AUDIOCAPTURESERVICEPLUGIN_H -#define AUDIOCAPTURESERVICEPLUGIN_H - -#include "qmediaserviceproviderplugin.h" - -QT_USE_NAMESPACE - -class AudioCaptureServicePlugin : public QMediaServiceProviderPlugin -{ - Q_OBJECT - -public: - QStringList keys() const; - QMediaService* create(QString const& key); - void release(QMediaService *service); -}; - -#endif // AUDIOCAPTURESERVICEPLUGIN_H diff --git a/src/plugins/audiocapture/audiocapturesession.cpp b/src/plugins/audiocapture/audiocapturesession.cpp deleted file mode 100644 index 82d330f..0000000 --- a/src/plugins/audiocapture/audiocapturesession.cpp +++ /dev/null @@ -1,358 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qdebug.h> -#include <QtCore/qurl.h> -#include <QtCore/qdir.h> -#include <qaudiodeviceinfo.h> - -#include "qmediarecorder.h" - -#include "audiocapturesession.h" - -AudioCaptureSession::AudioCaptureSession(QObject *parent): - QObject(parent) -{ - m_deviceInfo = new QAudioDeviceInfo(QAudioDeviceInfo::defaultInputDevice()); - m_audioInput = 0; - m_position = 0; - m_state = QMediaRecorder::StoppedState; - - m_format.setFrequency(8000); - m_format.setChannels(1); - m_format.setSampleSize(8); - m_format.setSampleType(QAudioFormat::UnSignedInt); - m_format.setCodec("audio/pcm"); - wavFile = true; -} - -AudioCaptureSession::~AudioCaptureSession() -{ - stop(); - - if(m_audioInput) - delete m_audioInput; -} - -QAudioDeviceInfo* AudioCaptureSession::deviceInfo() const -{ - return m_deviceInfo; -} - -QAudioFormat AudioCaptureSession::format() const -{ - return m_format; -} - -bool AudioCaptureSession::isFormatSupported(const QAudioFormat &format) const -{ - if(m_deviceInfo) { - if(format.codec().contains(QLatin1String("audio/x-wav"))) { - QAudioFormat fmt = format; - fmt.setCodec("audio/pcm"); - return m_deviceInfo->isFormatSupported(fmt); - } else - return m_deviceInfo->isFormatSupported(format); - } - return false; -} - -bool AudioCaptureSession::setFormat(const QAudioFormat &format) -{ - if(m_deviceInfo) { - - QAudioFormat fmt = format; - - if(m_deviceInfo->isFormatSupported(fmt)) { - m_format = fmt; - if(m_audioInput) delete m_audioInput; - m_audioInput = 0; - QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); - for(int i=0;i<devices.size();i++) { - if(qstrcmp(m_deviceInfo->deviceName().toLocal8Bit().constData(), - devices.at(i).deviceName().toLocal8Bit().constData()) == 0) { - m_audioInput = new QAudioInput(devices.at(i),m_format); - connect(m_audioInput,SIGNAL(stateChanged(QAudio::State)),this,SLOT(stateChanged(QAudio::State))); - connect(m_audioInput,SIGNAL(notify()),this,SLOT(notify())); - break; - } - } - } else { - m_format = m_deviceInfo->preferredFormat(); - qWarning()<<"failed to setFormat using preferred..."; - } - } - return false; -} - -QStringList AudioCaptureSession::supportedContainers() const -{ - QStringList list; - if(m_deviceInfo) { - if (m_deviceInfo->supportedCodecs().size() > 0) { - list << "audio/x-wav"; - list << "audio/pcm"; - } - } - return list; -} - -QString AudioCaptureSession::containerDescription(const QString &formatMimeType) const -{ - if(m_deviceInfo) { - if (formatMimeType.contains(QLatin1String("audio/pcm"))) - return tr("RAW file format"); - if (formatMimeType.contains(QLatin1String("audio/x-wav"))) - return tr("WAV file format"); - } - return QString(); -} - -void AudioCaptureSession::setContainerMimeType(const QString &formatMimeType) -{ - if (!formatMimeType.contains(QLatin1String("audio/x-wav")) && - !formatMimeType.contains(QLatin1String("audio/pcm")) && - !formatMimeType.isEmpty()) - return; - - if(m_deviceInfo) { - if (!m_deviceInfo->supportedCodecs().contains(QLatin1String("audio/pcm"))) - return; - - if (formatMimeType.isEmpty() || formatMimeType.contains(QLatin1String("audio/x-wav"))) { - wavFile = true; - m_format.setCodec("audio/pcm"); - } else { - wavFile = false; - m_format.setCodec(formatMimeType); - } - } -} - -QString AudioCaptureSession::containerMimeType() const -{ - if(wavFile) - return QString("audio/x-wav"); - - return QString("audio/pcm"); -} - -QUrl AudioCaptureSession::outputLocation() const -{ - return m_actualSink; -} - -bool AudioCaptureSession::setOutputLocation(const QUrl& sink) -{ - m_sink = m_actualSink = sink; - return true; -} - -qint64 AudioCaptureSession::position() const -{ - return m_position; -} - -int AudioCaptureSession::state() const -{ - return int(m_state); -} - -QDir AudioCaptureSession::defaultDir() const -{ - QStringList dirCandidates; - -#if defined(Q_WS_MAEMO_6) - dirCandidates << QLatin1String("/home/user/MyDocs"); -#endif - - dirCandidates << QDir::home().filePath("Documents"); - dirCandidates << QDir::home().filePath("My Documents"); - dirCandidates << QDir::homePath(); - dirCandidates << QDir::currentPath(); - dirCandidates << QDir::tempPath(); - - foreach (const QString &path, dirCandidates) { - QDir dir(path); - if (dir.exists() && QFileInfo(path).isWritable()) - return dir; - } - - return QDir(); -} - -QString AudioCaptureSession::generateFileName(const QDir &dir, const QString &ext) const -{ - - int lastClip = 0; - foreach(QString fileName, dir.entryList(QStringList() << QString("clip_*.%1").arg(ext))) { - int imgNumber = fileName.mid(5, fileName.size()-6-ext.length()).toInt(); - lastClip = qMax(lastClip, imgNumber); - } - - QString name = QString("clip_%1.%2").arg(lastClip+1, - 4, //fieldWidth - 10, - QLatin1Char('0')).arg(ext); - - return dir.absoluteFilePath(name); -} - -void AudioCaptureSession::record() -{ - if(!m_audioInput) { - setFormat(m_format); - } - - m_actualSink = m_sink; - - if (m_actualSink.isEmpty()) { - QString ext = wavFile ? QLatin1String("wav") : QLatin1String("raw"); - m_actualSink = generateFileName(defaultDir(), ext); - } - - if(m_actualSink.toLocalFile().length() > 0) - file.setFileName(m_actualSink.toLocalFile()); - else - file.setFileName(m_actualSink.toString()); - - if(m_audioInput) { - if(m_state == QMediaRecorder::StoppedState) { - if(file.open(QIODevice::WriteOnly)) { - memset(&header,0,sizeof(CombinedHeader)); - memcpy(header.riff.descriptor.id,"RIFF",4); - header.riff.descriptor.size = 0xFFFFFFFF; // This should be updated on stop(), filesize-8 - memcpy(header.riff.type,"WAVE",4); - memcpy(header.wave.descriptor.id,"fmt ",4); - header.wave.descriptor.size = 16; - header.wave.audioFormat = 1; // for PCM data - header.wave.numChannels = m_format.channels(); - header.wave.sampleRate = m_format.frequency(); - header.wave.byteRate = m_format.frequency()*m_format.channels()*m_format.sampleSize()/8; - header.wave.blockAlign = m_format.channels()*m_format.sampleSize()/8; - header.wave.bitsPerSample = m_format.sampleSize(); - memcpy(header.data.descriptor.id,"data",4); - header.data.descriptor.size = 0xFFFFFFFF; // This should be updated on stop(),samples*channels*sampleSize/8 - if (wavFile) - file.write((char*)&header,sizeof(CombinedHeader)); - - m_audioInput->start(qobject_cast<QIODevice*>(&file)); - } else { - emit error(1,QString("can't open source, failed")); - m_state = QMediaRecorder::StoppedState; - emit stateChanged(m_state); - } - } - } - - m_state = QMediaRecorder::RecordingState; -} - -void AudioCaptureSession::pause() -{ - if(m_audioInput) - m_audioInput->stop(); - - m_state = QMediaRecorder::PausedState; -} - -void AudioCaptureSession::stop() -{ - if(m_audioInput) { - m_audioInput->stop(); - file.close(); - if (wavFile) { - qint32 fileSize = file.size()-8; - file.open(QIODevice::ReadWrite | QIODevice::Unbuffered); - file.read((char*)&header,sizeof(CombinedHeader)); - header.riff.descriptor.size = fileSize; // filesize-8 - header.data.descriptor.size = fileSize-44; // samples*channels*sampleSize/8 - file.seek(0); - file.write((char*)&header,sizeof(CombinedHeader)); - file.close(); - } - m_position = 0; - } - m_state = QMediaRecorder::StoppedState; -} - -void AudioCaptureSession::stateChanged(QAudio::State state) -{ - switch(state) { - case QAudio::ActiveState: - emit stateChanged(QMediaRecorder::RecordingState); - break; - default: - if(!((m_state == QMediaRecorder::PausedState)||(m_state == QMediaRecorder::StoppedState))) - m_state = QMediaRecorder::StoppedState; - - emit stateChanged(m_state); - break; - } -} - -void AudioCaptureSession::notify() -{ - m_position += m_audioInput->notifyInterval(); - emit positionChanged(m_position); -} - -void AudioCaptureSession::setCaptureDevice(const QString &deviceName) -{ - m_captureDevice = deviceName; - if(m_deviceInfo) - delete m_deviceInfo; - - m_deviceInfo = 0; - - QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); - for(int i = 0; i < devices.size(); i++) { - if(qstrcmp(m_captureDevice.toLocal8Bit().constData(), - devices.at(i).deviceName().toLocal8Bit().constData())==0){ - m_deviceInfo = new QAudioDeviceInfo(QAudioDeviceInfo::defaultInputDevice()); - return; - } - } - m_deviceInfo = new QAudioDeviceInfo(QAudioDeviceInfo::defaultInputDevice()); -} - - - diff --git a/src/plugins/audiocapture/audiocapturesession.h b/src/plugins/audiocapture/audiocapturesession.h deleted file mode 100644 index 8b0636f..0000000 --- a/src/plugins/audiocapture/audiocapturesession.h +++ /dev/null @@ -1,152 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef AUDIOCAPTURESESSION_H -#define AUDIOCAPTURESESSION_H - -#include <QFile> -#include <QUrl> -#include <QDir> - -#include "audioencodercontrol.h" -#include "audioendpointselector.h" -#include "audiomediarecordercontrol.h" - -#include <qaudioformat.h> -#include <qaudioinput.h> -#include <qaudiodeviceinfo.h> - -QT_USE_NAMESPACE - -class AudioCaptureSession : public QObject -{ - Q_OBJECT - -public: - AudioCaptureSession(QObject *parent = 0); - ~AudioCaptureSession(); - - QAudioFormat format() const; - QAudioDeviceInfo* deviceInfo() const; - bool isFormatSupported(const QAudioFormat &format) const; - bool setFormat(const QAudioFormat &format); - QStringList supportedContainers() const; - QString containerMimeType() const; - void setContainerMimeType(const QString &formatMimeType); - QString containerDescription(const QString &formatMimeType) const; - - QUrl outputLocation() const; - bool setOutputLocation(const QUrl& sink); - qint64 position() const; - int state() const; - void record(); - void pause(); - void stop(); - -public slots: - void setCaptureDevice(const QString &deviceName); - -signals: - void stateChanged(QMediaRecorder::State state); - void positionChanged(qint64 position); - void error(int error, const QString &errorString); - -private slots: - void stateChanged(QAudio::State state); - void notify(); - -private: - QDir defaultDir() const; - QString generateFileName(const QDir &dir, const QString &ext) const; - - QFile file; - QString m_captureDevice; - QUrl m_sink; - QUrl m_actualSink; - QMediaRecorder::State m_state; - QAudioInput *m_audioInput; - QAudioDeviceInfo *m_deviceInfo; - QAudioFormat m_format; - qint64 m_position; - bool wavFile; - - // WAV header stuff - - struct chunk - { - char id[4]; - quint32 size; - }; - - struct RIFFHeader - { - chunk descriptor; - char type[4]; - }; - - struct WAVEHeader - { - chunk descriptor; - quint16 audioFormat; // PCM = 1 - quint16 numChannels; - quint32 sampleRate; - quint32 byteRate; - quint16 blockAlign; - quint16 bitsPerSample; - }; - - struct DATAHeader - { - chunk descriptor; -// quint8 data[]; - }; - - struct CombinedHeader - { - RIFFHeader riff; - WAVEHeader wave; - DATAHeader data; - }; - - CombinedHeader header; -}; - -#endif diff --git a/src/plugins/audiocapture/audiocontainercontrol.cpp b/src/plugins/audiocapture/audiocontainercontrol.cpp deleted file mode 100644 index b5c84d2..0000000 --- a/src/plugins/audiocapture/audiocontainercontrol.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "audiocontainercontrol.h" -#include "audiocapturesession.h" - -AudioContainerControl::AudioContainerControl(QObject *parent) - :QMediaContainerControl(parent) -{ - m_session = qobject_cast<AudioCaptureSession*>(parent); -} - -AudioContainerControl::~AudioContainerControl() -{ -} - -QStringList AudioContainerControl::supportedContainers() const -{ - return m_session->supportedContainers(); -} - -QString AudioContainerControl::containerMimeType() const -{ - return m_session->containerMimeType(); -} - -void AudioContainerControl::setContainerMimeType(const QString &formatMimeType) -{ - m_session->setContainerMimeType(formatMimeType); -} - -QString AudioContainerControl::containerDescription(const QString &formatMimeType) const -{ - return m_session->containerDescription(formatMimeType); -} - diff --git a/src/plugins/audiocapture/audiocontainercontrol.h b/src/plugins/audiocapture/audiocontainercontrol.h deleted file mode 100644 index 793e7f8..0000000 --- a/src/plugins/audiocapture/audiocontainercontrol.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef AUDIOCONTAINERCONTROL_H -#define AUDIOCONTAINERCONTROL_H - -#include "qmediacontainercontrol.h" - -#include <QtCore/qstringlist.h> -#include <QtCore/qmap.h> - -class AudioCaptureSession; - -QT_USE_NAMESPACE - -class AudioContainerControl : public QMediaContainerControl -{ - Q_OBJECT -public: - AudioContainerControl(QObject *parent); - virtual ~AudioContainerControl(); - - QStringList supportedContainers() const; - QString containerMimeType() const; - void setContainerMimeType(const QString &formatMimeType); - QString containerDescription(const QString &formatMimeType) const; - -private: - AudioCaptureSession* m_session; -}; - -#endif diff --git a/src/plugins/audiocapture/audioencodercontrol.cpp b/src/plugins/audiocapture/audioencodercontrol.cpp deleted file mode 100644 index ce2ab42..0000000 --- a/src/plugins/audiocapture/audioencodercontrol.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "audioencodercontrol.h" -#include "audiocapturesession.h" - -#include <qaudioformat.h> - -#include <QtCore/qdebug.h> - -AudioEncoderControl::AudioEncoderControl(QObject *parent) - :QAudioEncoderControl(parent) -{ - m_session = qobject_cast<AudioCaptureSession*>(parent); - - QT_PREPEND_NAMESPACE(QAudioFormat) fmt; - fmt.setSampleSize(8); - fmt.setChannels(1); - fmt.setFrequency(8000); - fmt.setSampleType(QT_PREPEND_NAMESPACE(QAudioFormat)::SignedInt); - fmt.setCodec("audio/pcm"); - fmt.setByteOrder(QAudioFormat::LittleEndian); - m_session->setFormat(fmt); - - m_settings.setEncodingMode(QtMultimedia::ConstantQualityEncoding); - m_settings.setCodec("audio/pcm"); - m_settings.setBitRate(8000); - m_settings.setChannelCount(1); - m_settings.setSampleRate(8000); - m_settings.setQuality(QtMultimedia::LowQuality); -} - -AudioEncoderControl::~AudioEncoderControl() -{ -} - -QStringList AudioEncoderControl::supportedAudioCodecs() const -{ - QStringList list; - if (m_session->supportedContainers().size() > 0) - list.append("audio/pcm"); - - return list; -} - -QString AudioEncoderControl::codecDescription(const QString &codecName) const -{ - if (codecName.contains(QLatin1String("audio/pcm"))) - return tr("PCM audio data"); - - return QString(); -} - -QStringList AudioEncoderControl::supportedEncodingOptions(const QString &codec) const -{ - Q_UNUSED(codec) - - QStringList list; - return list; -} - -QVariant AudioEncoderControl::encodingOption(const QString &codec, const QString &name) const -{ - Q_UNUSED(codec) - Q_UNUSED(name) - - return QVariant(); -} - -void AudioEncoderControl::setEncodingOption( - const QString &codec, const QString &name, const QVariant &value) -{ - Q_UNUSED(value) - Q_UNUSED(codec) - Q_UNUSED(name) -} - -QList<int> AudioEncoderControl::supportedSampleRates(const QAudioEncoderSettings &, bool *continuous) const -{ - if (continuous) - *continuous = false; - - return m_session->deviceInfo()->supportedFrequencies(); -} - -QAudioEncoderSettings AudioEncoderControl::audioSettings() const -{ - return m_settings; -} - -void AudioEncoderControl::setAudioSettings(const QAudioEncoderSettings &settings) -{ - QAudioFormat fmt = m_session->format(); - - if (settings.encodingMode() == QtMultimedia::ConstantQualityEncoding) { - if (settings.quality() == QtMultimedia::LowQuality) { - fmt.setSampleSize(8); - fmt.setChannels(1); - fmt.setFrequency(8000); - fmt.setSampleType(QAudioFormat::UnSignedInt); - - } else if (settings.quality() == QtMultimedia::NormalQuality) { - fmt.setSampleSize(16); - fmt.setChannels(1); - fmt.setFrequency(22050); - fmt.setSampleType(QAudioFormat::SignedInt); - - } else { - fmt.setSampleSize(16); - fmt.setChannels(1); - fmt.setFrequency(44100); - fmt.setSampleType(QAudioFormat::SignedInt); - } - - } else { - fmt.setChannels(settings.channelCount()); - fmt.setFrequency(settings.sampleRate()); - if (settings.sampleRate() == 8000 && settings.bitRate() == 8000) { - fmt.setSampleType(QAudioFormat::UnSignedInt); - fmt.setSampleSize(8); - } else { - fmt.setSampleSize(16); - fmt.setSampleType(QAudioFormat::SignedInt); - } - } - fmt.setCodec("audio/pcm"); - - m_session->setFormat(fmt); - m_settings = settings; -} diff --git a/src/plugins/audiocapture/audioencodercontrol.h b/src/plugins/audiocapture/audioencodercontrol.h deleted file mode 100644 index 25e86e7..0000000 --- a/src/plugins/audiocapture/audioencodercontrol.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef AUDIOENCODERCONTROL_H -#define AUDIOENCODERCONTROL_H - -#include "qaudioencodercontrol.h" - -#include <QtCore/qstringlist.h> -#include <QtCore/qmap.h> - -#include <qaudioformat.h> - -class AudioCaptureSession; - -QT_USE_NAMESPACE - -class AudioEncoderControl : public QAudioEncoderControl -{ - Q_OBJECT -public: - AudioEncoderControl(QObject *parent); - virtual ~AudioEncoderControl(); - - QStringList supportedAudioCodecs() const; - QString codecDescription(const QString &codecName) const; - QList<int> supportedSampleRates(const QAudioEncoderSettings &, bool *continuous = 0) const; - - QAudioEncoderSettings audioSettings() const; - void setAudioSettings(const QAudioEncoderSettings&); - - 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); - -private: - AudioCaptureSession* m_session; - QAudioEncoderSettings m_settings; -}; - -#endif diff --git a/src/plugins/audiocapture/audioendpointselector.cpp b/src/plugins/audiocapture/audioendpointselector.cpp deleted file mode 100644 index 9a20981..0000000 --- a/src/plugins/audiocapture/audioendpointselector.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "audiocapturesession.h" -#include "audioendpointselector.h" - -#include <qaudiodeviceinfo.h> - - -AudioEndpointSelector::AudioEndpointSelector(QObject *parent) - :QAudioEndpointSelector(parent) -{ - m_session = qobject_cast<AudioCaptureSession*>(parent); - - update(); - - m_audioInput = defaultEndpoint(); -} - -AudioEndpointSelector::~AudioEndpointSelector() -{ -} - -QList<QString> AudioEndpointSelector::availableEndpoints() const -{ - return m_names; -} - -QString AudioEndpointSelector::endpointDescription(const QString& name) const -{ - QString desc; - - for(int i = 0; i < m_names.count(); i++) { - if (m_names.at(i).compare(name) == 0) { - desc = m_names.at(i); - break; - } - } - return desc; -} - -QString AudioEndpointSelector::defaultEndpoint() const -{ - return QAudioDeviceInfo(QAudioDeviceInfo::defaultInputDevice()).deviceName(); -} - -QString AudioEndpointSelector::activeEndpoint() const -{ - return m_audioInput; -} - -void AudioEndpointSelector::setActiveEndpoint(const QString& name) -{ - if (m_audioInput.compare(name) != 0) { - m_audioInput = name; - m_session->setCaptureDevice(name); - emit activeEndpointChanged(name); - } -} - -void AudioEndpointSelector::update() -{ - m_names.clear(); - m_descriptions.clear(); - - QList<QAudioDeviceInfo> devices; - devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); - for(int i = 0; i < devices.size(); ++i) { - m_names.append(devices.at(i).deviceName()); - m_descriptions.append(devices.at(i).deviceName()); - } -} diff --git a/src/plugins/audiocapture/audioendpointselector.h b/src/plugins/audiocapture/audioendpointselector.h deleted file mode 100644 index b4dbe2a..0000000 --- a/src/plugins/audiocapture/audioendpointselector.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef AUDIOENDPOINTSELECTOR_H -#define AUDIOENDPOINTSELECTOR_H - -#include <QStringList> - -#include "qaudioendpointselector.h" - -class AudioCaptureSession; - -QT_USE_NAMESPACE - -class AudioEndpointSelector : public QAudioEndpointSelector -{ -Q_OBJECT -public: - AudioEndpointSelector(QObject *parent); - virtual ~AudioEndpointSelector(); - - QList<QString> availableEndpoints() const; - QString endpointDescription(const QString& name) const; - QString defaultEndpoint() const; - QString activeEndpoint() const; - -public Q_SLOTS: - void setActiveEndpoint(const QString& name); - -private: - void update(); - - QString m_audioInput; - QList<QString> m_names; - QList<QString> m_descriptions; - AudioCaptureSession* m_session; -}; - -#endif // AUDIOENDPOINTSELECTOR_H diff --git a/src/plugins/audiocapture/audiomediarecordercontrol.cpp b/src/plugins/audiocapture/audiomediarecordercontrol.cpp deleted file mode 100644 index 4778610..0000000 --- a/src/plugins/audiocapture/audiomediarecordercontrol.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "audiocapturesession.h" -#include "audiomediarecordercontrol.h" - -#include <QtCore/qdebug.h> - -AudioMediaRecorderControl::AudioMediaRecorderControl(QObject *parent) - :QMediaRecorderControl(parent) -{ - m_session = qobject_cast<AudioCaptureSession*>(parent); - connect(m_session,SIGNAL(positionChanged(qint64)),this,SIGNAL(durationChanged(qint64))); - connect(m_session,SIGNAL(stateChanged(QMediaRecorder::State)),this,SIGNAL(stateChanged(QMediaRecorder::State))); - connect(m_session,SIGNAL(error(int,QString)),this,SIGNAL(error(int,QString))); -} - -AudioMediaRecorderControl::~AudioMediaRecorderControl() -{ -} - -QUrl AudioMediaRecorderControl::outputLocation() const -{ - return m_session->outputLocation(); -} - -bool AudioMediaRecorderControl::setOutputLocation(const QUrl& sink) -{ - return m_session->setOutputLocation(sink); -} - -QMediaRecorder::State AudioMediaRecorderControl::state() const -{ - return (QMediaRecorder::State)m_session->state(); -} - -qint64 AudioMediaRecorderControl::duration() const -{ - return m_session->position(); -} - -void AudioMediaRecorderControl::record() -{ - m_session->record(); -} - -void AudioMediaRecorderControl::pause() -{ - m_session->stop(); -} - -void AudioMediaRecorderControl::stop() -{ - m_session->stop(); -} - -bool AudioMediaRecorderControl::isMuted() const -{ - return false; -} - -void AudioMediaRecorderControl::setMuted(bool) -{ -} diff --git a/src/plugins/audiocapture/audiomediarecordercontrol.h b/src/plugins/audiocapture/audiomediarecordercontrol.h deleted file mode 100644 index 603aaf2..0000000 --- a/src/plugins/audiocapture/audiomediarecordercontrol.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef AUDIOMEDIARECORDERCONTROL_H -#define AUDIOMEDIARECORDERCONTROL_H - -#include <QtCore/qobject.h> - -#include "qmediarecorder.h" -#include "qmediarecordercontrol.h" - -class AudioCaptureSession; - -QT_USE_NAMESPACE - -class AudioMediaRecorderControl : public QMediaRecorderControl -{ - Q_OBJECT -public: - AudioMediaRecorderControl(QObject *parent = 0); - ~AudioMediaRecorderControl(); - - QUrl outputLocation() const; - bool setOutputLocation(const QUrl &sink); - - QMediaRecorder::State state() const; - - qint64 duration() const; - - bool isMuted() const; - - void applySettings() {} - -public slots: - void record(); - void pause(); - void stop(); - void setMuted(bool); - -private: - AudioCaptureSession* m_session; -}; - -#endif diff --git a/src/plugins/directshow/camera/camera.pri b/src/plugins/directshow/camera/camera.pri deleted file mode 100644 index 42f5999..0000000 --- a/src/plugins/directshow/camera/camera.pri +++ /dev/null @@ -1,31 +0,0 @@ -INCLUDEPATH += $$PWD - -DEFINES += QMEDIA_DIRECTSHOW_CAMERA - -win32-g++: DEFINES += QT_NO_WMSDK - -win32: DEFINES += _CRT_SECURE_NO_WARNINGS - -HEADERS += \ - $$PWD/dscameraservice.h \ - $$PWD/dscameracontrol.h \ - $$PWD/dsvideorenderer.h \ - $$PWD/dsvideodevicecontrol.h \ - $$PWD/dsimagecapturecontrol.h \ - $$PWD/dscamerasession.h \ - $$PWD/dsvideowidgetcontrol.h \ - $$PWD/dscameraservice.h \ - $$PWD/directshowglobal.h - - -SOURCES += \ - $$PWD/dscameraservice.cpp \ - $$PWD/dscameracontrol.cpp \ - $$PWD/dsvideorenderer.cpp \ - $$PWD/dsvideodevicecontrol.cpp \ - $$PWD/dsimagecapturecontrol.cpp \ - $$PWD/dscamerasession.cpp \ - $$PWD/dsvideowidgetcontrol.cpp - -INCLUDEPATH += $(DXSDK_DIR)/include -LIBS += -lstrmiids -ldmoguids -luuid -lmsdmo -lole32 -loleaut32 diff --git a/src/plugins/directshow/camera/directshowglobal.h b/src/plugins/directshow/camera/directshowglobal.h deleted file mode 100644 index c595aba..0000000 --- a/src/plugins/directshow/camera/directshowglobal.h +++ /dev/null @@ -1,236 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DIRECTSHOWGLOBAL_H -#define DIRECTSHOWGLOBAL_H - -#include <QtCore/qglobal.h> - -#include <dshow.h> - -DEFINE_GUID(MEDIASUBTYPE_I420, - 0x30323449,0x0000,0x0010,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71); - -extern const GUID MEDIASUBTYPE_RGB24; -extern const GUID MEDIASUBTYPE_RGB32; -extern const GUID MEDIASUBTYPE_YUY2; -extern const GUID MEDIASUBTYPE_MJPG; -extern const GUID MEDIASUBTYPE_RGB555; -extern const GUID MEDIASUBTYPE_YVU9; -extern const GUID MEDIASUBTYPE_UYVY; -extern const GUID PIN_CATEGORY_CAPTURE; -extern const GUID PIN_CATEGORY_PREVIEW; - -extern const IID IID_IPropertyBag; -extern const IID IID_ISampleGrabber; -extern const IID IID_ICaptureGraphBuilder2; -extern const IID IID_IAMStreamConfig; - - -extern const CLSID CLSID_CVidCapClassManager; -extern const CLSID CLSID_VideoInputDeviceCategory; -extern const CLSID CLSID_SampleGrabber; -extern const CLSID CLSID_CaptureGraphBuilder2; - -#define SAFE_RELEASE(x) { if(x) x->Release(); x = NULL; } - -typedef struct IFileSinkFilter *LPFILESINKFILTER; -typedef struct IAMCopyCaptureFileProgress *LPAMCOPYCAPTUREFILEPROGRESS; - -#ifndef __ICaptureGraphBuilder2_INTERFACE_DEFINED__ -#define __ICaptureGraphBuilder2_INTERFACE_DEFINED__ -struct ICaptureGraphBuilder2 : public IUnknown -{ -public: - virtual HRESULT STDMETHODCALLTYPE SetFiltergraph( - /* [in] */ IGraphBuilder *pfg) = 0; - - virtual HRESULT STDMETHODCALLTYPE GetFiltergraph( - /* [out] */ IGraphBuilder **ppfg) = 0; - - virtual HRESULT STDMETHODCALLTYPE SetOutputFileName( - /* [in] */ const GUID *pType, - /* [in] */ LPCOLESTR lpstrFile, - /* [out] */ IBaseFilter **ppf, - /* [out] */ IFileSinkFilter **ppSink) = 0; - - virtual /* [local] */ HRESULT STDMETHODCALLTYPE FindInterface( - /* [in] */ const GUID *pCategory, - /* [in] */ const GUID *pType, - /* [in] */ IBaseFilter *pf, - /* [in] */ REFIID riid, - /* [out] */ void **ppint) = 0; - - virtual HRESULT STDMETHODCALLTYPE RenderStream( - /* [in] */ const GUID *pCategory, - /* [in] */ const GUID *pType, - /* [in] */ IUnknown *pSource, - /* [in] */ IBaseFilter *pfCompressor, - /* [in] */ IBaseFilter *pfRenderer) = 0; - - virtual HRESULT STDMETHODCALLTYPE ControlStream( - /* [in] */ const GUID *pCategory, - /* [in] */ const GUID *pType, - /* [in] */ IBaseFilter *pFilter, - /* [in] */ REFERENCE_TIME *pstart, - /* [in] */ REFERENCE_TIME *pstop, - /* [in] */ WORD wStartCookie, - /* [in] */ WORD wStopCookie) = 0; - - virtual HRESULT STDMETHODCALLTYPE AllocCapFile( - /* [in] */ LPCOLESTR lpstr, - /* [in] */ DWORDLONG dwlSize) = 0; - - virtual HRESULT STDMETHODCALLTYPE CopyCaptureFile( - /* [in] */ LPOLESTR lpwstrOld, - /* [in] */ LPOLESTR lpwstrNew, - /* [in] */ int fAllowEscAbort, - /* [in] */ IAMCopyCaptureFileProgress *pCallback) = 0; - - virtual HRESULT STDMETHODCALLTYPE FindPin( - /* [in] */ IUnknown *pSource, - /* [in] */ PIN_DIRECTION pindir, - /* [in] */ const GUID *pCategory, - /* [in] */ const GUID *pType, - /* [in] */ BOOL fUnconnected, - /* [in] */ int num, - /* [out] */ IPin **ppPin) = 0; - -}; -#endif - -#ifndef __IAMStreamConfig_INTERFACE_DEFINED__ -#define __IAMStreamConfig_INTERFACE_DEFINED__ -struct IAMStreamConfig : public IUnknown -{ -public: - virtual HRESULT STDMETHODCALLTYPE SetFormat( - /* [in] */ AM_MEDIA_TYPE *pmt) = 0; - - virtual HRESULT STDMETHODCALLTYPE GetFormat( - /* [out] */ AM_MEDIA_TYPE **ppmt) = 0; - - virtual HRESULT STDMETHODCALLTYPE GetNumberOfCapabilities( - /* [out] */ int *piCount, - /* [out] */ int *piSize) = 0; - - virtual HRESULT STDMETHODCALLTYPE GetStreamCaps( - /* [in] */ int iIndex, - /* [out] */ AM_MEDIA_TYPE **ppmt, - /* [out] */ BYTE *pSCC) = 0; - -}; -#endif - -#ifndef __IErrorLog_INTERFACE_DEFINED__ -#define __IErrorLog_INTERFACE_DEFINED__ -struct IErrorLog : public IUnknown - { - public: - virtual HRESULT STDMETHODCALLTYPE AddError( - /* [in] */ LPCOLESTR pszPropName, - /* [in] */ EXCEPINFO *pExcepInfo) = 0; - - }; -#endif - -#ifndef __IPropertyBag_INTERFACE_DEFINED__ -#define __IPropertyBag_INTERFACE_DEFINED__ -struct IPropertyBag : public IUnknown -{ -public: - virtual /* [local] */ HRESULT STDMETHODCALLTYPE Read( - /* [in] */ LPCOLESTR pszPropName, - /* [out][in] */ VARIANT *pVar, - /* [in] */ IErrorLog *pErrorLog) = 0; - - virtual HRESULT STDMETHODCALLTYPE Write( - /* [in] */ LPCOLESTR pszPropName, - /* [in] */ VARIANT *pVar) = 0; - -}; -#endif - -typedef struct IMediaSample *LPMEDIASAMPLE; - -EXTERN_C const IID IID_ISampleGrabberCB; - -#ifndef __ISampleGrabberCB_INTERFACE_DEFINED__ -#define __ISampleGrabberCB_INTERFACE_DEFINED__ - -#undef INTERFACE -#define INTERFACE ISampleGrabberCB -DECLARE_INTERFACE_(ISampleGrabberCB, IUnknown) -{ -// STDMETHOD(QueryInterface) (THIS_ const GUID *, void **) PURE; - STDMETHOD(QueryInterface) (THIS_ REFIID riid, void **) PURE; - STDMETHOD_(ULONG, AddRef) (THIS) PURE; - STDMETHOD_(ULONG, Release) (THIS) PURE; - STDMETHOD_(HRESULT, SampleCB) (THIS_ double, LPMEDIASAMPLE) PURE; - STDMETHOD_(HRESULT, BufferCB) (THIS_ double, BYTE *, long) PURE; -}; -#undef INTERFACE - -#endif - - -#ifndef __ISampleGrabber_INTERFACE_DEFINED__ -#define __ISampleGrabber_INTERFACE_DEFINED__ - -#define INTERFACE ISampleGrabber -DECLARE_INTERFACE_(ISampleGrabber,IUnknown) -{ - STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE; - STDMETHOD_(ULONG,AddRef)(THIS) PURE; - STDMETHOD_(ULONG,Release)(THIS) PURE; - STDMETHOD(SetOneShot)(THIS_ BOOL) PURE; - STDMETHOD(SetMediaType)(THIS_ const AM_MEDIA_TYPE*) PURE; - STDMETHOD(GetConnectedMediaType)(THIS_ AM_MEDIA_TYPE*) PURE; - STDMETHOD(SetBufferSamples)(THIS_ BOOL) PURE; - STDMETHOD(GetCurrentBuffer)(THIS_ long*,long*) PURE; - STDMETHOD(GetCurrentSample)(THIS_ IMediaSample**) PURE; - STDMETHOD(SetCallback)(THIS_ ISampleGrabberCB *,long) PURE; -}; -#undef INTERFACE -#endif - - -#endif diff --git a/src/plugins/directshow/camera/dscameracontrol.cpp b/src/plugins/directshow/camera/dscameracontrol.cpp deleted file mode 100644 index 4379b79..0000000 --- a/src/plugins/directshow/camera/dscameracontrol.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qdebug.h> - -#include "dscameracontrol.h" -#include "dscameraservice.h" -#include "dscamerasession.h" - -QT_BEGIN_NAMESPACE - -DSCameraControl::DSCameraControl(QObject *parent) - :QCameraControl(parent), m_captureMode(QCamera::CaptureStillImage) -{ - m_session = qobject_cast<DSCameraSession*>(parent); - connect(m_session, SIGNAL(stateChanged(QCamera::State)),this, SIGNAL(stateChanged(QCamera::State))); -} - -DSCameraControl::~DSCameraControl() -{ -} - -void DSCameraControl::setState(QCamera::State state) -{ - switch (state) { - case QCamera::ActiveState: - start(); - break; - case QCamera::UnloadedState: /* fall through */ - case QCamera::LoadedState: - stop(); - break; - } -} - -bool DSCameraControl::isCaptureModeSupported(QCamera::CaptureMode mode) const -{ - bool bCaptureSupported = false; - switch (mode) { - case QCamera::CaptureStillImage: - bCaptureSupported = true; - break; - case QCamera::CaptureVideo: - bCaptureSupported = false; - break; - } - return bCaptureSupported; -} - -void DSCameraControl::start() -{ - m_session->record(); -} - -void DSCameraControl::stop() -{ - m_session->stop(); -} - -QCamera::State DSCameraControl::state() const -{ - return (QCamera::State)m_session->state(); -} - -QT_END_NAMESPACE diff --git a/src/plugins/directshow/camera/dscameracontrol.h b/src/plugins/directshow/camera/dscameracontrol.h deleted file mode 100644 index ee9e594..0000000 --- a/src/plugins/directshow/camera/dscameracontrol.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DSCAMERACONTROL_H -#define DSCAMERACONTROL_H - -#include <QtCore/qobject.h> -#include <qcameracontrol.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class DSCameraService; -class DSCameraSession; - - -class DSCameraControl : public QCameraControl -{ - Q_OBJECT -public: - DSCameraControl(QObject *parent = 0); - ~DSCameraControl(); - - void start(); - void stop(); - QCamera::State state() const; - - QCamera::CaptureMode captureMode() const { return m_captureMode; } - void setCaptureMode(QCamera::CaptureMode mode) - { - if (m_captureMode != mode) { - m_captureMode = mode; - emit captureModeChanged(mode); - } - } - - void setState(QCamera::State state); - - QCamera::Status status() const { return QCamera::UnavailableStatus; } - bool isCaptureModeSupported(QCamera::CaptureMode mode) const; - bool canChangeProperty(PropertyChangeType /* changeType */, QCamera::Status /* status */) const {return false; } - -private: - DSCameraSession *m_session; - DSCameraService *m_service; - QCamera::CaptureMode m_captureMode; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif - - diff --git a/src/plugins/directshow/camera/dscameraservice.cpp b/src/plugins/directshow/camera/dscameraservice.cpp deleted file mode 100644 index 3b42a18..0000000 --- a/src/plugins/directshow/camera/dscameraservice.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qvariant.h> -#include <QtCore/qdebug.h> -#include <QtWidgets/qwidget.h> -#include <QVideoWidgetControl.h> - - -#include "dscameraservice.h" -#include "dscameracontrol.h" -#include "dscamerasession.h" -#include "dsvideorenderer.h" -#include "dsvideodevicecontrol.h" -#include "dsimagecapturecontrol.h" -#include "dsvideowidgetcontrol.h" - -QT_BEGIN_NAMESPACE - -DSCameraService::DSCameraService(QObject *parent): - QMediaService(parent) -{ - m_session = new DSCameraSession(this); - - m_control = new DSCameraControl(m_session); - - m_videoDevice = new DSVideoDeviceControl(m_session); - - m_videoRenderer = new DSVideoRendererControl(m_session, this); - - m_imageCapture = new DSImageCaptureControl(m_session); - - m_viewFinderWidget = new DSVideoWidgetControl(m_session); - - m_device = QByteArray("default"); -} - -DSCameraService::~DSCameraService() -{ - delete m_control; - delete m_videoDevice; - delete m_videoRenderer; - delete m_imageCapture; - delete m_viewFinderWidget; - delete m_session; -} - -QMediaControl* DSCameraService::requestControl(const char *name) -{ - if(qstrcmp(name,QCameraControl_iid) == 0) - return m_control; - - if (qstrcmp(name, QCameraImageCaptureControl_iid) == 0) - return m_imageCapture; - - if (qstrcmp(name, QVideoWidgetControl_iid) == 0) { - if (m_viewFinderWidget) { - return m_viewFinderWidget; - } - } - - if(qstrcmp(name,QVideoRendererControl_iid) == 0) - return m_videoRenderer; - - if(qstrcmp(name,QVideoDeviceControl_iid) == 0) - return m_videoDevice; - - return 0; -} - -void DSCameraService::releaseControl(QMediaControl *control) -{ - // Implemented as a singleton, so we do nothing. -} - -QT_END_NAMESPACE diff --git a/src/plugins/directshow/camera/dscameraservice.h b/src/plugins/directshow/camera/dscameraservice.h deleted file mode 100644 index 2423801..0000000 --- a/src/plugins/directshow/camera/dscameraservice.h +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DSCAMERASERVICE_H -#define DSCAMERASERVICE_H - -#include <QtCore/qobject.h> - -#include <qmediaservice.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class DSCameraControl; -class DSCameraSession; -class DSVideoOutputControl; -class DSVideoDeviceControl; -class DSVideoRendererControl; -class DSImageCaptureControl; -class DSVideoWidgetControl; - - -class DSCameraService : public QMediaService -{ - Q_OBJECT - -public: - DSCameraService(QObject *parent = 0); - ~DSCameraService(); - - virtual QMediaControl* requestControl(const char *name); - virtual void releaseControl(QMediaControl *control); - -private: - DSCameraControl *m_control; - DSCameraSession *m_session; - DSVideoOutputControl *m_videoOutput; - DSVideoWidgetControl *m_viewFinderWidget; - DSVideoDeviceControl *m_videoDevice; - DSVideoRendererControl *m_videoRenderer; - DSImageCaptureControl *m_imageCapture; - QByteArray m_device; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/plugins/directshow/camera/dscamerasession.cpp b/src/plugins/directshow/camera/dscamerasession.cpp deleted file mode 100644 index 073bc60..0000000 --- a/src/plugins/directshow/camera/dscamerasession.cpp +++ /dev/null @@ -1,1160 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qdebug.h> -#include <QWidget> -#include <QFile> -#include <QtMultimedia/qabstractvideobuffer.h> -#include <QtMultimedia/qvideosurfaceformat.h> - -#include "dscamerasession.h" -#include "dsvideorenderer.h" -#include "directshowglobal.h" - -QT_BEGIN_NAMESPACE - -// If frames come in quicker than we display them, we allow the queue to build -// up to this number before we start dropping them. -const int LIMIT_FRAME = 5; - -namespace { -// DirectShow helper implementation -void _FreeMediaType(AM_MEDIA_TYPE& mt) -{ - if (mt.cbFormat != 0) { - CoTaskMemFree((PVOID)mt.pbFormat); - mt.cbFormat = 0; - mt.pbFormat = NULL; - } - if (mt.pUnk != NULL) { - // pUnk should not be used. - mt.pUnk->Release(); - mt.pUnk = NULL; - } -} - -} // end namespace - -class SampleGrabberCallbackPrivate : public ISampleGrabberCB -{ -public: - STDMETHODIMP_(ULONG) AddRef() { return 1; } - STDMETHODIMP_(ULONG) Release() { return 2; } - - STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject) - { - if (NULL == ppvObject) - return E_POINTER; - if (riid == IID_IUnknown /*__uuidof(IUnknown) */ ) { - *ppvObject = static_cast<IUnknown*>(this); - return S_OK; - } - if (riid == IID_ISampleGrabberCB /*__uuidof(ISampleGrabberCB)*/ ) { - *ppvObject = static_cast<ISampleGrabberCB*>(this); - return S_OK; - } - return E_NOTIMPL; - } - - STDMETHODIMP SampleCB(double Time, IMediaSample *pSample) - { - return E_NOTIMPL; - } - - STDMETHODIMP BufferCB(double Time, BYTE *pBuffer, long BufferLen) - { - if (!cs || active) { - return S_OK; - } - - if ((cs->StillMediaType.majortype != MEDIATYPE_Video) || - (cs->StillMediaType.formattype != FORMAT_VideoInfo) || - (cs->StillMediaType.cbFormat < sizeof(VIDEOINFOHEADER))) { - return VFW_E_INVALIDMEDIATYPE; - } - - active = true; - - if(toggle == true) { - toggle = false; - } - else { - toggle = true; - } - - if(toggle) { - active = false; - return S_OK; - } - - bool check = false; - cs->mutex.lock(); - - if (cs->frames.size() > LIMIT_FRAME) { - check = true; - } - - if (check) { - cs->mutex.unlock(); - // Frames building up. We're going to drop some here - Sleep(100); - active = false; - return S_OK; - } - cs->mutex.unlock(); - - unsigned char* vidData = new unsigned char[BufferLen]; - memcpy(vidData, pBuffer, BufferLen); - - cs->mutex.lock(); - - video_buffer* buf = new video_buffer; - buf->buffer = vidData; - buf->length = BufferLen; - buf->time = (qint64)Time; - - cs->frames.append(buf); - - cs->mutex.unlock(); - - QMetaObject::invokeMethod(cs, "captureFrame", Qt::QueuedConnection); - - active = false; - - return S_OK; - } - - DSCameraSession* cs; - bool active; - bool toggle; -}; - - -DSCameraSession::DSCameraSession(QObject *parent) - : QObject(parent) - ,m_currentImageId(0) -{ - pBuild = NULL; - pGraph = NULL; - pCap = NULL; - pSG_Filter = NULL; - pSG = NULL; - - opened = false; - available = false; - resolutions.clear(); - m_state = QCamera::UnloadedState; - m_device = "default"; - - StillCapCB = new SampleGrabberCallbackPrivate; - StillCapCB->cs = this; - StillCapCB->active = false; - StillCapCB->toggle = false; - - m_output = 0; - m_surface = 0; - m_windowSize = QSize(320,240); - pixelF = QVideoFrame::Format_RGB24; - actualFormat = QVideoSurfaceFormat(m_windowSize,pixelF); - - graph = false; - active = false; - - ::CoInitialize(NULL); -} - -DSCameraSession::~DSCameraSession() -{ - if (opened) { - closeStream(); - } - - CoUninitialize(); - - SAFE_RELEASE(pCap); - SAFE_RELEASE(pSG_Filter); - SAFE_RELEASE(pGraph); - SAFE_RELEASE(pBuild); - - if (StillCapCB) { - delete StillCapCB; - } -} - -int DSCameraSession::captureImage(const QString &fileName) -{ - emit readyForCaptureChanged(false); - - // We're going to do this in one big synchronous call - m_currentImageId++; - if (fileName.isEmpty()) { - m_snapshot = "img.jpg"; - } else { - m_snapshot = fileName; - } - - if (!active) { - startStream(); - } - - return m_currentImageId; -} - -void DSCameraSession::setSurface(QAbstractVideoSurface* surface) -{ - m_surface = surface; -} - -bool DSCameraSession::deviceReady() -{ - return available; -} - -bool DSCameraSession::pictureInProgress() -{ - return m_snapshot.isEmpty(); -} - -int DSCameraSession::framerate() const -{ - return -1; -} - -void DSCameraSession::setFrameRate(int rate) -{ - Q_UNUSED(rate) -} - -int DSCameraSession::brightness() const -{ - return -1; -} - -void DSCameraSession::setBrightness(int b) -{ - Q_UNUSED(b) -} - -int DSCameraSession::contrast() const -{ - return -1; -} - -void DSCameraSession::setContrast(int c) -{ - Q_UNUSED(c) -} - -int DSCameraSession::saturation() const -{ - return -1; -} - -void DSCameraSession::setSaturation(int s) -{ - Q_UNUSED(s) -} - -int DSCameraSession::hue() const -{ - return -1; -} - -void DSCameraSession::setHue(int h) -{ - Q_UNUSED(h) -} - -int DSCameraSession::sharpness() const -{ - return -1; -} - -void DSCameraSession::setSharpness(int s) -{ - Q_UNUSED(s) -} - -int DSCameraSession::zoom() const -{ - return -1; -} - -void DSCameraSession::setZoom(int z) -{ - Q_UNUSED(z) -} - -bool DSCameraSession::backlightCompensation() const -{ - return false; -} - -void DSCameraSession::setBacklightCompensation(bool b) -{ - Q_UNUSED(b) -} - -int DSCameraSession::whitelevel() const -{ - return -1; -} - -void DSCameraSession::setWhitelevel(int w) -{ - Q_UNUSED(w) -} - -int DSCameraSession::rotation() const -{ - return 0; -} - -void DSCameraSession::setRotation(int r) -{ - Q_UNUSED(r) -} - -bool DSCameraSession::flash() const -{ - return false; -} - -void DSCameraSession::setFlash(bool f) -{ - Q_UNUSED(f) -} - -bool DSCameraSession::autofocus() const -{ - return false; -} - -void DSCameraSession::setAutofocus(bool f) -{ - Q_UNUSED(f) -} - -QSize DSCameraSession::frameSize() const -{ - return m_windowSize; -} - -void DSCameraSession::setFrameSize(const QSize& s) -{ - if (supportedResolutions(pixelF).contains(s)) - m_windowSize = s; - else - qWarning() << "frame size if not supported for current pixel format, no change"; -} - -void DSCameraSession::setDevice(const QString &device) -{ - if(opened) - stopStream(); - - if(graph) { - SAFE_RELEASE(pCap); - SAFE_RELEASE(pSG_Filter); - SAFE_RELEASE(pGraph); - SAFE_RELEASE(pBuild); - } - - available = false; - m_state = QCamera::LoadedState; - - CoInitialize(NULL); - - ICreateDevEnum* pDevEnum = NULL; - IEnumMoniker* pEnum = NULL; - - // Create the System device enumerator - HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, - CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, - reinterpret_cast<void**>(&pDevEnum)); - if(SUCCEEDED(hr)) { - // Create the enumerator for the video capture category - hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnum, 0); - if (S_OK == hr) { - pEnum->Reset(); - // go through and find all video capture devices - IMoniker* pMoniker = NULL; - while(pEnum->Next(1, &pMoniker, NULL) == S_OK) { - IPropertyBag *pPropBag; - hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, - (void**)(&pPropBag)); - if(FAILED(hr)) { - pMoniker->Release(); - continue; // skip this one - } - // Find the description - WCHAR str[120]; - VARIANT varName; - varName.vt = VT_BSTR; - hr = pPropBag->Read(L"Description", &varName, 0); - if(FAILED(hr)) - hr = pPropBag->Read(L"FriendlyName", &varName, 0); - if(SUCCEEDED(hr)) { - wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0])); - QString temp(QString::fromUtf16((unsigned short*)str)); - if(temp.contains(device)) { - available = true; - } - } - pPropBag->Release(); - pMoniker->Release(); - } - pEnum->Release(); - } - pDevEnum->Release(); - } - CoUninitialize(); - - if(available) { - m_device = QByteArray(device.toLocal8Bit().constData()); - graph = createFilterGraph(); - if(!graph) - available = false; - } -} - -QList<QVideoFrame::PixelFormat> DSCameraSession::supportedPixelFormats() -{ - return types; -} - -QVideoFrame::PixelFormat DSCameraSession::pixelFormat() const -{ - return pixelF; -} - -void DSCameraSession::setPixelFormat(QVideoFrame::PixelFormat fmt) -{ - pixelF = fmt; -} - -QList<QSize> DSCameraSession::supportedResolutions(QVideoFrame::PixelFormat format) -{ - if (!resolutions.contains(format)) - return QList<QSize>(); - return resolutions.value(format); -} - -bool DSCameraSession::setOutputLocation(const QUrl &sink) -{ - m_sink = sink; - - return true; -} - -QUrl DSCameraSession::outputLocation() const -{ - return m_sink; -} - -qint64 DSCameraSession::position() const -{ - return timeStamp.elapsed(); -} - -int DSCameraSession::state() const -{ - return int(m_state); -} - -void DSCameraSession::record() -{ - if(opened) { - return; - } - - if(m_surface) { - bool match = false; - - if (!m_surface->isFormatSupported(actualFormat)) { - QList<QVideoFrame::PixelFormat> fmts; - foreach(QVideoFrame::PixelFormat f, types) { - if (fmts.contains(f)) { - match = true; - pixelF = f; - actualFormat = QVideoSurfaceFormat(m_windowSize,pixelF); - break; - } - } - } - if (!m_surface->isFormatSupported(actualFormat) && !match) { - // fallback - if (types.contains(QVideoFrame::Format_RGB24)) { - // get RGB24 from camera and convert to RGB32 for surface! - pixelF = QVideoFrame::Format_RGB32; - actualFormat = QVideoSurfaceFormat(m_windowSize,pixelF); - } - } - - if (m_surface->isFormatSupported(actualFormat)) { - m_surface->start(actualFormat); - m_state = QCamera::ActiveState; - emit stateChanged(QCamera::ActiveState); - } else { - qWarning() << "surface doesn't support camera format, cant start"; - m_state = QCamera::LoadedState; - emit stateChanged(QCamera::LoadedState); - return; - } - } else { - qWarning() << "no video surface, cant start"; - m_state = QCamera::LoadedState; - emit stateChanged(QCamera::LoadedState); - return; - } - - opened = startStream(); - - if (!opened) { - qWarning() << "Stream did not open"; - m_state = QCamera::LoadedState; - emit stateChanged(QCamera::LoadedState); - } -} - -void DSCameraSession::pause() -{ - suspendStream(); -} - -void DSCameraSession::stop() -{ - if(!opened) { - return; - } - - stopStream(); - opened = false; - m_state = QCamera::LoadedState; - emit stateChanged(QCamera::LoadedState); -} - -void DSCameraSession::captureFrame() -{ - if(m_surface && frames.count() > 0) { - - QImage image; - - if(pixelF == QVideoFrame::Format_RGB24) { - - mutex.lock(); - - image = QImage(frames.at(0)->buffer,m_windowSize.width(),m_windowSize.height(), - QImage::Format_RGB888).rgbSwapped().mirrored(true); - - QVideoFrame frame(image); - frame.setStartTime(frames.at(0)->time); - - mutex.unlock(); - - m_surface->present(frame); - - } else if (pixelF == QVideoFrame::Format_RGB32) { - - mutex.lock(); - - image = QImage(frames.at(0)->buffer,m_windowSize.width(),m_windowSize.height(), - QImage::Format_RGB888).rgbSwapped().mirrored(true); - - QVideoFrame frame(image.convertToFormat(QImage::Format_RGB32)); - frame.setStartTime(frames.at(0)->time); - - mutex.unlock(); - - m_surface->present(frame); - - } else { - qWarning() << "TODO:captureFrame() format =" << pixelF; - } - - if (m_snapshot.length() > 0) { - emit imageCaptured(m_currentImageId, image); - image.save(m_snapshot,"JPG"); - emit imageSaved(m_currentImageId, m_snapshot); - m_snapshot.clear(); - emit readyForCaptureChanged(true); - } - - mutex.lock(); - if (frames.isEmpty()) { - qWarning() << "Frames over-run"; - } - - video_buffer* buf = frames.takeFirst(); - delete buf->buffer; - delete buf; - mutex.unlock(); - } -} - -HRESULT DSCameraSession::getPin(IBaseFilter *pFilter, PIN_DIRECTION PinDir, IPin **ppPin) -{ - *ppPin = 0; - IEnumPins *pEnum = 0; - IPin *pPin = 0; - - HRESULT hr = pFilter->EnumPins(&pEnum); - if(FAILED(hr)) { - return hr; - } - - pEnum->Reset(); - while(pEnum->Next(1, &pPin, NULL) == S_OK) { - PIN_DIRECTION ThisPinDir; - pPin->QueryDirection(&ThisPinDir); - if(ThisPinDir == PinDir) { - pEnum->Release(); - *ppPin = pPin; - return S_OK; - } - pEnum->Release(); - } - pEnum->Release(); - return E_FAIL; -} - -bool DSCameraSession::createFilterGraph() -{ - HRESULT hr; - IMoniker* pMoniker = NULL; - ICreateDevEnum* pDevEnum = NULL; - IEnumMoniker* pEnum = NULL; - - CoInitialize(NULL); - - // Create the filter graph - hr = CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC, - IID_IGraphBuilder, (void**)&pGraph); - if (FAILED(hr)) { - qWarning()<<"failed to create filter graph"; - return false; - } - - // Create the capture graph builder - hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC, - IID_ICaptureGraphBuilder2, (void**)&pBuild); - if (FAILED(hr)) { - qWarning()<<"failed to create graph builder"; - return false; - } - - // Attach the filter graph to the capture graph - hr = pBuild->SetFiltergraph(pGraph); - if (FAILED(hr)) { - qWarning()<<"failed to connect capture graph and filter graph"; - return false; - } - - // Find the Capture device - hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, - CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, - reinterpret_cast<void**>(&pDevEnum)); - if (SUCCEEDED(hr)) { - // Create an enumerator for the video capture category - hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnum, 0); - pDevEnum->Release(); - if (S_OK == hr) { - pEnum->Reset(); - //go through and find all video capture devices - while (pEnum->Next(1, &pMoniker, NULL) == S_OK) { - IPropertyBag *pPropBag; - hr = pMoniker->BindToStorage(0, 0, - IID_IPropertyBag, (void**)(&pPropBag)); - if(FAILED(hr)) { - pMoniker->Release(); - continue; // skip this one - } - // Find the description - WCHAR str[120]; - VARIANT varName; - varName.vt = VT_BSTR; - hr = pPropBag->Read(L"FriendlyName", &varName, 0); - if (SUCCEEDED(hr)) { - // check if it is the selected device - wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0])); - QString output = QString::fromUtf16((unsigned short*)str); - if (m_device.contains(output.toLocal8Bit().constData())) { - hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&pCap); - if (SUCCEEDED(hr)) { - pPropBag->Release(); - pMoniker->Release(); - break; - } - } - } - pPropBag->Release(); - pMoniker->Release(); - } - if (NULL == pCap) - { - if (m_device.contains("default")) - { - pEnum->Reset(); - // still have to loop to discard bind to storage failure case - while (pEnum->Next(1, &pMoniker, NULL) == S_OK) { - IPropertyBag *pPropBag = 0; - - hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void**)(&pPropBag)); - if (FAILED(hr)) { - pMoniker->Release(); - continue; // Don't panic yet - } - - // No need to get the description, just grab it - - hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&pCap); - pPropBag->Release(); - pMoniker->Release(); - if (SUCCEEDED(hr)) { - break; // done, stop looping through - } - else - { - qWarning() << "Object bind failed"; - } - } - } - } - pEnum->Release(); - } - } - - // Sample grabber filter - hr = CoCreateInstance(CLSID_SampleGrabber, NULL,CLSCTX_INPROC, - IID_IBaseFilter, (void**)&pSG_Filter); - if (FAILED(hr)) { - qWarning() << "failed to create sample grabber"; - return false; - } - - pSG_Filter->QueryInterface(IID_ISampleGrabber, (void**)&pSG); - if (FAILED(hr)) { - qWarning() << "failed to get sample grabber"; - return false; - } - pSG->SetOneShot(FALSE); - pSG->SetBufferSamples(TRUE); - pSG->SetCallback(StillCapCB, 1); - - CoUninitialize(); - - return true; -} - -void DSCameraSession::updateProperties() -{ - HRESULT hr; - AM_MEDIA_TYPE *pmt = NULL; - VIDEOINFOHEADER *pvi = NULL; - VIDEO_STREAM_CONFIG_CAPS scc; - IAMStreamConfig* pConfig = 0; - - hr = pBuild->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,pCap, - IID_IAMStreamConfig, (void**)&pConfig); - if (FAILED(hr)) { - qWarning()<<"failed to get config on capture device"; - return; - } - - int iCount; - int iSize; - hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize); - if (FAILED(hr)) { - qWarning()<<"failed to get capabilities"; - return; - } - - QList<QSize> sizes; - QVideoFrame::PixelFormat f = QVideoFrame::Format_Invalid; - - types.clear(); - resolutions.clear(); - - for (int iIndex = 0; iIndex < iCount; iIndex++) { - hr = pConfig->GetStreamCaps(iIndex, &pmt, reinterpret_cast<BYTE*>(&scc)); - if (hr == S_OK) { - pvi = (VIDEOINFOHEADER*)pmt->pbFormat; - if ((pmt->majortype == MEDIATYPE_Video) && - (pmt->formattype == FORMAT_VideoInfo)) { - // Add types - if (pmt->subtype == MEDIASUBTYPE_RGB24) { - if (!types.contains(QVideoFrame::Format_RGB24)) { - types.append(QVideoFrame::Format_RGB24); - f = QVideoFrame::Format_RGB24; - } - } else if (pmt->subtype == MEDIASUBTYPE_RGB32) { - if (!types.contains(QVideoFrame::Format_RGB32)) { - types.append(QVideoFrame::Format_RGB32); - f = QVideoFrame::Format_RGB32; - } - } else if (pmt->subtype == MEDIASUBTYPE_YUY2) { - if (!types.contains(QVideoFrame::Format_YUYV)) { - types.append(QVideoFrame::Format_YUYV); - f = QVideoFrame::Format_YUYV; - } - } else if (pmt->subtype == MEDIASUBTYPE_MJPG) { - } else if (pmt->subtype == MEDIASUBTYPE_I420) { - if (!types.contains(QVideoFrame::Format_YUV420P)) { - types.append(QVideoFrame::Format_YUV420P); - f = QVideoFrame::Format_YUV420P; - } - } else if (pmt->subtype == MEDIASUBTYPE_RGB555) { - if (!types.contains(QVideoFrame::Format_RGB555)) { - types.append(QVideoFrame::Format_RGB555); - f = QVideoFrame::Format_RGB555; - } - } else if (pmt->subtype == MEDIASUBTYPE_YVU9) { - } else if (pmt->subtype == MEDIASUBTYPE_UYVY) { - if (!types.contains(QVideoFrame::Format_UYVY)) { - types.append(QVideoFrame::Format_UYVY); - f = QVideoFrame::Format_UYVY; - } - } else { - qWarning() << "UNKNOWN FORMAT: " << pmt->subtype.Data1; - } - // Add resolutions - QSize res(pvi->bmiHeader.biWidth, pvi->bmiHeader.biHeight); - if (!resolutions.contains(f)) { - sizes.clear(); - resolutions.insert(f,sizes); - } - resolutions[f].append(res); - } - } - } - pConfig->Release(); -} - -bool DSCameraSession::setProperties() -{ - CoInitialize(NULL); - - HRESULT hr; - AM_MEDIA_TYPE am_media_type; - AM_MEDIA_TYPE *pmt = NULL; - VIDEOINFOHEADER *pvi = NULL; - VIDEO_STREAM_CONFIG_CAPS scc; - - IAMStreamConfig* pConfig = 0; - hr = pBuild->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, pCap, - IID_IAMStreamConfig, (void**)&pConfig); - if(FAILED(hr)) { - qWarning()<<"failed to get config on capture device"; - return false; - } - - int iCount; - int iSize; - hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize); - if(FAILED(hr)) { - qWarning()<<"failed to get capabilities"; - return false; - } - - bool setFormatOK = false; - for (int iIndex = 0; iIndex < iCount; iIndex++) { - hr = pConfig->GetStreamCaps(iIndex, &pmt, reinterpret_cast<BYTE*>(&scc)); - if (hr == S_OK) { - pvi = (VIDEOINFOHEADER*)pmt->pbFormat; - - if ((pmt->majortype == MEDIATYPE_Video) && - (pmt->formattype == FORMAT_VideoInfo)) { - if ((actualFormat.frameWidth() == pvi->bmiHeader.biWidth) && - (actualFormat.frameHeight() == pvi->bmiHeader.biHeight)) { - hr = pConfig->SetFormat(pmt); - _FreeMediaType(*pmt); - if(FAILED(hr)) { - qWarning()<<"failed to set format:" << hr; - qWarning()<<"but going to continue"; - continue; // We going to continue - } else { - setFormatOK = true; - break; - } - } - } - } - } - pConfig->Release(); - - if (!setFormatOK) { - qWarning() << "unable to set any format for camera"; - return false; - } - - // Set Sample Grabber config to match capture - ZeroMemory(&am_media_type, sizeof(am_media_type)); - am_media_type.majortype = MEDIATYPE_Video; - - if (actualFormat.pixelFormat() == QVideoFrame::Format_RGB32) - am_media_type.subtype = MEDIASUBTYPE_RGB24; - else if (actualFormat.pixelFormat() == QVideoFrame::Format_RGB24) - am_media_type.subtype = MEDIASUBTYPE_RGB24; - else if (actualFormat.pixelFormat() == QVideoFrame::Format_YUYV) - am_media_type.subtype = MEDIASUBTYPE_YUY2; - else if (actualFormat.pixelFormat() == QVideoFrame::Format_YUV420P) - am_media_type.subtype = MEDIASUBTYPE_I420; - else if (actualFormat.pixelFormat() == QVideoFrame::Format_RGB555) - am_media_type.subtype = MEDIASUBTYPE_RGB555; - else if (actualFormat.pixelFormat() == QVideoFrame::Format_UYVY) - am_media_type.subtype = MEDIASUBTYPE_UYVY; - else { - qWarning()<<"unknown format? for SG"; - return false; - } - - am_media_type.formattype = FORMAT_VideoInfo; - hr = pSG->SetMediaType(&am_media_type); - if (FAILED(hr)) { - qWarning()<<"failed to set video format on grabber"; - return false; - } - - pSG->GetConnectedMediaType(&StillMediaType); - - CoUninitialize(); - - return true; -} - -bool DSCameraSession::openStream() -{ - //Opens the stream for reading and allocates any necessary resources needed - //Return true if success, false otherwise - - if (opened) { - return true; - } - - if (!graph) { - graph = createFilterGraph(); - if(!graph) { - qWarning()<<"failed to create filter graph in openStream"; - return false; - } - } - - CoInitialize(NULL); - - HRESULT hr; - - hr = pGraph->AddFilter(pCap, L"Capture Filter"); - if (FAILED(hr)) { - qWarning()<<"failed to create capture filter"; - return false; - } - - hr = pGraph->AddFilter(pSG_Filter, L"Sample Grabber"); - if (FAILED(hr)) { - qWarning()<<"failed to add sample grabber"; - return false; - } - - hr = pBuild->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, - pCap, NULL, pSG_Filter); - if (FAILED(hr)) { - qWarning() << "failed to renderstream" << hr; - return false; - } - pSG->GetConnectedMediaType(&StillMediaType); - pSG_Filter->Release(); - - CoUninitialize(); - - return true; -} - -void DSCameraSession::closeStream() -{ - // Closes the stream and internally frees any resources used - HRESULT hr; - IMediaControl* pControl = 0; - - hr = pGraph->QueryInterface(IID_IMediaControl,(void**)&pControl); - if (FAILED(hr)) { - qWarning()<<"failed to get stream control"; - return; - } - - hr = pControl->StopWhenReady(); - if (FAILED(hr)) { - qWarning()<<"failed to stop"; - pControl->Release(); - return; - } - - pControl->Release(); - - opened = false; - IPin *pPin = 0; - - if (pCap) - { - hr = getPin(pCap, PINDIR_OUTPUT, &pPin); - if(FAILED(hr)) { - qWarning()<<"failed to disconnect capture filter"; - return; - } - } - - pGraph->Disconnect(pPin); - if (FAILED(hr)) { - qWarning()<<"failed to disconnect grabber filter"; - return; - } - - hr = getPin(pSG_Filter,PINDIR_INPUT,&pPin); - pGraph->Disconnect(pPin); - pGraph->RemoveFilter(pSG_Filter); - pGraph->RemoveFilter(pCap); - - SAFE_RELEASE(pCap); - SAFE_RELEASE(pSG_Filter); - SAFE_RELEASE(pGraph); - SAFE_RELEASE(pBuild); - - graph = false; -} - -bool DSCameraSession::startStream() -{ - // Starts the stream, by emitting either QVideoPackets - // or QvideoFrames, depending on Format chosen - if (!graph) - graph = createFilterGraph(); - - if (!setProperties()) { - qWarning() << "Couldn't set properties (retrying)"; - closeStream(); - if (!openStream()) { - qWarning() << "Retry to open strean failed"; - return false; - } - } - - if (!opened) { - opened = openStream(); - if (!opened) { - qWarning() << "failed to openStream()"; - return false; - } - } - - HRESULT hr; - IMediaControl* pControl = 0; - - hr = pGraph->QueryInterface(IID_IMediaControl, (void**)&pControl); - if (FAILED(hr)) { - qWarning() << "failed to get stream control"; - return false; - } - - hr = pControl->Run(); - pControl->Release(); - - if (FAILED(hr)) { - qWarning() << "failed to start"; - return false; - } - active = true; - return true; -} - -void DSCameraSession::stopStream() -{ - // Stops the stream from emitting packets - HRESULT hr; - - IMediaControl* pControl = 0; - hr = pGraph->QueryInterface(IID_IMediaControl, (void**)&pControl); - if (FAILED(hr)) { - qWarning() << "failed to get stream control"; - return; - } - - hr = pControl->Stop(); - pControl->Release(); - if (FAILED(hr)) { - qWarning() << "failed to stop"; - return; - } - active = false; - - if (opened) { - closeStream(); - } -} - -void DSCameraSession::suspendStream() -{ - // Pauses the stream - HRESULT hr; - - IMediaControl* pControl = 0; - hr = pGraph->QueryInterface(IID_IMediaControl, (void**)&pControl); - if (FAILED(hr)) { - qWarning() << "failed to get stream control"; - return; - } - - hr = pControl->Pause(); - pControl->Release(); - if (FAILED(hr)) { - qWarning() << "failed to pause"; - return; - } - - active = false; -} - -void DSCameraSession::resumeStream() -{ - // Resumes a paused stream - startStream(); -} - -QT_END_NAMESPACE - diff --git a/src/plugins/directshow/camera/dscamerasession.h b/src/plugins/directshow/camera/dscamerasession.h deleted file mode 100644 index 3ac4622..0000000 --- a/src/plugins/directshow/camera/dscamerasession.h +++ /dev/null @@ -1,208 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DSCAMERASESSION_H -#define DSCAMERASESSION_H - -#include <QtCore/qobject.h> -#include <QTime> -#include <QUrl> -#include <QMutex> - -#include <qcamera.h> -#include <QtMultimedia/qvideoframe.h> -#include <QtMultimedia/qabstractvideosurface.h> -#include <QtMultimedia/qvideosurfaceformat.h> - -#include <tchar.h> -#include <dshow.h> -#include <objbase.h> -#include <initguid.h> -#pragma comment(lib, "strmiids.lib") -#pragma comment(lib, "ole32.lib") -#include <windows.h> - -#pragma include_alias("dxtrans.h","qedit.h") -#define __IDxtCompositor_INTERFACE_DEFINED__ -#define __IDxtAlphaSetter_INTERFACE_DEFINED__ -#define __IDxtJpeg_INTERFACE_DEFINED__ -#define __IDxtKey_INTERFACE_DEFINED__ -#include <qedit.h> - -struct ICaptureGraphBuilder2; -struct ISampleGrabber; - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class DSVideoRenderer; -class SampleGrabberCallbackPrivate; - - -struct video_buffer { - unsigned char* buffer; - int length; - qint64 time; -}; - -typedef QMap<unsigned int, QList<QSize> > FormatResolutionMap; - -class DSCameraSession : public QObject -{ - Q_OBJECT -public: - DSCameraSession(QObject *parent = 0); - ~DSCameraSession(); - - bool deviceReady(); - bool pictureInProgress(); - - // camera controls - - int framerate() const; - void setFrameRate(int rate); - int brightness() const; - void setBrightness(int b); - int contrast() const; - void setContrast(int c); - int saturation() const; - void setSaturation(int s); - int hue() const; - void setHue(int h); - int sharpness() const; - void setSharpness(int s); - int zoom() const; - void setZoom(int z); - bool backlightCompensation() const; - void setBacklightCompensation(bool); - int whitelevel() const; - void setWhitelevel(int w); - int rotation() const; - void setRotation(int r); - bool flash() const; - void setFlash(bool f); - bool autofocus() const; - void setAutofocus(bool f); - - QSize frameSize() const; - void setFrameSize(const QSize& s); - void setDevice(const QString &device); - QList<QVideoFrame::PixelFormat> supportedPixelFormats(); - QVideoFrame::PixelFormat pixelFormat() const; - void setPixelFormat(QVideoFrame::PixelFormat fmt); - QList<QSize> supportedResolutions(QVideoFrame::PixelFormat format); - - // media control - - bool setOutputLocation(const QUrl &sink); - QUrl outputLocation() const; - qint64 position() const; - int state() const; - void record(); - void pause(); - void stop(); - - void setSurface(QAbstractVideoSurface* surface); - - int captureImage(const QString &fileName); - - AM_MEDIA_TYPE StillMediaType; - QList<video_buffer*> frames; - SampleGrabberCallbackPrivate* StillCapCB; - - QMutex mutex; - -Q_SIGNALS: - void stateChanged(QCamera::State); - void imageCaptured(int id, const QImage &preview); - void imageSaved(int id, const QString &fileName); - void readyForCaptureChanged(bool); - -private Q_SLOTS: - void captureFrame(); - -private: - QVideoSurfaceFormat actualFormat; - QList<QVideoFrame::PixelFormat> types; - - QTime timeStamp; - bool graph; - bool active; - bool opened; - bool available; - QCamera::State m_state; - QByteArray m_device; - QUrl m_sink; - DSVideoRenderer* m_output; - QAbstractVideoSurface* m_surface; - QVideoFrame::PixelFormat pixelF; - QSize m_windowSize; - FormatResolutionMap resolutions; - - ICaptureGraphBuilder2* pBuild; - IGraphBuilder* pGraph; - IBaseFilter* pCap; - IBaseFilter* pSG_Filter; - ISampleGrabber *pSG; - - - QString m_snapshot; - int m_currentImageId; -protected: - HRESULT getPin(IBaseFilter *pFilter, PIN_DIRECTION PinDir, IPin **ppPin); - bool createFilterGraph(); - void updateProperties(); - bool setProperties(); - bool openStream(); - void closeStream(); - bool startStream(); - void stopStream(); - void suspendStream(); - void resumeStream(); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - - -#endif diff --git a/src/plugins/directshow/camera/dsimagecapturecontrol.cpp b/src/plugins/directshow/camera/dsimagecapturecontrol.cpp deleted file mode 100644 index 7ee6ffd..0000000 --- a/src/plugins/directshow/camera/dsimagecapturecontrol.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/QDebug> - -#include "dsimagecapturecontrol.h" - -QT_BEGIN_NAMESPACE - -DSImageCaptureControl::DSImageCaptureControl(DSCameraSession *session) - :QCameraImageCaptureControl(session), m_session(session), m_ready(false) -{ - connect(m_session, SIGNAL(stateChanged(QCamera::State)), SLOT(updateState())); - connect(m_session, SIGNAL(imageCaptured(const int, QImage)), - this, SIGNAL(imageCaptured(const int, QImage))); - connect(m_session, SIGNAL(imageSaved(const int, const QString &)), - this, SIGNAL(imageSaved(const int, const QString &))); - connect(m_session, SIGNAL(readyForCaptureChanged(bool)), - this, SIGNAL(readyForCaptureChanged(bool))); -} - -DSImageCaptureControl::~DSImageCaptureControl() -{ -} - -bool DSImageCaptureControl::isReadyForCapture() const -{ - return m_ready; -} - -int DSImageCaptureControl::capture(const QString &fileName) -{ - return m_session->captureImage(fileName); -} - -void DSImageCaptureControl::updateState() -{ - bool ready = (m_session->state() == QCamera::ActiveState) && - !m_session->pictureInProgress(); - if(m_ready != ready) - emit readyForCaptureChanged(m_ready = ready); -} - -QT_END_NAMESPACE - diff --git a/src/plugins/directshow/camera/dsimagecapturecontrol.h b/src/plugins/directshow/camera/dsimagecapturecontrol.h deleted file mode 100644 index baf649a..0000000 --- a/src/plugins/directshow/camera/dsimagecapturecontrol.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DSIMAGECAPTURECONTROL_H -#define DSIMAGECAPTURECONTROL_H - -#include <qcameraimagecapturecontrol.h> -#include "dscamerasession.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class DSImageCaptureControl : public QCameraImageCaptureControl -{ - Q_OBJECT -public: - DSImageCaptureControl(DSCameraSession *session); - virtual ~DSImageCaptureControl(); - - bool isReadyForCapture() const; - int capture(const QString &fileName); - - virtual QCameraImageCapture::DriveMode driveMode() const { return QCameraImageCapture::SingleImageCapture; } - virtual void setDriveMode(QCameraImageCapture::DriveMode mode) { } - - virtual void cancelCapture() {} - -private slots: - void updateState(); - - -private: - DSCameraSession *m_session; - bool m_ready; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // DSCAPTURECONTROL_H diff --git a/src/plugins/directshow/camera/dsvideodevicecontrol.cpp b/src/plugins/directshow/camera/dsvideodevicecontrol.cpp deleted file mode 100644 index 11da5d3..0000000 --- a/src/plugins/directshow/camera/dsvideodevicecontrol.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QDebug> -#include <QFile> -#include <QtWidgets/QIcon> - -#include "dsvideodevicecontrol.h" -#include "dscamerasession.h" - -#include <tchar.h> -#include <dshow.h> -#include <objbase.h> -#include <initguid.h> -#include <Ocidl.h> -#include <string.h> - -extern const CLSID CLSID_VideoInputDeviceCategory; - -QT_BEGIN_NAMESPACE - -DSVideoDeviceControl::DSVideoDeviceControl(QObject *parent) - : QVideoDeviceControl(parent) -{ - m_session = qobject_cast<DSCameraSession*>(parent); - - devices.clear(); - descriptions.clear(); - - CoInitialize(NULL); - ICreateDevEnum* pDevEnum = NULL; - IEnumMoniker* pEnum = NULL; - // Create the System device enumerator - HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, - CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, - reinterpret_cast<void**>(&pDevEnum)); - if(SUCCEEDED(hr)) { - // Create the enumerator for the video capture category - hr = pDevEnum->CreateClassEnumerator( - CLSID_VideoInputDeviceCategory, &pEnum, 0); - if (S_OK == hr) { - pEnum->Reset(); - // go through and find all video capture devices - IMoniker* pMoniker = NULL; - while(pEnum->Next(1, &pMoniker, NULL) == S_OK) { - IPropertyBag *pPropBag; - hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, - (void**)(&pPropBag)); - if(FAILED(hr)) { - pMoniker->Release(); - continue; // skip this one - } - // Find the description - WCHAR str[120]; - VARIANT varName; - varName.vt = VT_BSTR; - hr = pPropBag->Read(L"FriendlyName", &varName, 0); - if(SUCCEEDED(hr)) { - wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0])); - QString temp(QString::fromUtf16((unsigned short*)str)); - devices.append(QString("ds:%1").arg(temp).toLocal8Bit().constData()); - hr = pPropBag->Read(L"Description", &varName, 0); - wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0])); - QString temp2(QString::fromUtf16((unsigned short*)str)); - descriptions.append(temp2.toLocal8Bit().constData()); - } - pPropBag->Release(); - pMoniker->Release(); - } - pEnum->Release(); - } - pDevEnum->Release(); - } - CoUninitialize(); - - selected = 0; -} - -int DSVideoDeviceControl::deviceCount() const -{ - return devices.count(); -} - -QString DSVideoDeviceControl::deviceName(int index) const -{ - if(index >= 0 && index <= devices.count()) - return devices.at(index); - - return QString(); -} - -QString DSVideoDeviceControl::deviceDescription(int index) const -{ - if(index >= 0 && index <= descriptions.count()) - return descriptions.at(index); - - return QString(); -} - -QIcon DSVideoDeviceControl::deviceIcon(int index) const -{ - Q_UNUSED(index) - - return QIcon(); -} - -int DSVideoDeviceControl::defaultDevice() const -{ - return 0; -} - -int DSVideoDeviceControl::selectedDevice() const -{ - return selected; -} - -void DSVideoDeviceControl::setSelectedDevice(int index) -{ - if(index >= 0 && index <= devices.count()) { - if (m_session) { - QString device = devices.at(index); - if (device.startsWith("ds:")) - device.remove(0,3); - m_session->setDevice(device); - } - selected = index; - } -} - -QT_END_NAMESPACE diff --git a/src/plugins/directshow/camera/dsvideodevicecontrol.h b/src/plugins/directshow/camera/dsvideodevicecontrol.h deleted file mode 100644 index 0711479..0000000 --- a/src/plugins/directshow/camera/dsvideodevicecontrol.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DSVIDEODEVICECONTROL_H -#define DSVIDEODEVICECONTROL_H - -#include <qvideodevicecontrol.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE -class DSCameraSession; - -//QTM_USE_NAMESPACE - -class DSVideoDeviceControl : public QVideoDeviceControl -{ - Q_OBJECT -public: - DSVideoDeviceControl(QObject *parent = 0); - - int deviceCount() const; - QString deviceName(int index) const; - QString deviceDescription(int index) const; - QIcon deviceIcon(int index) const; - int defaultDevice() const; - int selectedDevice() const; - -public Q_SLOTS: - void setSelectedDevice(int index); - -private: - DSCameraSession* m_session; - - QList<QString> devices; - QList<QString> descriptions; - - int selected; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/plugins/directshow/camera/dsvideorenderer.cpp b/src/plugins/directshow/camera/dsvideorenderer.cpp deleted file mode 100644 index f0a80e2..0000000 --- a/src/plugins/directshow/camera/dsvideorenderer.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qdebug.h> - -#include "dsvideorenderer.h" - -QT_BEGIN_NAMESPACE - -DSVideoRendererControl::DSVideoRendererControl(DSCameraSession* session, QObject *parent) - :QVideoRendererControl(parent), - m_surface(0), - m_session(session) -{ -} - -DSVideoRendererControl::~DSVideoRendererControl() -{ -} - -QAbstractVideoSurface* DSVideoRendererControl::surface() const -{ - return m_surface; -} - -void DSVideoRendererControl::setSurface(QAbstractVideoSurface *surface) -{ - m_surface = surface; - if(m_session) - m_session->setSurface(m_surface); -} - -QT_END_NAMESPACE - diff --git a/src/plugins/directshow/camera/dsvideorenderer.h b/src/plugins/directshow/camera/dsvideorenderer.h deleted file mode 100644 index f8e7642..0000000 --- a/src/plugins/directshow/camera/dsvideorenderer.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DSVIDEORENDERER_H -#define DSVIDEORENDERER_H - -#include <qvideorenderercontrol.h> -#include "dscamerasession.h" - -class CameraFormatConverter; - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - - -class DSVideoRendererControl : public QVideoRendererControl -{ - Q_OBJECT -public: - DSVideoRendererControl(DSCameraSession* session, QObject *parent = 0); - ~DSVideoRendererControl(); - - QAbstractVideoSurface *surface() const; - void setSurface(QAbstractVideoSurface *surface); - - void setSession(DSCameraSession* session); - -private: - QAbstractVideoSurface* m_surface; - DSCameraSession* m_session; - CameraFormatConverter* converter; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // DSVIDEORENDERER_H diff --git a/src/plugins/directshow/camera/dsvideowidgetcontrol.cpp b/src/plugins/directshow/camera/dsvideowidgetcontrol.cpp deleted file mode 100644 index 676b2d5..0000000 --- a/src/plugins/directshow/camera/dsvideowidgetcontrol.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qcoreevent.h> -#include <QtCore/qtimer.h> - -#include "DSVideoWidgetControl.h" -#include "dscamerasession.h" - -QT_BEGIN_NAMESPACE - -DSVideoWidgetSurface::DSVideoWidgetSurface(QLabel *pWidget, QObject *parent) -{ - widget = pWidget; - myPixmap = 0; -} - -QList<QVideoFrame::PixelFormat> DSVideoWidgetSurface::supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType) const -{ - if (handleType == QAbstractVideoBuffer::NoHandle) { - return QList<QVideoFrame::PixelFormat>() - << QVideoFrame::Format_RGB32 - << QVideoFrame::Format_RGB24; - } else { - return QList<QVideoFrame::PixelFormat>(); - } -} - - -bool DSVideoWidgetSurface::present(const QVideoFrame &frame) -{ - QVideoFrame myFrame = frame; - myFrame.map(QAbstractVideoBuffer::ReadOnly); - QImage image( - frame.bits(), - frame.width(), - frame.height(), - frame.bytesPerLine(), - imageFormat); - if (image.isNull()) - { - // Try to adapt - QImage image2( - frame.bits(), - frame.width(), - frame.height(), - frame.bytesPerLine(), - QImage::Format_RGB888); - image = image2; - } - myFrame.unmap(); - delete myPixmap; - myPixmap = new QPixmap(QPixmap::fromImage(image).scaled(widget->size())); - widget->setPixmap(*myPixmap); - widget->repaint(); - return true; -} - -void DSVideoWidgetSurface::setImageFormat(QImage::Format fmt) -{ - imageFormat = fmt; -} - -void DSVideoWidgetSurface::updateVideoRect() -{ -} - -void DSVideoWidgetSurface::paint(QPainter *painter) -{ -} - - -DSVideoWidgetControl::DSVideoWidgetControl(DSCameraSession* session, QObject *parent) : - m_session(session), QVideoWidgetControl(parent), - m_widget(new QLabel()), - m_fullScreen(false) -{ - m_widget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - m_widget->setAlignment(Qt::AlignCenter); - m_widget->setAttribute(Qt::WA_NoSystemBackground, true); - - surface = new DSVideoWidgetSurface(m_widget); - - QPalette palette; - palette.setColor(QPalette::Background, Qt::black); - m_widget->setPalette(palette); - m_widget->setAutoFillBackground( true ); - - // Request QEvents - m_widget->installEventFilter(this); - m_windowId = m_widget->effectiveWinId(); - - surface->setImageFormat(QImage::Format_RGB888); - session->setSurface(surface); -} - -DSVideoWidgetControl::~DSVideoWidgetControl() -{ - delete m_widget; -} - -bool DSVideoWidgetControl::eventFilter(QObject *object, QEvent *e) -{ - if (object == m_widget) { - switch (e->type()) { - case QEvent::ParentChange: - case QEvent::WinIdChange: - case QEvent::Show: - m_windowId = m_widget->effectiveWinId(); - emit widgetUpdated(); - break; - case QEvent::Resize: - emit widgetResized(m_widget->size()); - break; - case QEvent::PolishRequest: - m_widget->ensurePolished(); - break; - - default: - // Do nothing - break; - } - } - return false; -} - -QWidget *DSVideoWidgetControl::videoWidget() -{ - return m_widget; -} - -Qt::AspectRatioMode DSVideoWidgetControl::aspectRatioMode() const -{ - return m_aspectRatioMode; -} - -void DSVideoWidgetControl::setAspectRatioMode(Qt::AspectRatioMode ratio) -{ - if (m_aspectRatioMode==ratio) { - return; - } - m_aspectRatioMode = ratio; - - if (m_aspectRatioMode == Qt::KeepAspectRatio) - m_widget->setScaledContents(false); - else { - m_widget->setScaledContents(true); - } -} - -bool DSVideoWidgetControl::isFullScreen() const -{ - return m_fullScreen; -} - -void DSVideoWidgetControl::setFullScreen(bool fullScreen) -{ - if (m_widget && !fullScreen && m_fullScreen) { - m_widget->showNormal(); - m_fullScreen = false; - } else if (m_widget && fullScreen) { - m_widget->showFullScreen(); - m_fullScreen = true; - } - - emit fullScreenChanged(fullScreen); -} - -int DSVideoWidgetControl::brightness() const -{ - return 0; -} - -void DSVideoWidgetControl::setBrightness(int brightness) -{ - Q_UNUSED(brightness); -} - -int DSVideoWidgetControl::contrast() const -{ - return 0; -} - -void DSVideoWidgetControl::setContrast(int contrast) -{ - Q_UNUSED(contrast); -} - -int DSVideoWidgetControl::hue() const -{ - return 0; -} - -void DSVideoWidgetControl::setHue(int hue) -{ - Q_UNUSED(hue); -} - -int DSVideoWidgetControl::saturation() const -{ - return 0; -} - -void DSVideoWidgetControl::setSaturation(int saturation) -{ - Q_UNUSED(saturation); -} - -QT_END_NAMESPACE - -// End of file diff --git a/src/plugins/directshow/camera/dsvideowidgetcontrol.h b/src/plugins/directshow/camera/dsvideowidgetcontrol.h deleted file mode 100644 index 62eb502..0000000 --- a/src/plugins/directshow/camera/dsvideowidgetcontrol.h +++ /dev/null @@ -1,154 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DSVIDEOWIDGETCONTROL_H -#define DSVIDEOWIDGETCONTROL_H - -#include <QtCore/qobject.h> -#include <QtWidgets> -#include <QtMultimedia/qvideoframe.h> -#include <QtMultimedia/qabstractvideosurface.h> -#include <QtMultimedia/qvideosurfaceformat.h> - -#include <qvideowidgetcontrol.h> -#include "DsCameraControl.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class DSVideoWidgetSurface : public QAbstractVideoSurface -{ - Q_OBJECT - public: - DSVideoWidgetSurface(QLabel *pWidget, QObject *parent = 0); - - QList<QVideoFrame::PixelFormat> supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const; - - bool present(const QVideoFrame &frame); - - QRect videoRect() const { return targetRect; } - void updateVideoRect(); - - void paint(QPainter *painter); - void setImageFormat(QImage::Format fmt); - - private: - QLabel *widget; - QImage::Format imageFormat; - QRect targetRect; - QSize imageSize; - QRect sourceRect; - QPixmap* myPixmap; - }; - -class DSVideoWidgetControl : public QVideoWidgetControl -{ - Q_OBJECT - - DSVideoWidgetSurface* surface; -public: // Constructor & Destructor - - DSVideoWidgetControl(DSCameraSession* session, QObject *parent = 0); - virtual ~DSVideoWidgetControl(); - -public: // QVideoWidgetControl - - QWidget *videoWidget(); - - // Aspect Ratio - Qt::AspectRatioMode aspectRatioMode() const; - void setAspectRatioMode(Qt::AspectRatioMode ratio); - - // Full Screen - bool isFullScreen() const; - void setFullScreen(bool fullScreen); - - // Brightness - int brightness() const; - void setBrightness(int brightness); - - // Contrast - int contrast() const; - void setContrast(int contrast); - - // Hue - int hue() const; - void setHue(int hue); - - // Saturation - int saturation() const; - void setSaturation(int saturation); - -public: // Internal - - bool eventFilter(QObject *object, QEvent *event); - -/* -Q_SIGNALS: // QVideoWidgetControl - - void fullScreenChanged(bool fullScreen); - void brightnessChanged(int brightness); - void contrastChanged(int contrast); - void hueChanged(int hue); - void saturationChanged(int saturation); -*/ - -Q_SIGNALS: // Internal Signals - - void widgetResized(QSize size); - void widgetUpdated(); - -private: // Data - - DSCameraSession* m_session; - QLabel *m_widget; - WId m_windowId; - Qt::AspectRatioMode m_aspectRatioMode; - bool m_fullScreen; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // DSVideoWidgetControl_H diff --git a/src/plugins/directshow/directshow.pro b/src/plugins/directshow/directshow.pro deleted file mode 100644 index 80d588f..0000000 --- a/src/plugins/directshow/directshow.pro +++ /dev/null @@ -1,23 +0,0 @@ -TEMPLATE = lib - -CONFIG += plugin -TARGET = $$qtLibraryTarget(dsengine) - -PLUGIN_TYPE=mediaservice - -include (../../../common.pri) - -QT += multimedia - -DEPENDPATH += . - -HEADERS += dsserviceplugin.h -SOURCES += dsserviceplugin.cpp - -!contains(config_test_wmsdk, yes): DEFINES += QT_NO_WMSDK - -contains(config_test_wmf, no): include (player/player.pri) -include (camera/camera.pri) - -target.path += $$[QT_INSTALL_PLUGINS]/$${PLUGIN_TYPE} -INSTALLS += target diff --git a/src/plugins/directshow/dsserviceplugin.cpp b/src/plugins/directshow/dsserviceplugin.cpp deleted file mode 100644 index adfb025..0000000 --- a/src/plugins/directshow/dsserviceplugin.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qstring.h> -#include <QtCore/qdebug.h> -#include <QtCore/QFile> - -#include "dsserviceplugin.h" - - -#ifdef QMEDIA_DIRECTSHOW_CAMERA -#include <dshow.h> -#include "dscameraservice.h" -#endif - -#ifdef QMEDIA_DIRECTSHOW_PLAYER -#include "directshowplayerservice.h" -#endif - -#include <qmediaserviceprovider.h> - - -#ifdef QMEDIA_DIRECTSHOW_CAMERA - -extern const CLSID CLSID_VideoInputDeviceCategory; - - -#ifndef _STRSAFE_H_INCLUDED_ -#include <tchar.h> -#endif -#include <dshow.h> -#include <objbase.h> -#include <initguid.h> -#pragma comment(lib, "strmiids.lib") -#pragma comment(lib, "ole32.lib") -#include <windows.h> -#include <ocidl.h> -#endif - -QT_USE_NAMESPACE - -QStringList DSServicePlugin::keys() const -{ - return QStringList() -#ifdef QMEDIA_DIRECTSHOW_CAMERA - << QLatin1String(Q_MEDIASERVICE_CAMERA) -#endif -#ifdef QMEDIA_DIRECTSHOW_PLAYER - << QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER) -#endif - ; -} - -QMediaService* DSServicePlugin::create(QString const& key) -{ -#ifdef QMEDIA_DIRECTSHOW_CAMERA - if (key == QLatin1String(Q_MEDIASERVICE_CAMERA)) - return new DSCameraService; -#endif -#ifdef QMEDIA_DIRECTSHOW_PLAYER - if (key == QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER)) - return new DirectShowPlayerService; -#endif - - qDebug() << "unsupported key:" << key; - return 0; -} - -void DSServicePlugin::release(QMediaService *service) -{ - delete service; -} - -QMediaServiceProviderHint::Features DSServicePlugin::supportedFeatures( - const QByteArray &service) const -{ - if (service == Q_MEDIASERVICE_MEDIAPLAYER) - return QMediaServiceProviderHint::StreamPlayback | QMediaServiceProviderHint::VideoSurface; - else - return QMediaServiceProviderHint::Features(); -} - -QList<QByteArray> DSServicePlugin::devices(const QByteArray &service) const -{ -#ifdef QMEDIA_DIRECTSHOW_CAMERA - if (service == Q_MEDIASERVICE_CAMERA) { - if (m_cameraDevices.isEmpty()) - updateDevices(); - - return m_cameraDevices; - } -#endif - - return QList<QByteArray>(); -} - -QString DSServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device) -{ -#ifdef QMEDIA_DIRECTSHOW_CAMERA - if (service == Q_MEDIASERVICE_CAMERA) { - if (m_cameraDevices.isEmpty()) - updateDevices(); - - for (int i=0; i<m_cameraDevices.count(); i++) - if (m_cameraDevices[i] == device) - return m_cameraDescriptions[i]; - } -#endif - return QString(); -} - -#ifdef QMEDIA_DIRECTSHOW_CAMERA - -void DSServicePlugin::updateDevices() const -{ - m_cameraDevices.clear(); - m_cameraDescriptions.clear(); - BOOL bFound = TRUE; - CoInitialize(NULL); - ICreateDevEnum* pDevEnum = NULL; - IEnumMoniker* pEnum = NULL; - // Create the System device enumerator - HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, - CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, - reinterpret_cast<void**>(&pDevEnum)); - if(SUCCEEDED(hr)) { - // Create the enumerator for the video capture category - hr = pDevEnum->CreateClassEnumerator( - CLSID_VideoInputDeviceCategory, &pEnum, 0); - if (S_OK == hr) { - pEnum->Reset(); - // go through and find all video capture devices - IMoniker* pMoniker = NULL; - while(pEnum->Next(1, &pMoniker, NULL) == S_OK) { - IPropertyBag *pPropBag; - hr = pMoniker->BindToStorage(0,0,IID_IPropertyBag, - (void**)(&pPropBag)); - if(FAILED(hr)) { - pMoniker->Release(); - continue; // skip this one - } - bFound = TRUE; - // Find the description - WCHAR str[120]; - VARIANT varName; - varName.vt = VT_BSTR; - hr = pPropBag->Read(L"FriendlyName", &varName, 0); - if(SUCCEEDED(hr)) { - wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0])); - QString temp(QString::fromUtf16((unsigned short*)str)); - m_cameraDevices.append(QString("ds:%1").arg(temp).toLocal8Bit().constData()); - hr = pPropBag->Read(L"Description", &varName, 0); - wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0])); - QString temp2(QString::fromUtf16((unsigned short*)str)); - m_cameraDescriptions.append(temp2); - } else { - qWarning() << "No friendly name"; - } - pPropBag->Release(); - pMoniker->Release(); - } - pEnum->Release(); - } - pDevEnum->Release(); - } - CoUninitialize(); - if (!bFound) { - qWarning() << "No camera devices found"; - } -} -#endif - -Q_EXPORT_PLUGIN2(qtmedia_dsengine, DSServicePlugin); - diff --git a/src/plugins/directshow/dsserviceplugin.h b/src/plugins/directshow/dsserviceplugin.h deleted file mode 100644 index 6baa5d0..0000000 --- a/src/plugins/directshow/dsserviceplugin.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DSSERVICEPLUGIN_H -#define DSSERVICEPLUGIN_H - -#include "qmediaserviceproviderplugin.h" - -QT_USE_NAMESPACE - -class DSServicePlugin - : public QMediaServiceProviderPlugin - , public QMediaServiceSupportedDevicesInterface - , public QMediaServiceFeaturesInterface -{ - Q_OBJECT - Q_INTERFACES(QMediaServiceSupportedDevicesInterface) - Q_INTERFACES(QMediaServiceFeaturesInterface) -public: - QStringList keys() const; - QMediaService* create(QString const& key); - void release(QMediaService *service); - - QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const; - - QList<QByteArray> devices(const QByteArray &service) const; - QString deviceDescription(const QByteArray &service, const QByteArray &device); - -private: -#ifdef QMEDIA_DIRECTSHOW_CAMERA - void updateDevices() const; - - mutable QList<QByteArray> m_cameraDevices; - mutable QStringList m_cameraDescriptions; -#endif -}; - -#endif // DSSERVICEPLUGIN_H diff --git a/src/plugins/directshow/player/directshowaudioendpointcontrol.cpp b/src/plugins/directshow/player/directshowaudioendpointcontrol.cpp deleted file mode 100644 index 92272ff..0000000 --- a/src/plugins/directshow/player/directshowaudioendpointcontrol.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "directshowaudioendpointcontrol.h" - -#include "directshowglobal.h" -#include "directshowplayerservice.h" - -DirectShowAudioEndpointControl::DirectShowAudioEndpointControl( - DirectShowPlayerService *service, QObject *parent) - : QAudioEndpointSelector(parent) - , m_service(service) - , m_bindContext(0) - , m_deviceEnumerator(0) -{ - if (CreateBindCtx(0, &m_bindContext) == S_OK) { - m_deviceEnumerator = com_new<ICreateDevEnum>(CLSID_SystemDeviceEnum, IID_ICreateDevEnum); - - updateEndpoints(); - - setActiveEndpoint(m_defaultEndpoint); - } -} - -DirectShowAudioEndpointControl::~DirectShowAudioEndpointControl() -{ - foreach (IMoniker *moniker, m_devices) - moniker->Release(); - - if (m_bindContext) - m_bindContext->Release(); - - if (m_deviceEnumerator) - m_deviceEnumerator->Release(); -} - -QList<QString> DirectShowAudioEndpointControl::availableEndpoints() const -{ - return m_devices.keys(); -} - -QString DirectShowAudioEndpointControl::endpointDescription(const QString &name) const -{ -#ifdef __IPropertyBag_INTERFACE_DEFINED__ - QString description; - - if (IMoniker *moniker = m_devices.value(name, 0)) { - IPropertyBag *propertyBag = 0; - if (SUCCEEDED(moniker->BindToStorage( - 0, 0, IID_IPropertyBag, reinterpret_cast<void **>(&propertyBag)))) { - VARIANT name; - VariantInit(&name); - if (SUCCEEDED(propertyBag->Read(L"FriendlyName", &name, 0))) - description = QString::fromWCharArray(name.bstrVal); - VariantClear(&name); - propertyBag->Release(); - } - } - - return description; -#else - return name.section(QLatin1Char('\\'), -1); -#endif -} - -QString DirectShowAudioEndpointControl::defaultEndpoint() const -{ - return m_defaultEndpoint; -} - -QString DirectShowAudioEndpointControl::activeEndpoint() const -{ - return m_activeEndpoint; -} - -void DirectShowAudioEndpointControl::setActiveEndpoint(const QString &name) -{ - if (m_activeEndpoint == name) - return; - - if (IMoniker *moniker = m_devices.value(name, 0)) { - IBaseFilter *filter = 0; - - if (moniker->BindToObject( - m_bindContext, - 0, - IID_IBaseFilter, - reinterpret_cast<void **>(&filter)) == S_OK) { - m_service->setAudioOutput(filter); - - filter->Release(); - } - } -} - -void DirectShowAudioEndpointControl::updateEndpoints() -{ - IMalloc *oleMalloc = 0; - if (m_deviceEnumerator && CoGetMalloc(1, &oleMalloc) == S_OK) { - IEnumMoniker *monikers = 0; - - if (m_deviceEnumerator->CreateClassEnumerator( - CLSID_AudioRendererCategory, &monikers, 0) == S_OK) { - for (IMoniker *moniker = 0; monikers->Next(1, &moniker, 0) == S_OK; moniker->Release()) { - OLECHAR *string = 0; - if (moniker->GetDisplayName(m_bindContext, 0, &string) == S_OK) { - QString deviceId = QString::fromWCharArray(string); - oleMalloc->Free(string); - - moniker->AddRef(); - m_devices.insert(deviceId, moniker); - - if (m_defaultEndpoint.isEmpty() - || deviceId.endsWith(QLatin1String("Default DirectSound Device"))) { - m_defaultEndpoint = deviceId; - } - } - } - monikers->Release(); - } - oleMalloc->Release(); - } -} diff --git a/src/plugins/directshow/player/directshowaudioendpointcontrol.h b/src/plugins/directshow/player/directshowaudioendpointcontrol.h deleted file mode 100644 index f98f488..0000000 --- a/src/plugins/directshow/player/directshowaudioendpointcontrol.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DIRECTSHOWAUDIOENDPOINTCONTROL_H -#define DIRECTSHOWAUDIOENDPOINTCONTROL_H - -#include "qaudioendpointselector.h" - -#include <dshow.h> - -class DirectShowPlayerService; - -QT_USE_NAMESPACE - -class DirectShowAudioEndpointControl : public QAudioEndpointSelector -{ - Q_OBJECT -public: - DirectShowAudioEndpointControl(DirectShowPlayerService *service, QObject *parent = 0); - ~DirectShowAudioEndpointControl(); - - QList<QString> availableEndpoints() const; - - QString endpointDescription(const QString &name) const; - - QString defaultEndpoint() const; - QString activeEndpoint() const; - - void setActiveEndpoint(const QString& name); - -private: - void updateEndpoints(); - - DirectShowPlayerService *m_service; - IBindCtx *m_bindContext; - ICreateDevEnum *m_deviceEnumerator; - - QMap<QString, IMoniker *> m_devices; - QString m_defaultEndpoint; - QString m_activeEndpoint; -}; - -#endif - diff --git a/src/plugins/directshow/player/directshoweventloop.cpp b/src/plugins/directshow/player/directshoweventloop.cpp deleted file mode 100644 index 69efb9f..0000000 --- a/src/plugins/directshow/player/directshoweventloop.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <directshoweventloop.h> - -#include <QtCore/qcoreapplication.h> -#include <QtCore/qcoreevent.h> - -class DirectShowPostedEvent -{ -public: - DirectShowPostedEvent(QObject *receiver, QEvent *event) - : receiver(receiver) - , event(event) - , next(0) - { - } - - ~DirectShowPostedEvent() - { - delete event; - } - - QObject *receiver; - QEvent *event; - DirectShowPostedEvent *next; -}; - -DirectShowEventLoop::DirectShowEventLoop(QObject *parent) - : QObject(parent) - , m_postsHead(0) - , m_postsTail(0) - , m_eventHandle(::CreateEvent(0, 0, 0, 0)) - , m_waitHandle(::CreateEvent(0, 0, 0, 0)) -{ -} - -DirectShowEventLoop::~DirectShowEventLoop() -{ - ::CloseHandle(m_eventHandle); - ::CloseHandle(m_waitHandle); - - for (DirectShowPostedEvent *post = m_postsHead; post; post = m_postsHead) { - m_postsHead = m_postsHead->next; - - delete post; - } -} - -void DirectShowEventLoop::wait(QMutex *mutex) -{ - ::ResetEvent(m_waitHandle); - - mutex->unlock(); - - HANDLE handles[] = { m_eventHandle, m_waitHandle }; - while (::WaitForMultipleObjects(2, handles, false, INFINITE) == WAIT_OBJECT_0) - processEvents(); - - mutex->lock(); -} - -void DirectShowEventLoop::wake() -{ - ::SetEvent(m_waitHandle); -} - -void DirectShowEventLoop::postEvent(QObject *receiver, QEvent *event) -{ - QMutexLocker locker(&m_mutex); - - DirectShowPostedEvent *post = new DirectShowPostedEvent(receiver, event); - - if (m_postsTail) - m_postsTail->next = post; - else - m_postsHead = post; - - m_postsTail = post; - - QCoreApplication::postEvent(this, new QEvent(QEvent::User)); - ::SetEvent(m_eventHandle); -} - -void DirectShowEventLoop::customEvent(QEvent *event) -{ - if (event->type() == QEvent::User) { - processEvents(); - } else { - QObject::customEvent(event); - } -} - -void DirectShowEventLoop::processEvents() -{ - QMutexLocker locker(&m_mutex); - - ::ResetEvent(m_eventHandle); - - while(m_postsHead) { - DirectShowPostedEvent *post = m_postsHead; - m_postsHead = m_postsHead->next; - - if (!m_postsHead) - m_postsTail = 0; - - locker.unlock(); - QCoreApplication::sendEvent(post->receiver, post->event); - delete post; - locker.relock(); - } -} diff --git a/src/plugins/directshow/player/directshoweventloop.h b/src/plugins/directshow/player/directshoweventloop.h deleted file mode 100644 index cea4c5f..0000000 --- a/src/plugins/directshow/player/directshoweventloop.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DIRECTSHOWEVENTLOOP_H -#define DIRECTSHOWEVENTLOOP_H - -#include <QtCore/qmutex.h> -#include <QtCore/qobject.h> -#include <QtCore/qwaitcondition.h> - -#include <windows.h> - -class DirectShowPostedEvent; - -class DirectShowEventLoop : public QObject -{ - Q_OBJECT -public: - DirectShowEventLoop(QObject *parent = 0); - ~DirectShowEventLoop(); - - void wait(QMutex *mutex); - void wake(); - - void postEvent(QObject *object, QEvent *event); - -protected: - void customEvent(QEvent *event); - -private: - void processEvents(); - - DirectShowPostedEvent *m_postsHead; - DirectShowPostedEvent *m_postsTail; - HANDLE m_eventHandle; - HANDLE m_waitHandle; - QMutex m_mutex; -}; - -#endif diff --git a/src/plugins/directshow/player/directshowglobal.h b/src/plugins/directshow/player/directshowglobal.h deleted file mode 100644 index f209805..0000000 --- a/src/plugins/directshow/player/directshowglobal.h +++ /dev/null @@ -1,139 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DIRECTSHOWGLOBAL_H -#define DIRECTSHOWGLOBAL_H - -#include <QtCore/qglobal.h> - -#include <dshow.h> - -template <typename T> T *com_cast(IUnknown *unknown, const IID &iid) -{ - T *iface = 0; - return unknown && unknown->QueryInterface(iid, reinterpret_cast<void **>(&iface)) == S_OK - ? iface - : 0; -} - -template <typename T> T *com_new(const IID &clsid, const IID &iid) -{ - T *object = 0; - return CoCreateInstance( - clsid, - NULL, - CLSCTX_INPROC_SERVER, - iid, - reinterpret_cast<void **>(&object)) == S_OK - ? object - : 0; -} - -#ifndef __IFilterGraph2_INTERFACE_DEFINED__ -#define __IFilterGraph2_INTERFACE_DEFINED__ -#define INTERFACE IFilterGraph2 -DECLARE_INTERFACE_(IFilterGraph2 ,IGraphBuilder) -{ - STDMETHOD(AddSourceFilterForMoniker)(THIS_ IMoniker *, IBindCtx *, LPCWSTR,IBaseFilter **) PURE; - STDMETHOD(ReconnectEx)(THIS_ IPin *, const AM_MEDIA_TYPE *) PURE; - STDMETHOD(RenderEx)(IPin *, DWORD, DWORD *) PURE; -}; -#undef INTERFACE -#endif - -#ifndef __IAMFilterMiscFlags_INTERFACE_DEFINED__ -#define __IAMFilterMiscFlags_INTERFACE_DEFINED__ -#define INTERFACE IAMFilterMiscFlags -DECLARE_INTERFACE_(IAMFilterMiscFlags ,IUnknown) -{ - STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE; - STDMETHOD_(ULONG,AddRef)(THIS) PURE; - STDMETHOD_(ULONG,Release)(THIS) PURE; - STDMETHOD_(ULONG,GetMiscFlags)(THIS) PURE; -}; -#undef INTERFACE -#endif - -#ifndef __IFileSourceFilter_INTERFACE_DEFINED__ -#define __IFileSourceFilter_INTERFACE_DEFINED__ -#define INTERFACE IFileSourceFilter -DECLARE_INTERFACE_(IFileSourceFilter ,IUnknown) -{ - STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE; - STDMETHOD_(ULONG,AddRef)(THIS) PURE; - STDMETHOD_(ULONG,Release)(THIS) PURE; - STDMETHOD(Load)(THIS_ LPCOLESTR, const AM_MEDIA_TYPE *) PURE; - STDMETHOD(GetCurFile)(THIS_ LPOLESTR *ppszFileName, AM_MEDIA_TYPE *) PURE; -}; -#undef INTERFACE -#endif - -#ifndef __IAMOpenProgress_INTERFACE_DEFINED__ -#define __IAMOpenProgress_INTERFACE_DEFINED__ -#define INTERFACE IAMOpenProgress -DECLARE_INTERFACE_(IAMOpenProgress ,IUnknown) -{ - STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE; - STDMETHOD_(ULONG,AddRef)(THIS) PURE; - STDMETHOD_(ULONG,Release)(THIS) PURE; - STDMETHOD(QueryProgress)(THIS_ LONGLONG *, LONGLONG *) PURE; - STDMETHOD(AbortOperation)(THIS) PURE; -}; -#undef INTERFACE -#endif - -#ifndef __IFilterChain_INTERFACE_DEFINED__ -#define __IFilterChain_INTERFACE_DEFINED__ -#define INTERFACE IFilterChain -DECLARE_INTERFACE_(IFilterChain ,IUnknown) -{ - STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE; - STDMETHOD_(ULONG,AddRef)(THIS) PURE; - STDMETHOD_(ULONG,Release)(THIS) PURE; - STDMETHOD(StartChain)(IBaseFilter *, IBaseFilter *) PURE; - STDMETHOD(PauseChain)(IBaseFilter *, IBaseFilter *) PURE; - STDMETHOD(StopChain)(IBaseFilter *, IBaseFilter *) PURE; - STDMETHOD(RemoveChain)(IBaseFilter *, IBaseFilter *) PURE; -}; -#undef INTERFACE -#endif - -#endif diff --git a/src/plugins/directshow/player/directshowioreader.cpp b/src/plugins/directshow/player/directshowioreader.cpp deleted file mode 100644 index 71208f7..0000000 --- a/src/plugins/directshow/player/directshowioreader.cpp +++ /dev/null @@ -1,496 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "directshowioreader.h" - -#include "directshoweventloop.h" -#include "directshowglobal.h" -#include "directshowiosource.h" - -#include <QtCore/qcoreapplication.h> -#include <QtCore/qcoreevent.h> -#include <QtCore/qiodevice.h> -#include <QtCore/qthread.h> - -class DirectShowSampleRequest -{ -public: - DirectShowSampleRequest( - IMediaSample *sample, DWORD_PTR userData, LONGLONG position, LONG length, BYTE *buffer) - : next(0) - , sample(sample) - , userData(userData) - , position(position) - , length(length) - , buffer(buffer) - , result(S_FALSE) - { - } - - DirectShowSampleRequest *remove() { DirectShowSampleRequest *n = next; delete this; return n; } - - DirectShowSampleRequest *next; - IMediaSample *sample; - DWORD_PTR userData; - LONGLONG position; - LONG length; - BYTE *buffer; - HRESULT result; -}; - -DirectShowIOReader::DirectShowIOReader( - QIODevice *device, DirectShowIOSource *source, DirectShowEventLoop *loop) - : m_source(source) - , m_device(device) - , m_loop(loop) - , m_pendingHead(0) - , m_pendingTail(0) - , m_readyHead(0) - , m_readyTail(0) - , m_synchronousPosition(0) - , m_synchronousLength(0) - , m_synchronousBytesRead(0) - , m_synchronousBuffer(0) - , m_synchronousResult(S_OK) - , m_totalLength(0) - , m_availableLength(0) - , m_flushing(false) -{ - moveToThread(device->thread()); - - connect(device, SIGNAL(readyRead()), this, SLOT(readyRead())); -} - -DirectShowIOReader::~DirectShowIOReader() -{ - flushRequests(); -} - -HRESULT DirectShowIOReader::QueryInterface(REFIID riid, void **ppvObject) -{ - return m_source->QueryInterface(riid, ppvObject); -} - -ULONG DirectShowIOReader::AddRef() -{ - return m_source->AddRef(); -} - -ULONG DirectShowIOReader::Release() -{ - return m_source->Release(); -} - -// IAsyncReader -HRESULT DirectShowIOReader::RequestAllocator( - IMemAllocator *pPreferred, ALLOCATOR_PROPERTIES *pProps, IMemAllocator **ppActual) -{ - if (!ppActual || !pProps) { - return E_POINTER; - } else { - ALLOCATOR_PROPERTIES actualProperties; - - if (pProps->cbAlign == 0) - pProps->cbAlign = 1; - - if (pPreferred && pPreferred->SetProperties(pProps, &actualProperties) == S_OK) { - pPreferred->AddRef(); - - *ppActual = pPreferred; - - m_source->setAllocator(*ppActual); - - return S_OK; - } else { - *ppActual = com_new<IMemAllocator>(CLSID_MemoryAllocator, IID_IMemAllocator); - - if (*ppActual) { - if ((*ppActual)->SetProperties(pProps, &actualProperties) != S_OK) { - (*ppActual)->Release(); - } else { - m_source->setAllocator(*ppActual); - - return S_OK; - } - } - } - ppActual = 0; - - return E_FAIL; - } -} - -HRESULT DirectShowIOReader::Request(IMediaSample *pSample, DWORD_PTR dwUser) -{ - QMutexLocker locker(&m_mutex); - - if (!pSample) { - return E_POINTER; - } else if (m_flushing) { - return VFW_E_WRONG_STATE; - } else { - REFERENCE_TIME startTime = 0; - REFERENCE_TIME endTime = 0; - BYTE *buffer; - - if (pSample->GetTime(&startTime, &endTime) != S_OK - || pSample->GetPointer(&buffer) != S_OK) { - return VFW_E_SAMPLE_TIME_NOT_SET; - } else { - LONGLONG position = startTime / 10000000; - LONG length = (endTime - startTime) / 10000000; - - DirectShowSampleRequest *request = new DirectShowSampleRequest( - pSample, dwUser, position, length, buffer); - - if (m_pendingTail) { - m_pendingTail->next = request; - } else { - m_pendingHead = request; - - m_loop->postEvent(this, new QEvent(QEvent::User)); - } - m_pendingTail = request; - - return S_OK; - } - } -} - -HRESULT DirectShowIOReader::WaitForNext( - DWORD dwTimeout, IMediaSample **ppSample, DWORD_PTR *pdwUser) -{ - if (!ppSample || !pdwUser) - return E_POINTER; - - QMutexLocker locker(&m_mutex); - - do { - if (m_readyHead) { - DirectShowSampleRequest *request = m_readyHead; - - *ppSample = request->sample; - *pdwUser = request->userData; - - HRESULT hr = request->result; - - m_readyHead = request->next; - - if (!m_readyHead) - m_readyTail = 0; - - delete request; - - return hr; - } else if (m_flushing) { - *ppSample = 0; - *pdwUser = 0; - - return VFW_E_WRONG_STATE; - } - } while (m_wait.wait(&m_mutex, dwTimeout)); - - *ppSample = 0; - *pdwUser = 0; - - return VFW_E_TIMEOUT; -} - -HRESULT DirectShowIOReader::SyncReadAligned(IMediaSample *pSample) -{ - if (!pSample) { - return E_POINTER; - } else { - REFERENCE_TIME startTime = 0; - REFERENCE_TIME endTime = 0; - BYTE *buffer; - - if (pSample->GetTime(&startTime, &endTime) != S_OK - || pSample->GetPointer(&buffer) != S_OK) { - return VFW_E_SAMPLE_TIME_NOT_SET; - } else { - LONGLONG position = startTime / 10000000; - LONG length = (endTime - startTime) / 10000000; - - QMutexLocker locker(&m_mutex); - - if (thread() == QThread::currentThread()) { - qint64 bytesRead = 0; - - HRESULT hr = blockingRead(position, length, buffer, &bytesRead); - - if (SUCCEEDED(hr)) - pSample->SetActualDataLength(bytesRead); - - return hr; - } else { - m_synchronousPosition = position; - m_synchronousLength = length; - m_synchronousBuffer = buffer; - - m_loop->postEvent(this, new QEvent(QEvent::User)); - - m_wait.wait(&m_mutex); - - m_synchronousBuffer = 0; - - if (SUCCEEDED(m_synchronousResult)) - pSample->SetActualDataLength(m_synchronousBytesRead); - - return m_synchronousResult; - } - } - } -} - -HRESULT DirectShowIOReader::SyncRead(LONGLONG llPosition, LONG lLength, BYTE *pBuffer) -{ - if (!pBuffer) { - return E_POINTER; - } else { - if (thread() == QThread::currentThread()) { - qint64 bytesRead; - - return blockingRead(llPosition, lLength, pBuffer, &bytesRead); - } else { - QMutexLocker locker(&m_mutex); - - m_synchronousPosition = llPosition; - m_synchronousLength = lLength; - m_synchronousBuffer = pBuffer; - - m_loop->postEvent(this, new QEvent(QEvent::User)); - - m_wait.wait(&m_mutex); - - m_synchronousBuffer = 0; - - return m_synchronousResult; - } - } -} - -HRESULT DirectShowIOReader::Length(LONGLONG *pTotal, LONGLONG *pAvailable) -{ - if (!pTotal || !pAvailable) { - return E_POINTER; - } else { - QMutexLocker locker(&m_mutex); - - *pTotal = m_totalLength; - *pAvailable = m_availableLength; - - return S_OK; - } -} - - -HRESULT DirectShowIOReader::BeginFlush() -{ - QMutexLocker locker(&m_mutex); - - if (m_flushing) - return S_FALSE; - - m_flushing = true; - - flushRequests(); - - m_wait.wakeAll(); - - return S_OK; -} - -HRESULT DirectShowIOReader::EndFlush() -{ - QMutexLocker locker(&m_mutex); - - if (!m_flushing) - return S_FALSE; - - m_flushing = false; - - return S_OK; -} - -void DirectShowIOReader::customEvent(QEvent *event) -{ - if (event->type() == QEvent::User) { - readyRead(); - } else { - QObject::customEvent(event); - } -} - -void DirectShowIOReader::readyRead() -{ - QMutexLocker locker(&m_mutex); - - m_availableLength = m_device->bytesAvailable() + m_device->pos(); - m_totalLength = m_device->size(); - - if (m_synchronousBuffer) { - if (nonBlockingRead( - m_synchronousPosition, - m_synchronousLength, - m_synchronousBuffer, - &m_synchronousBytesRead, - &m_synchronousResult)) { - m_wait.wakeAll(); - } - } else { - qint64 bytesRead = 0; - - while (m_pendingHead && nonBlockingRead( - m_pendingHead->position, - m_pendingHead->length, - m_pendingHead->buffer, - &bytesRead, - &m_pendingHead->result)) { - m_pendingHead->sample->SetActualDataLength(bytesRead); - - if (m_readyTail) - m_readyTail->next = m_pendingHead; - m_readyTail = m_pendingHead; - - m_pendingHead = m_pendingHead->next; - - m_readyTail->next = 0; - - if (!m_pendingHead) - m_pendingTail = 0; - - if (!m_readyHead) - m_readyHead = m_readyTail; - - m_wait.wakeAll(); - } - } -} - -HRESULT DirectShowIOReader::blockingRead( - LONGLONG position, LONG length, BYTE *buffer, qint64 *bytesRead) -{ - *bytesRead = 0; - - if (qint64(position) > m_device->size()) - return S_FALSE; - - const qint64 maxSize = qMin<qint64>(m_device->size(), position + length); - - while (m_device->bytesAvailable() + m_device->pos() < maxSize) { - if (!m_device->waitForReadyRead(-1)) - return S_FALSE; - } - - if (m_device->pos() != position && !m_device->seek(position)) - return S_FALSE; - - const qint64 maxBytes = qMin<qint64>(length, m_device->bytesAvailable()); - - *bytesRead = m_device->read(reinterpret_cast<char *>(buffer), maxBytes); - - if (*bytesRead != length) { - qMemSet(buffer + *bytesRead, 0, length - *bytesRead); - - return S_FALSE; - } else { - return S_OK; - } -} - -bool DirectShowIOReader::nonBlockingRead( - LONGLONG position, LONG length, BYTE *buffer, qint64 *bytesRead, HRESULT *result) -{ - const qint64 maxSize = qMin<qint64>(m_device->size(), position + length); - - if (position > m_device->size()) { - *bytesRead = 0; - *result = S_FALSE; - - return true; - } else if (m_device->bytesAvailable() + m_device->pos() >= maxSize) { - if (m_device->pos() != position && !m_device->seek(position)) { - *bytesRead = 0; - *result = S_FALSE; - - return true; - } else { - const qint64 maxBytes = qMin<qint64>(length, m_device->bytesAvailable()); - - *bytesRead = m_device->read(reinterpret_cast<char *>(buffer), maxBytes); - - if (*bytesRead != length) { - qMemSet(buffer + *bytesRead, 0, length - *bytesRead); - - *result = S_FALSE; - } else { - *result = S_OK; - } - - return true; - } - } else { - return false; - } -} - -void DirectShowIOReader::flushRequests() -{ - while (m_pendingHead) { - m_pendingHead->result = VFW_E_WRONG_STATE; - - if (m_readyTail) - m_readyTail->next = m_pendingHead; - - m_readyTail = m_pendingHead; - - m_pendingHead = m_pendingHead->next; - - m_readyTail->next = 0; - - if (!m_pendingHead) - m_pendingTail = 0; - - if (!m_readyHead) - m_readyHead = m_readyTail; - } -} diff --git a/src/plugins/directshow/player/directshowioreader.h b/src/plugins/directshow/player/directshowioreader.h deleted file mode 100644 index 6056baf..0000000 --- a/src/plugins/directshow/player/directshowioreader.h +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DIRECTSHOWIOREADER_H -#define DIRECTSHOWIOREADER_H - -#include <QtCore/qmutex.h> -#include <QtCore/qobject.h> -#include <QtCore/qwaitcondition.h> - -#include <dshow.h> - -QT_BEGIN_NAMESPACE -class QIODevice; -QT_END_NAMESPACE - -class DirectShowEventLoop; -class DirectShowIOSource; -class DirectShowSampleRequest; - -class DirectShowIOReader : public QObject, public IAsyncReader -{ - Q_OBJECT -public: - DirectShowIOReader(QIODevice *device, DirectShowIOSource *source, DirectShowEventLoop *loop); - ~DirectShowIOReader(); - - // IUnknown - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); - ULONG STDMETHODCALLTYPE AddRef(); - ULONG STDMETHODCALLTYPE Release(); - - // IAsyncReader - HRESULT STDMETHODCALLTYPE RequestAllocator( - IMemAllocator *pPreferred, ALLOCATOR_PROPERTIES *pProps, IMemAllocator **ppActual); - - HRESULT STDMETHODCALLTYPE Request(IMediaSample *pSample, DWORD_PTR dwUser); - - HRESULT STDMETHODCALLTYPE WaitForNext( - DWORD dwTimeout, IMediaSample **ppSample, DWORD_PTR *pdwUser); - - HRESULT STDMETHODCALLTYPE SyncReadAligned(IMediaSample *pSample); - - HRESULT STDMETHODCALLTYPE SyncRead(LONGLONG llPosition, LONG lLength, BYTE *pBuffer); - - HRESULT STDMETHODCALLTYPE Length(LONGLONG *pTotal, LONGLONG *pAvailable); - - HRESULT STDMETHODCALLTYPE BeginFlush(); - HRESULT STDMETHODCALLTYPE EndFlush(); - -protected: - void customEvent(QEvent *event); - -private Q_SLOTS: - void readyRead(); - -private: - HRESULT blockingRead(LONGLONG position, LONG length, BYTE *buffer, qint64 *bytesRead); - bool nonBlockingRead( - LONGLONG position, LONG length, BYTE *buffer, qint64 *bytesRead, HRESULT *result); - void flushRequests(); - - DirectShowIOSource *m_source; - QIODevice *m_device; - DirectShowEventLoop *m_loop; - DirectShowSampleRequest *m_pendingHead; - DirectShowSampleRequest *m_pendingTail; - DirectShowSampleRequest *m_readyHead; - DirectShowSampleRequest *m_readyTail; - LONGLONG m_synchronousPosition; - LONG m_synchronousLength; - qint64 m_synchronousBytesRead; - BYTE *m_synchronousBuffer; - HRESULT m_synchronousResult; - LONGLONG m_totalLength; - LONGLONG m_availableLength; - bool m_flushing; - QMutex m_mutex; - QWaitCondition m_wait; -}; - -#endif diff --git a/src/plugins/directshow/player/directshowiosource.cpp b/src/plugins/directshow/player/directshowiosource.cpp deleted file mode 100644 index 8445a03..0000000 --- a/src/plugins/directshow/player/directshowiosource.cpp +++ /dev/null @@ -1,639 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "directshowiosource.h" - -#include "directshowglobal.h" -#include "directshowmediatype.h" -#include "directshowpinenum.h" - -#include <QtCore/qcoreapplication.h> -#include <QtCore/qurl.h> - -static const GUID directshow_subtypes[] = -{ - MEDIASUBTYPE_Avi, - MEDIASUBTYPE_WAVE, - MEDIASUBTYPE_NULL -}; - -DirectShowIOSource::DirectShowIOSource(DirectShowEventLoop *loop) - : m_ref(1) - , m_state(State_Stopped) - , m_reader(0) - , m_loop(loop) - , m_graph(0) - , m_clock(0) - , m_allocator(0) - , m_peerPin(0) - , m_pinId(QLatin1String("Data")) -{ - QVector<AM_MEDIA_TYPE> mediaTypes; - - AM_MEDIA_TYPE type = - { - MEDIATYPE_Stream, // majortype - MEDIASUBTYPE_NULL, // subtype - TRUE, // bFixedSizeSamples - FALSE, // bTemporalCompression - 1, // lSampleSize - GUID_NULL, // formattype - 0, // pUnk - 0, // cbFormat - 0, // pbFormat - }; - - static const int count = sizeof(directshow_subtypes) / sizeof(GUID); - - for (int i = 0; i < count; ++i) { - type.subtype = directshow_subtypes[i]; - mediaTypes.append(type); - } - - setMediaTypes(mediaTypes); -} - -DirectShowIOSource::~DirectShowIOSource() -{ - Q_ASSERT(m_ref == 0); - - delete m_reader; -} - -void DirectShowIOSource::setDevice(QIODevice *device) -{ - Q_ASSERT(!m_reader); - - m_reader = new DirectShowIOReader(device, this, m_loop); -} - -void DirectShowIOSource::setAllocator(IMemAllocator *allocator) -{ - if (m_allocator) - m_allocator->Release(); - - m_allocator = allocator; - - if (m_allocator) - m_allocator->AddRef(); -} - -// IUnknown -HRESULT DirectShowIOSource::QueryInterface(REFIID riid, void **ppvObject) -{ - // 2dd74950-a890-11d1-abe8-00a0c905f375 - static const GUID iid_IAmFilterMiscFlags = { - 0x2dd74950, 0xa890, 0x11d1, {0xab, 0xe8, 0x00, 0xa0, 0xc9, 0x05, 0xf3, 0x75}}; - - if (!ppvObject) { - return E_POINTER; - } else if (riid == IID_IUnknown - || riid == IID_IPersist - || riid == IID_IMediaFilter - || riid == IID_IBaseFilter) { - *ppvObject = static_cast<IBaseFilter *>(this); - } else if (riid == iid_IAmFilterMiscFlags) { - *ppvObject = static_cast<IAMFilterMiscFlags *>(this); - } else if (riid == IID_IPin) { - *ppvObject = static_cast<IPin *>(this); - } else if (riid == IID_IAsyncReader) { - *ppvObject = static_cast<IAsyncReader *>(m_reader); - } else { - *ppvObject = 0; - - return E_NOINTERFACE; - } - - AddRef(); - - return S_OK; -} - -ULONG DirectShowIOSource::AddRef() -{ - return InterlockedIncrement(&m_ref); -} - -ULONG DirectShowIOSource::Release() -{ - ULONG ref = InterlockedDecrement(&m_ref); - - if (ref == 0) { - delete this; - } - - return ref; -} - -// IPersist -HRESULT DirectShowIOSource::GetClassID(CLSID *pClassID) -{ - *pClassID = CLSID_NULL; - - return S_OK; -} - -// IMediaFilter -HRESULT DirectShowIOSource::Run(REFERENCE_TIME tStart) -{ - QMutexLocker locker(&m_mutex); - - m_state = State_Running; - - return S_OK; -} - -HRESULT DirectShowIOSource::Pause() -{ - QMutexLocker locker(&m_mutex); - - m_state = State_Paused; - - return S_OK; -} - -HRESULT DirectShowIOSource::Stop() -{ - QMutexLocker locker(&m_mutex); - - m_state = State_Stopped; - - return S_OK; -} - -HRESULT DirectShowIOSource::GetState(DWORD dwMilliSecsTimeout, FILTER_STATE *pState) -{ - Q_UNUSED(dwMilliSecsTimeout); - - if (!pState) { - return E_POINTER; - } else { - QMutexLocker locker(&m_mutex); - - *pState = m_state; - - return S_OK; - } -} - -HRESULT DirectShowIOSource::SetSyncSource(IReferenceClock *pClock) -{ - QMutexLocker locker(&m_mutex); - - if (m_clock) - m_clock->Release(); - - m_clock = pClock; - - if (m_clock) - m_clock->AddRef(); - - return S_OK; -} - -HRESULT DirectShowIOSource::GetSyncSource(IReferenceClock **ppClock) -{ - if (!ppClock) { - return E_POINTER; - } else { - if (!m_clock) { - *ppClock = 0; - - return S_FALSE; - } else { - m_clock->AddRef(); - - *ppClock = m_clock; - - return S_OK; - } - } -} - -// IBaseFilter -HRESULT DirectShowIOSource::EnumPins(IEnumPins **ppEnum) -{ - if (!ppEnum) { - return E_POINTER; - } else { - *ppEnum = new DirectShowPinEnum(QList<IPin *>() << this); - - return S_OK; - } -} - -HRESULT DirectShowIOSource::FindPin(LPCWSTR Id, IPin **ppPin) -{ - if (!ppPin || !Id) { - return E_POINTER; - } else { - QMutexLocker locker(&m_mutex); - if (QString::fromWCharArray(Id) == m_pinId) { - AddRef(); - - *ppPin = this; - - return S_OK; - } else { - *ppPin = 0; - - return VFW_E_NOT_FOUND; - } - } -} - -HRESULT DirectShowIOSource::JoinFilterGraph(IFilterGraph *pGraph, LPCWSTR pName) -{ - QMutexLocker locker(&m_mutex); - - m_graph = pGraph; - m_filterName = QString::fromWCharArray(pName); - - return S_OK; -} - -HRESULT DirectShowIOSource::QueryFilterInfo(FILTER_INFO *pInfo) -{ - if (!pInfo) { - return E_POINTER; - } else { - QString name = m_filterName; - - if (name.length() >= MAX_FILTER_NAME) - name.truncate(MAX_FILTER_NAME - 1); - - int length = name.toWCharArray(pInfo->achName); - pInfo->achName[length] = '\0'; - - if (m_graph) - m_graph->AddRef(); - - pInfo->pGraph = m_graph; - - return S_OK; - } -} - -HRESULT DirectShowIOSource::QueryVendorInfo(LPWSTR *pVendorInfo) -{ - Q_UNUSED(pVendorInfo); - - return E_NOTIMPL; -} - -// IAMFilterMiscFlags -ULONG DirectShowIOSource::GetMiscFlags() -{ - return AM_FILTER_MISC_FLAGS_IS_SOURCE; -} - -// IPin -HRESULT DirectShowIOSource::Connect(IPin *pReceivePin, const AM_MEDIA_TYPE *pmt) -{ - QMutexLocker locker(&m_mutex); - if (!pReceivePin) { - return E_POINTER; - } else if (m_state != State_Stopped) { - return VFW_E_NOT_STOPPED; - } else if (m_peerPin) { - return VFW_E_ALREADY_CONNECTED; - } else { - HRESULT hr = VFW_E_TYPE_NOT_ACCEPTED; - - m_peerPin = pReceivePin; - m_peerPin->AddRef(); - - if (!pmt) { - IEnumMediaTypes *mediaTypes = 0; - if (pReceivePin->EnumMediaTypes(&mediaTypes) == S_OK) { - for (AM_MEDIA_TYPE *type = 0; - mediaTypes->Next(1, &type, 0) == S_OK; - DirectShowMediaType::deleteType(type)) { - switch (tryConnect(pReceivePin, type)) { - case S_OK: - DirectShowMediaType::freeData(type); - mediaTypes->Release(); - return S_OK; - case VFW_E_NO_TRANSPORT: - hr = VFW_E_NO_TRANSPORT; - break; - default: - break; - } - } - mediaTypes->Release(); - } - AM_MEDIA_TYPE type = - { - MEDIATYPE_Stream, // majortype - MEDIASUBTYPE_NULL, // subtype - TRUE, // bFixedSizeSamples - FALSE, // bTemporalCompression - 1, // lSampleSize - GUID_NULL, // formattype - 0, // pUnk - 0, // cbFormat - 0, // pbFormat - }; - - static const int count = sizeof(directshow_subtypes) / sizeof(GUID); - - for (int i = 0; i < count; ++i) { - type.subtype = directshow_subtypes[i]; - - switch (tryConnect(pReceivePin, &type)) { - case S_OK: - return S_OK; - case VFW_E_NO_TRANSPORT: - hr = VFW_E_NO_TRANSPORT; - break; - default: - break; - } - } - } else if (pmt->majortype == MEDIATYPE_Stream && (hr = tryConnect(pReceivePin, pmt))) { - return S_OK; - } - - m_peerPin->Release(); - m_peerPin = 0; - - m_mediaType.clear(); - - return hr; - } -} - -HRESULT DirectShowIOSource::tryConnect(IPin *pin, const AM_MEDIA_TYPE *type) -{ - m_mediaType = *type; - - HRESULT hr = pin->ReceiveConnection(this, type); - - if (!SUCCEEDED(hr)) { - if (m_allocator) { - m_allocator->Release(); - m_allocator = 0; - } - } else if (!m_allocator) { - hr = VFW_E_NO_TRANSPORT; - - if (IMemInputPin *memPin = com_cast<IMemInputPin>(pin, IID_IMemInputPin)) { - if ((m_allocator = com_new<IMemAllocator>(CLSID_MemoryAllocator, IID_IMemAllocator))) { - ALLOCATOR_PROPERTIES properties; - if (memPin->GetAllocatorRequirements(&properties) == S_OK - || m_allocator->GetProperties(&properties) == S_OK) { - if (properties.cbAlign == 0) - properties.cbAlign = 1; - - ALLOCATOR_PROPERTIES actualProperties; - if (SUCCEEDED(hr = m_allocator->SetProperties(&properties, &actualProperties))) - hr = memPin->NotifyAllocator(m_allocator, TRUE); - } - if (!SUCCEEDED(hr)) { - m_allocator->Release(); - m_allocator = 0; - } - } - memPin->Release(); - } - if (!SUCCEEDED(hr)) - pin->Disconnect(); - } - return hr; -} - -HRESULT DirectShowIOSource::ReceiveConnection(IPin *pConnector, const AM_MEDIA_TYPE *pmt) -{ - Q_UNUSED(pConnector); - Q_UNUSED(pmt); - // Output pin. - return E_NOTIMPL; -} - -HRESULT DirectShowIOSource::Disconnect() -{ - if (!m_peerPin) { - return S_FALSE; - } else if (m_state != State_Stopped) { - return VFW_E_NOT_STOPPED; - } else { - HRESULT hr = m_peerPin->Disconnect(); - - if (!SUCCEEDED(hr)) - return hr; - - if (m_allocator) { - m_allocator->Release(); - m_allocator = 0; - } - - m_peerPin->Release(); - m_peerPin = 0; - - m_mediaType.clear(); - - return S_OK; - } -} - -HRESULT DirectShowIOSource::ConnectedTo(IPin **ppPin) -{ - if (!ppPin) { - return E_POINTER; - } else { - QMutexLocker locker(&m_mutex); - - if (!m_peerPin) { - *ppPin = 0; - - return VFW_E_NOT_CONNECTED; - } else { - m_peerPin->AddRef(); - - *ppPin = m_peerPin; - - return S_OK; - } - } -} - -HRESULT DirectShowIOSource::ConnectionMediaType(AM_MEDIA_TYPE *pmt) -{ - if (!pmt) { - return E_POINTER; - } else { - QMutexLocker locker(&m_mutex); - - if (!m_peerPin) { - pmt = 0; - - return VFW_E_NOT_CONNECTED; - } else { - DirectShowMediaType::copy(pmt, m_mediaType); - - return S_OK; - } - } -} - -HRESULT DirectShowIOSource::QueryPinInfo(PIN_INFO *pInfo) -{ - if (!pInfo) { - return E_POINTER; - } else { - AddRef(); - - pInfo->pFilter = this; - pInfo->dir = PINDIR_OUTPUT; - - const int bytes = qMin(MAX_FILTER_NAME, (m_pinId.length() + 1) * 2); - - qMemCopy(pInfo->achName, m_pinId.utf16(), bytes); - - return S_OK; - } -} - -HRESULT DirectShowIOSource::QueryId(LPWSTR *Id) -{ - if (!Id) { - return E_POINTER; - } else { - const int bytes = (m_pinId.length() + 1) * 2; - - *Id = static_cast<LPWSTR>(::CoTaskMemAlloc(bytes)); - - qMemCopy(*Id, m_pinId.utf16(), bytes); - - return S_OK; - } -} - -HRESULT DirectShowIOSource::QueryAccept(const AM_MEDIA_TYPE *pmt) -{ - if (!pmt) { - return E_POINTER; - } else if (pmt->majortype == MEDIATYPE_Stream) { - return S_OK; - } else { - return S_FALSE; - } -} - -HRESULT DirectShowIOSource::EnumMediaTypes(IEnumMediaTypes **ppEnum) -{ - if (!ppEnum) { - return E_POINTER; - } else { - *ppEnum = createMediaTypeEnum(); - - return S_OK; - } -} - -HRESULT DirectShowIOSource::QueryInternalConnections(IPin **apPin, ULONG *nPin) -{ - Q_UNUSED(apPin); - Q_UNUSED(nPin); - - return E_NOTIMPL; -} - -HRESULT DirectShowIOSource::EndOfStream() -{ - return S_OK; -} - -HRESULT DirectShowIOSource::BeginFlush() -{ - return m_reader->BeginFlush(); -} - -HRESULT DirectShowIOSource::EndFlush() -{ - return m_reader->EndFlush(); -} - -HRESULT DirectShowIOSource::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) -{ - Q_UNUSED(tStart); - Q_UNUSED(tStop); - Q_UNUSED(dRate); - - return S_OK; -} - -HRESULT DirectShowIOSource::QueryDirection(PIN_DIRECTION *pPinDir) -{ - if (!pPinDir) { - return E_POINTER; - } else { - *pPinDir = PINDIR_OUTPUT; - - return S_OK; - } -} - -DirectShowRcSource::DirectShowRcSource(DirectShowEventLoop *loop) - : DirectShowIOSource(loop) -{ -} - -bool DirectShowRcSource::open(const QUrl &url) -{ - m_file.moveToThread(QCoreApplication::instance()->thread()); - - m_file.setFileName(QLatin1Char(':') + url.path()); - - qDebug("qrc file %s", qPrintable(m_file.fileName())); - - if (m_file.open(QIODevice::ReadOnly)) { - qDebug("Size %d", m_file.size()); - qDebug("Sequential %d", int(m_file.isSequential())); - - setDevice(&m_file); - - return true; - } else { - return false; - } -} diff --git a/src/plugins/directshow/player/directshowiosource.h b/src/plugins/directshow/player/directshowiosource.h deleted file mode 100644 index 137a4f1..0000000 --- a/src/plugins/directshow/player/directshowiosource.h +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DIRECTSHOWIOSOURCE_H -#define DIRECTSHOWIOSOURCE_H - -#include "directshowglobal.h" -#include "directshowioreader.h" -#include "directshowmediatype.h" -#include "directshowmediatypelist.h" - -#include <QtCore/qfile.h> - -class DirectShowIOSource - : public DirectShowMediaTypeList - , public IBaseFilter - , public IAMFilterMiscFlags - , public IPin -{ -public: - DirectShowIOSource(DirectShowEventLoop *loop); - ~DirectShowIOSource(); - - void setDevice(QIODevice *device); - void setAllocator(IMemAllocator *allocator); - - // IUnknown - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); - ULONG STDMETHODCALLTYPE AddRef(); - ULONG STDMETHODCALLTYPE Release(); - - // IPersist - HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pClassID); - - // IMediaFilter - HRESULT STDMETHODCALLTYPE Run(REFERENCE_TIME tStart); - HRESULT STDMETHODCALLTYPE Pause(); - HRESULT STDMETHODCALLTYPE Stop(); - - HRESULT STDMETHODCALLTYPE GetState(DWORD dwMilliSecsTimeout, FILTER_STATE *pState); - - HRESULT STDMETHODCALLTYPE SetSyncSource(IReferenceClock *pClock); - HRESULT STDMETHODCALLTYPE GetSyncSource(IReferenceClock **ppClock); - - // IBaseFilter - HRESULT STDMETHODCALLTYPE EnumPins(IEnumPins **ppEnum); - HRESULT STDMETHODCALLTYPE FindPin(LPCWSTR Id, IPin **ppPin); - - HRESULT STDMETHODCALLTYPE JoinFilterGraph(IFilterGraph *pGraph, LPCWSTR pName); - - HRESULT STDMETHODCALLTYPE QueryFilterInfo(FILTER_INFO *pInfo); - HRESULT STDMETHODCALLTYPE QueryVendorInfo(LPWSTR *pVendorInfo); - - // IAMFilterMiscFlags - ULONG STDMETHODCALLTYPE GetMiscFlags(); - - // IPin - HRESULT STDMETHODCALLTYPE Connect(IPin *pReceivePin, const AM_MEDIA_TYPE *pmt); - HRESULT STDMETHODCALLTYPE ReceiveConnection(IPin *pConnector, const AM_MEDIA_TYPE *pmt); - HRESULT STDMETHODCALLTYPE Disconnect(); - HRESULT STDMETHODCALLTYPE ConnectedTo(IPin **ppPin); - - HRESULT STDMETHODCALLTYPE ConnectionMediaType(AM_MEDIA_TYPE *pmt); - - HRESULT STDMETHODCALLTYPE QueryPinInfo(PIN_INFO *pInfo); - HRESULT STDMETHODCALLTYPE QueryId(LPWSTR *Id); - - HRESULT STDMETHODCALLTYPE QueryAccept(const AM_MEDIA_TYPE *pmt); - - HRESULT STDMETHODCALLTYPE EnumMediaTypes(IEnumMediaTypes **ppEnum); - - HRESULT STDMETHODCALLTYPE QueryInternalConnections(IPin **apPin, ULONG *nPin); - - HRESULT STDMETHODCALLTYPE EndOfStream(); - - HRESULT STDMETHODCALLTYPE BeginFlush(); - HRESULT STDMETHODCALLTYPE EndFlush(); - - HRESULT STDMETHODCALLTYPE NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate); - - HRESULT STDMETHODCALLTYPE QueryDirection(PIN_DIRECTION *pPinDir); - -private: - HRESULT tryConnect(IPin *pin, const AM_MEDIA_TYPE *type); - - volatile LONG m_ref; - FILTER_STATE m_state; - DirectShowIOReader *m_reader; - DirectShowEventLoop *m_loop; - IFilterGraph *m_graph; - IReferenceClock *m_clock; - IMemAllocator *m_allocator; - IPin *m_peerPin; - DirectShowMediaType m_mediaType; - QString m_filterName; - const QString m_pinId; - QMutex m_mutex; -}; - -class DirectShowRcSource : public DirectShowIOSource -{ -public: - DirectShowRcSource(DirectShowEventLoop *loop); - - bool open(const QUrl &url); - -private: - QFile m_file; -}; - -#endif diff --git a/src/plugins/directshow/player/directshowmediatype.cpp b/src/plugins/directshow/player/directshowmediatype.cpp deleted file mode 100644 index ab901c5..0000000 --- a/src/plugins/directshow/player/directshowmediatype.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "directshowmediatype.h" - -namespace -{ - struct TypeLookup - { - QVideoFrame::PixelFormat pixelFormat; - GUID mediaType; - }; - - static const TypeLookup qt_typeLookup[] = - { - { QVideoFrame::Format_RGB32, /*MEDIASUBTYPE_RGB32*/ {0xe436eb7e, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}} }, - { QVideoFrame::Format_BGR24, /*MEDIASUBTYPE_RGB24*/ {0xe436eb7d, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}} }, - { QVideoFrame::Format_RGB565, /*MEDIASUBTYPE_RGB565*/ {0xe436eb7b, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}} }, - { QVideoFrame::Format_RGB555, /*MEDIASUBTYPE_RGB555*/ {0xe436eb7c, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}} }, - { QVideoFrame::Format_AYUV444, /*MEDIASUBTYPE_AYUV*/ {0x56555941, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}} }, - { QVideoFrame::Format_YUYV, /*MEDIASUBTYPE_YUY2*/ {0x32595559, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}} }, - { QVideoFrame::Format_UYVY, /*MEDIASUBTYPE_UYVY*/ {0x59565955, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}} }, - { QVideoFrame::Format_IMC1, /*MEDIASUBTYPE_IMC1*/ {0x31434D49, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}} }, - { QVideoFrame::Format_IMC2, /*MEDIASUBTYPE_IMC2*/ {0x32434D49, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}} }, - { QVideoFrame::Format_IMC3, /*MEDIASUBTYPE_IMC3*/ {0x33434D49, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}} }, - { QVideoFrame::Format_IMC4, /*MEDIASUBTYPE_IMC4*/ {0x34434D49, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}} }, - { QVideoFrame::Format_YV12, /*MEDIASUBTYPE_YV12*/ {0x32315659, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}} }, - { QVideoFrame::Format_NV12, /*MEDIASUBTYPE_NV12*/ {0x3231564E, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}} }, - { QVideoFrame::Format_YUV420P, /*MEDIASUBTYPE_IYUV*/ {0x56555949, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}} } - }; -} - -void DirectShowMediaType::copy(AM_MEDIA_TYPE *target, const AM_MEDIA_TYPE &source) -{ - *target = source; - - if (source.cbFormat > 0) { - target->pbFormat = reinterpret_cast<PBYTE>(CoTaskMemAlloc(source.cbFormat)); - memcpy(target->pbFormat, source.pbFormat, source.cbFormat); - } - if (target->pUnk) - target->pUnk->AddRef(); -} - -void DirectShowMediaType::deleteType(AM_MEDIA_TYPE *type) -{ - freeData(type); - - CoTaskMemFree(type); -} - -void DirectShowMediaType::freeData(AM_MEDIA_TYPE *type) -{ - if (type->cbFormat > 0) - CoTaskMemFree(type->pbFormat); - - if (type->pUnk) - type->pUnk->Release(); -} - - -GUID DirectShowMediaType::convertPixelFormat(QVideoFrame::PixelFormat format) -{ - // MEDIASUBTYPE_None; - static const GUID none = { - 0xe436eb8e, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70} }; - - const int count = sizeof(qt_typeLookup) / sizeof(TypeLookup); - - for (int i = 0; i < count; ++i) - if (qt_typeLookup[i].pixelFormat == format) - return qt_typeLookup[i].mediaType; - return none; -} - -QVideoSurfaceFormat DirectShowMediaType::formatFromType(const AM_MEDIA_TYPE &type) -{ - const int count = sizeof(qt_typeLookup) / sizeof(TypeLookup); - - for (int i = 0; i < count; ++i) { - if (IsEqualGUID(qt_typeLookup[i].mediaType, type.subtype) && type.cbFormat > 0) { - if (IsEqualGUID(type.formattype, FORMAT_VideoInfo)) { - VIDEOINFOHEADER *header = reinterpret_cast<VIDEOINFOHEADER *>(type.pbFormat); - - QVideoSurfaceFormat format( - QSize(header->bmiHeader.biWidth, qAbs(header->bmiHeader.biHeight)), - qt_typeLookup[i].pixelFormat); - - if (header->AvgTimePerFrame > 0) - format.setFrameRate(10000 /header->AvgTimePerFrame); - - format.setScanLineDirection(header->bmiHeader.biHeight < 0 - ? QVideoSurfaceFormat::TopToBottom - : QVideoSurfaceFormat::BottomToTop); - - return format; - } else if (IsEqualGUID(type.formattype, FORMAT_VideoInfo2)) { - VIDEOINFOHEADER2 *header = reinterpret_cast<VIDEOINFOHEADER2 *>(type.pbFormat); - - QVideoSurfaceFormat format( - QSize(header->bmiHeader.biWidth, qAbs(header->bmiHeader.biHeight)), - qt_typeLookup[i].pixelFormat); - - if (header->AvgTimePerFrame > 0) - format.setFrameRate(10000 / header->AvgTimePerFrame); - - format.setScanLineDirection(header->bmiHeader.biHeight < 0 - ? QVideoSurfaceFormat::TopToBottom - : QVideoSurfaceFormat::BottomToTop); - - return format; - } - } - } - return QVideoSurfaceFormat(); -} - -#define PAD_TO_DWORD(x) (((x) + 3) & ~3) -int DirectShowMediaType::bytesPerLine(const QVideoSurfaceFormat &format) -{ - switch (format.pixelFormat()) { - // 32 bpp packed formats. - case QVideoFrame::Format_RGB32: - case QVideoFrame::Format_AYUV444: - return format.frameWidth() * 4; - // 24 bpp packed formats. - case QVideoFrame::Format_RGB24: - return PAD_TO_DWORD(format.frameWidth() * 3); - // 16 bpp packed formats. - case QVideoFrame::Format_RGB565: - case QVideoFrame::Format_RGB555: - case QVideoFrame::Format_YUYV: - case QVideoFrame::Format_UYVY: - return PAD_TO_DWORD(format.frameWidth() * 2); - // Planar formats. - case QVideoFrame::Format_IMC1: - case QVideoFrame::Format_IMC2: - case QVideoFrame::Format_IMC3: - case QVideoFrame::Format_IMC4: - case QVideoFrame::Format_YV12: - case QVideoFrame::Format_NV12: - case QVideoFrame::Format_YUV420P: - return PAD_TO_DWORD(format.frameWidth()); - default: - return 0; - } -} diff --git a/src/plugins/directshow/player/directshowmediatype.h b/src/plugins/directshow/player/directshowmediatype.h deleted file mode 100644 index 66f3028..0000000 --- a/src/plugins/directshow/player/directshowmediatype.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DIRECTSHOWMEDIATYPE_H -#define DIRECTSHOWMEDIATYPE_H - -#include <qvideosurfaceformat.h> - -#include <dshow.h> -#include <dvdmedia.h> - -class DirectShowMediaType : public AM_MEDIA_TYPE -{ -public: - DirectShowMediaType() { memset(this, 0, sizeof(DirectShowMediaType)); } - DirectShowMediaType(const AM_MEDIA_TYPE &type) { copy(this, type); } - DirectShowMediaType(const DirectShowMediaType &other) { copy(this, other); } - DirectShowMediaType &operator =(const AM_MEDIA_TYPE &type) { - freeData(this); copy(this, type); return *this; } - DirectShowMediaType &operator =(const DirectShowMediaType &other) { - freeData(this); copy(this, other); return *this; } - ~DirectShowMediaType() { freeData(this); } - - void clear() { freeData(this); memset(this, 0, sizeof(DirectShowMediaType)); } - - static void copy(AM_MEDIA_TYPE *target, const AM_MEDIA_TYPE &source); - static void freeData(AM_MEDIA_TYPE *type); - static void deleteType(AM_MEDIA_TYPE *type); - - static GUID convertPixelFormat(QVideoFrame::PixelFormat format); - static QVideoSurfaceFormat formatFromType(const AM_MEDIA_TYPE &type); - - static int bytesPerLine(const QVideoSurfaceFormat &format); -}; - -#endif diff --git a/src/plugins/directshow/player/directshowmediatypelist.cpp b/src/plugins/directshow/player/directshowmediatypelist.cpp deleted file mode 100644 index 06a7523..0000000 --- a/src/plugins/directshow/player/directshowmediatypelist.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "directshowmediatypelist.h" - -#include "directshowmediatype.h" -#include "videosurfacefilter.h" - - -class DirectShowMediaTypeEnum : public IEnumMediaTypes -{ -public: - DirectShowMediaTypeEnum(DirectShowMediaTypeList *list, int token, int index = 0); - ~DirectShowMediaTypeEnum(); - - // IUnknown - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); - ULONG STDMETHODCALLTYPE AddRef(); - ULONG STDMETHODCALLTYPE Release(); - - // IEnumMediaTypes - HRESULT STDMETHODCALLTYPE Next( - ULONG cMediaTypes, AM_MEDIA_TYPE **ppMediaTypes, ULONG *pcFetched); - HRESULT STDMETHODCALLTYPE Skip(ULONG cMediaTypes); - HRESULT STDMETHODCALLTYPE Reset(); - - HRESULT STDMETHODCALLTYPE Clone(IEnumMediaTypes **ppEnum); - -private: - LONG m_ref; - DirectShowMediaTypeList *m_list; - int m_mediaTypeToken; - int m_index; -}; - - -DirectShowMediaTypeEnum::DirectShowMediaTypeEnum( - DirectShowMediaTypeList *list, int token, int index) - : m_ref(1) - , m_list(list) - , m_mediaTypeToken(token) - , m_index(index) -{ - m_list->AddRef(); -} - -DirectShowMediaTypeEnum::~DirectShowMediaTypeEnum() -{ - m_list->Release(); -} - -HRESULT DirectShowMediaTypeEnum::QueryInterface(REFIID riid, void **ppvObject) -{ - if (!ppvObject) { - return E_POINTER; - } else if (riid == IID_IUnknown - || riid == IID_IEnumMediaTypes) { - *ppvObject = static_cast<IEnumMediaTypes *>(this); - } else { - *ppvObject = 0; - - return E_NOINTERFACE; - } - - AddRef(); - - return S_OK; -} - -ULONG DirectShowMediaTypeEnum::AddRef() -{ - return InterlockedIncrement(&m_ref); -} - -ULONG DirectShowMediaTypeEnum::Release() -{ - ULONG ref = InterlockedDecrement(&m_ref); - - if (ref == 0) { - delete this; - } - - return ref; -} - -HRESULT DirectShowMediaTypeEnum::Next( - ULONG cMediaTypes, AM_MEDIA_TYPE **ppMediaTypes, ULONG *pcFetched) -{ - return m_list->nextMediaType(m_mediaTypeToken, &m_index, cMediaTypes, ppMediaTypes, pcFetched); -} - -HRESULT DirectShowMediaTypeEnum::Skip(ULONG cMediaTypes) -{ - return m_list->skipMediaType(m_mediaTypeToken, &m_index, cMediaTypes); -} - -HRESULT DirectShowMediaTypeEnum::Reset() -{ - m_mediaTypeToken = m_list->currentMediaTypeToken(); - m_index = 0; - - return S_OK; -} - -HRESULT DirectShowMediaTypeEnum::Clone(IEnumMediaTypes **ppEnum) -{ - return m_list->cloneMediaType(m_mediaTypeToken, m_index, ppEnum); -} - - -DirectShowMediaTypeList::DirectShowMediaTypeList() - : m_mediaTypeToken(0) -{ -} - -IEnumMediaTypes *DirectShowMediaTypeList::createMediaTypeEnum() -{ - return new DirectShowMediaTypeEnum(this, m_mediaTypeToken, 0); -} - - -void DirectShowMediaTypeList::setMediaTypes(const QVector<AM_MEDIA_TYPE> &types) -{ - ++m_mediaTypeToken; - - m_mediaTypes = types; -} - - -int DirectShowMediaTypeList::currentMediaTypeToken() -{ - return m_mediaTypeToken; -} - -HRESULT DirectShowMediaTypeList::nextMediaType( - int token, int *index, ULONG count, AM_MEDIA_TYPE **types, ULONG *fetchedCount) -{ - if (!types || (count != 1 && !fetchedCount)) { - return E_POINTER; - } else if (m_mediaTypeToken != token) { - return VFW_E_ENUM_OUT_OF_SYNC; - } else { - int boundedCount = qBound<int>(0, count, m_mediaTypes.count() - *index); - - for (int i = 0; i < boundedCount; ++i, ++(*index)) { - types[i] = reinterpret_cast<AM_MEDIA_TYPE *>(CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE))); - - if (types[i]) { - DirectShowMediaType::copy(types[i], m_mediaTypes.at(*index)); - } else { - for (--i; i >= 0; --i) - CoTaskMemFree(types[i]); - - if (fetchedCount) - *fetchedCount = 0; - - return E_OUTOFMEMORY; - } - } - if (fetchedCount) - *fetchedCount = boundedCount; - - return boundedCount == count ? S_OK : S_FALSE; - } -} - -HRESULT DirectShowMediaTypeList::skipMediaType(int token, int *index, ULONG count) -{ - if (m_mediaTypeToken != token) { - return VFW_E_ENUM_OUT_OF_SYNC; - } else { - *index = qMin<int>(*index + count, m_mediaTypes.size()); - - return *index < m_mediaTypes.size() ? S_OK : S_FALSE; - } -} - -HRESULT DirectShowMediaTypeList::cloneMediaType(int token, int index, IEnumMediaTypes **enumeration) -{ - if (m_mediaTypeToken != token) { - return VFW_E_ENUM_OUT_OF_SYNC; - } else { - *enumeration = new DirectShowMediaTypeEnum(this, token, index); - - return S_OK; - } -} - diff --git a/src/plugins/directshow/player/directshowmediatypelist.h b/src/plugins/directshow/player/directshowmediatypelist.h deleted file mode 100644 index 62632da..0000000 --- a/src/plugins/directshow/player/directshowmediatypelist.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DIRECTSHOWMEDIATYPELIST_H -#define DIRECTSHOWMEDIATYPELIST_H - -#include <QtCore/qvector.h> - -#include <dshow.h> - -class DirectShowMediaTypeList : public IUnknown -{ -public: - DirectShowMediaTypeList(); - - IEnumMediaTypes *createMediaTypeEnum(); - - void setMediaTypes(const QVector<AM_MEDIA_TYPE> &types); - - virtual int currentMediaTypeToken(); - virtual HRESULT nextMediaType( - int token, int *index, ULONG count, AM_MEDIA_TYPE **types, ULONG *fetchedCount); - virtual HRESULT skipMediaType(int token, int *index, ULONG count); - virtual HRESULT cloneMediaType(int token, int index, IEnumMediaTypes **enumeration); - -private: - int m_mediaTypeToken; - QVector<AM_MEDIA_TYPE> m_mediaTypes; -}; - -#endif diff --git a/src/plugins/directshow/player/directshowmetadatacontrol.cpp b/src/plugins/directshow/player/directshowmetadatacontrol.cpp deleted file mode 100644 index 3bf2a32..0000000 --- a/src/plugins/directshow/player/directshowmetadatacontrol.cpp +++ /dev/null @@ -1,352 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <dshow.h> -#include <initguid.h> -#include <qnetwork.h> - -#include "directshowmetadatacontrol.h" - -#include "directshowplayerservice.h" - -#include <QtCore/qcoreapplication.h> - -#ifndef QT_NO_WMSDK -namespace -{ - struct QWMMetaDataKeyLookup - { - QtMultimedia::MetaData key; - const wchar_t *token; - }; -} - -static const QWMMetaDataKeyLookup qt_wmMetaDataKeys[] = -{ - { QtMultimedia::Title, L"Title" }, - { QtMultimedia::SubTitle, L"WM/SubTitle" }, - { QtMultimedia::Author, L"Author" }, - { QtMultimedia::Comment, L"Comment" }, - { QtMultimedia::Description, L"Description" }, - { QtMultimedia::Category, L"WM/Category" }, - { QtMultimedia::Genre, L"WM/Genre" }, - //{ QtMultimedia::Date, 0 }, - { QtMultimedia::Year, L"WM/Year" }, - { QtMultimedia::UserRating, L"UserRating" }, - //{ QtMultimedia::MetaDatawords, 0 }, - { QtMultimedia::Language, L"Language" }, - { QtMultimedia::Publisher, L"WM/Publisher" }, - { QtMultimedia::Copyright, L"Copyright" }, - { QtMultimedia::ParentalRating, L"ParentalRating" }, - { QtMultimedia::RatingOrganisation, L"RatingOrganisation" }, - - // Media - { QtMultimedia::Size, L"FileSize" }, - { QtMultimedia::MediaType, L"MediaType" }, - { QtMultimedia::Duration, L"Duration" }, - - // Audio - { QtMultimedia::AudioBitRate, L"AudioBitRate" }, - { QtMultimedia::AudioCodec, L"AudioCodec" }, - { QtMultimedia::ChannelCount, L"ChannelCount" }, - { QtMultimedia::SampleRate, L"Frequency" }, - - // Music - { QtMultimedia::AlbumTitle, L"WM/AlbumTitle" }, - { QtMultimedia::AlbumArtist, L"WM/AlbumArtist" }, - { QtMultimedia::ContributingArtist, L"Author" }, - { QtMultimedia::Composer, L"WM/Composer" }, - { QtMultimedia::Conductor, L"WM/Conductor" }, - { QtMultimedia::Lyrics, L"WM/Lyrics" }, - { QtMultimedia::Mood, L"WM/Mood" }, - { QtMultimedia::TrackNumber, L"WM/TrackNumber" }, - //{ QtMultimedia::TrackCount, 0 }, - //{ QtMultimedia::CoverArtUriSmall, 0 }, - //{ QtMultimedia::CoverArtUriLarge, 0 }, - - // Image/Video - //{ QtMultimedia::Resolution, 0 }, - //{ QtMultimedia::PixelAspectRatio, 0 }, - - // Video - //{ QtMultimedia::FrameRate, 0 }, - { QtMultimedia::VideoBitRate, L"VideoBitRate" }, - { QtMultimedia::VideoCodec, L"VideoCodec" }, - - //{ QtMultimedia::PosterUri, 0 }, - - // Movie - { QtMultimedia::ChapterNumber, L"ChapterNumber" }, - { QtMultimedia::Director, L"WM/Director" }, - { QtMultimedia::LeadPerformer, L"LeadPerformer" }, - { QtMultimedia::Writer, L"WM/Writer" }, - - // Photos - { QtMultimedia::CameraManufacturer, L"CameraManufacturer" }, - { QtMultimedia::CameraModel, L"CameraModel" }, - { QtMultimedia::Event, L"Event" }, - { QtMultimedia::Subject, L"Subject" } -}; - -static QVariant getValue(IWMHeaderInfo *header, const wchar_t *key) -{ - WORD streamNumber = 0; - WMT_ATTR_DATATYPE type = WMT_TYPE_DWORD; - WORD size = 0; - - if (header->GetAttributeByName(&streamNumber, key, &type, 0, &size) == S_OK) { - switch (type) { - case WMT_TYPE_DWORD: - if (size == sizeof(DWORD)) { - DWORD word; - if (header->GetAttributeByName( - &streamNumber, - key, - &type, - reinterpret_cast<BYTE *>(&word), - &size) == S_OK) { - return int(word); - } - } - break; - case WMT_TYPE_STRING: - { - QString string; - string.resize(size / 2 - 1); - - if (header->GetAttributeByName( - &streamNumber, - key, - &type, - reinterpret_cast<BYTE *>(const_cast<ushort *>(string.utf16())), - &size) == S_OK) { - return string; - } - } - break; - case WMT_TYPE_BINARY: - { - QByteArray bytes; - bytes.resize(size); - if (header->GetAttributeByName( - &streamNumber, - key, - &type, - reinterpret_cast<BYTE *>(bytes.data()), - &size) == S_OK) { - return bytes; - } - } - break; - case WMT_TYPE_BOOL: - if (size == sizeof(DWORD)) { - DWORD word; - if (header->GetAttributeByName( - &streamNumber, - key, - &type, - reinterpret_cast<BYTE *>(&word), - &size) == S_OK) { - return bool(word); - } - } - break; - case WMT_TYPE_QWORD: - if (size == sizeof(QWORD)) { - QWORD word; - if (header->GetAttributeByName( - &streamNumber, - key, - &type, - reinterpret_cast<BYTE *>(&word), - &size) == S_OK) { - return qint64(word); - } - } - break; - case WMT_TYPE_WORD: - if (size == sizeof(WORD)){ - WORD word; - if (header->GetAttributeByName( - &streamNumber, - key, - &type, - reinterpret_cast<BYTE *>(&word), - &size) == S_OK) { - return short(word); - } - } - break; - case WMT_TYPE_GUID: - if (size == 16) { - } - break; - default: - break; - } - } - return QVariant(); -} -#endif - -DirectShowMetaDataControl::DirectShowMetaDataControl(QObject *parent) - : QMetaDataReaderControl(parent) - , m_content(0) -#ifndef QT_NO_WMSDK - , m_headerInfo(0) -#endif -{ -} - -DirectShowMetaDataControl::~DirectShowMetaDataControl() -{ -} - -bool DirectShowMetaDataControl::isMetaDataAvailable() const -{ -#ifndef QT_NO_WMSDK - return m_content || m_headerInfo; -#else - return m_content; -#endif -} - -QVariant DirectShowMetaDataControl::metaData(QtMultimedia::MetaData key) const -{ - QVariant value; - -#ifndef QT_NO_WMSDK - if (m_headerInfo) { - static const int count = sizeof(qt_wmMetaDataKeys) / sizeof(QWMMetaDataKeyLookup); - for (int i = 0; i < count; ++i) { - if (qt_wmMetaDataKeys[i].key == key) { - value = getValue(m_headerInfo, qt_wmMetaDataKeys[i].token); - break; - } - } - } else if (m_content) { -#else - if (m_content) { -#endif - BSTR string = 0; - - switch (key) { - case QtMultimedia::Author: - m_content->get_AuthorName(&string); - break; - case QtMultimedia::Title: - m_content->get_Title(&string); - break; - case QtMultimedia::ParentalRating: - m_content->get_Rating(&string); - break; - case QtMultimedia::Description: - m_content->get_Description(&string); - break; - case QtMultimedia::Copyright: - m_content->get_Copyright(&string); - break; - default: - break; - } - - if (string) { - value = QString::fromUtf16(reinterpret_cast<ushort *>(string), ::SysStringLen(string)); - - ::SysFreeString(string); - } - } - return value; -} - -QList<QtMultimedia::MetaData> DirectShowMetaDataControl::availableMetaData() const -{ - return QList<QtMultimedia::MetaData>(); -} - -QVariant DirectShowMetaDataControl::extendedMetaData(const QString &) const -{ - return QVariant(); -} - -QStringList DirectShowMetaDataControl::availableExtendedMetaData() const -{ - return QStringList(); -} - -void DirectShowMetaDataControl::updateGraph(IFilterGraph2 *graph, IBaseFilter *source) -{ - if (m_content) - m_content->Release(); - - if (!graph || graph->QueryInterface( - IID_IAMMediaContent, reinterpret_cast<void **>(&m_content)) != S_OK) { - m_content = 0; - } - -#ifdef QT_NO_WMSDK - Q_UNUSED(source); -#else - if (m_headerInfo) - m_headerInfo->Release(); - - m_headerInfo = com_cast<IWMHeaderInfo>(source, IID_IWMHeaderInfo); -#endif - // DirectShowMediaPlayerService holds a lock at this point so defer emitting signals to a later - // time. - QCoreApplication::postEvent(this, new QEvent(QEvent::Type(MetaDataChanged))); -} - -void DirectShowMetaDataControl::customEvent(QEvent *event) -{ - if (event->type() == QEvent::Type(MetaDataChanged)) { - event->accept(); - - emit metaDataChanged(); -#ifndef QT_NO_WMSDK - emit metaDataAvailableChanged(m_content || m_headerInfo); -#else - emit metaDataAvailableChanged(m_content); -#endif - } else { - QMetaDataReaderControl::customEvent(event); - } -} diff --git a/src/plugins/directshow/player/directshowmetadatacontrol.h b/src/plugins/directshow/player/directshowmetadatacontrol.h deleted file mode 100644 index f5c65f1..0000000 --- a/src/plugins/directshow/player/directshowmetadatacontrol.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DIRECTSHOWMETADATACONTROL_H -#define DIRECTSHOWMETADATACONTROL_H - -#include <qmetadatareadercontrol.h> - -#include "directshowglobal.h" - -#include <qnetwork.h> - -#ifndef QT_NO_WMSDK -#include <wmsdk.h> -#endif - -#include <QtCore/qcoreevent.h> - -class DirectShowPlayerService; - -QT_USE_NAMESPACE - -class DirectShowMetaDataControl : public QMetaDataReaderControl -{ - Q_OBJECT -public: - DirectShowMetaDataControl(QObject *parent = 0); - ~DirectShowMetaDataControl(); - - bool isMetaDataAvailable() const; - - QVariant metaData(QtMultimedia::MetaData key) const; - QList<QtMultimedia::MetaData> availableMetaData() const; - - QVariant extendedMetaData(const QString &key) const; - QStringList availableExtendedMetaData() const; - - void updateGraph(IFilterGraph2 *graph, IBaseFilter *source); - -protected: - void customEvent(QEvent *event); - -private: - enum Event - { - MetaDataChanged = QEvent::User - }; - - IAMMediaContent *m_content; -#ifndef QT_NO_WMSDK - IWMHeaderInfo *m_headerInfo; -#endif -}; - -#endif diff --git a/src/plugins/directshow/player/directshowpinenum.cpp b/src/plugins/directshow/player/directshowpinenum.cpp deleted file mode 100644 index f88f791..0000000 --- a/src/plugins/directshow/player/directshowpinenum.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "directshowpinenum.h" - - -DirectShowPinEnum::DirectShowPinEnum(const QList<IPin *> &pins) - : m_ref(1) - , m_pins(pins) - , m_index(0) -{ - foreach (IPin *pin, m_pins) - pin->AddRef(); -} - -DirectShowPinEnum::~DirectShowPinEnum() -{ - foreach (IPin *pin, m_pins) - pin->Release(); -} - -HRESULT DirectShowPinEnum::QueryInterface(REFIID riid, void **ppvObject) -{ - if (riid == IID_IUnknown - || riid == IID_IEnumPins) { - AddRef(); - - *ppvObject = static_cast<IEnumPins *>(this); - - return S_OK; - } else { - *ppvObject = 0; - - return E_NOINTERFACE; - } -} - -ULONG DirectShowPinEnum::AddRef() -{ - return InterlockedIncrement(&m_ref); -} - -ULONG DirectShowPinEnum::Release() -{ - ULONG ref = InterlockedDecrement(&m_ref); - - if (ref == 0) { - delete this; - } - - return ref; -} - -HRESULT DirectShowPinEnum::Next(ULONG cPins, IPin **ppPins, ULONG *pcFetched) -{ - if (ppPins && (pcFetched || cPins == 1)) { - ULONG count = qBound<ULONG>(0, cPins, m_pins.count() - m_index); - - for (ULONG i = 0; i < count; ++i, ++m_index) { - ppPins[i] = m_pins.at(m_index); - ppPins[i]->AddRef(); - } - - if (pcFetched) - *pcFetched = count; - - return count == cPins ? S_OK : S_FALSE; - } else { - return E_POINTER; - } -} - -HRESULT DirectShowPinEnum::Skip(ULONG cPins) -{ - m_index = qMin(int(m_index + cPins), m_pins.count()); - - return m_index < m_pins.count() ? S_OK : S_FALSE; -} - -HRESULT DirectShowPinEnum::Reset() -{ - m_index = 0; - - return S_OK; -} - -HRESULT DirectShowPinEnum::Clone(IEnumPins **ppEnum) -{ - if (ppEnum) { - *ppEnum = new DirectShowPinEnum(m_pins); - - return S_OK; - } else { - return E_POINTER; - } -} diff --git a/src/plugins/directshow/player/directshowpinenum.h b/src/plugins/directshow/player/directshowpinenum.h deleted file mode 100644 index e1cbb10..0000000 --- a/src/plugins/directshow/player/directshowpinenum.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DIRECTSHOWPINENUM_H -#define DIRECTSHOWPINENUM_H - -#include <QtCore/qlist.h> - -#include <dshow.h> - -class DirectShowPinEnum : public IEnumPins -{ -public: - DirectShowPinEnum(const QList<IPin *> &pins); - ~DirectShowPinEnum(); - - // IUnknown - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); - ULONG STDMETHODCALLTYPE AddRef(); - ULONG STDMETHODCALLTYPE Release(); - - // IEnumPins - HRESULT STDMETHODCALLTYPE Next(ULONG cPins, IPin **ppPins, ULONG *pcFetched); - HRESULT STDMETHODCALLTYPE Skip(ULONG cPins); - HRESULT STDMETHODCALLTYPE Reset(); - HRESULT STDMETHODCALLTYPE Clone(IEnumPins **ppEnum); - -private: - LONG m_ref; - QList<IPin *> m_pins; - int m_index; -}; - -#endif diff --git a/src/plugins/directshow/player/directshowplayercontrol.cpp b/src/plugins/directshow/player/directshowplayercontrol.cpp deleted file mode 100644 index 4037dd0..0000000 --- a/src/plugins/directshow/player/directshowplayercontrol.cpp +++ /dev/null @@ -1,405 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "directshowplayercontrol.h" - -#include "directshowplayerservice.h" - -#include <QtCore/qcoreapplication.h> -#include <QtCore/qmath.h> - -static int volumeToDecibels(int volume) -{ - if (volume == 0) { - return -10000; - } else if (volume == 100) { - return 0; -#ifdef QT_USE_MATH_H_FLOATS - } else if (sizeof(qreal) == sizeof(float)) { - return qRound(::log10f(float(volume) / 100) * 5000); -#endif - } else { - return qRound(::log10(qreal(volume) / 100) * 5000); - } -} - -static int decibelsToVolume(int dB) -{ - if (dB == -10000) { - return 0; - } else if (dB == 0) { - return 100; - } else { - return qRound(100 * qPow(10, qreal(dB) / 5000)); - } -} - -DirectShowPlayerControl::DirectShowPlayerControl(DirectShowPlayerService *service, QObject *parent) - : QMediaPlayerControl(parent) - , m_service(service) - , m_audio(0) - , m_updateProperties(0) - , m_state(QMediaPlayer::StoppedState) - , m_status(QMediaPlayer::NoMedia) - , m_error(QMediaPlayer::NoError) - , m_streamTypes(0) - , m_muteVolume(-1) - , m_position(0) - , m_duration(0) - , m_playbackRate(0) - , m_seekable(false) -{ -} - -DirectShowPlayerControl::~DirectShowPlayerControl() -{ - if (m_audio) - m_audio->Release(); -} - -QMediaPlayer::State DirectShowPlayerControl::state() const -{ - return m_state; -} - -QMediaPlayer::MediaStatus DirectShowPlayerControl::mediaStatus() const -{ - return m_status; -} - -qint64 DirectShowPlayerControl::duration() const -{ - return m_duration; -} - -qint64 DirectShowPlayerControl::position() const -{ - return const_cast<qint64 &>(m_position) = m_service->position(); -} - -void DirectShowPlayerControl::setPosition(qint64 position) -{ - m_service->seek(position); -} - -int DirectShowPlayerControl::volume() const -{ - if (m_muteVolume >= 0) { - return m_muteVolume; - } else if (m_audio) { - long dB = 0; - - m_audio->get_Volume(&dB); - - return decibelsToVolume(dB); - } else { - return 0; - } -} - -void DirectShowPlayerControl::setVolume(int volume) -{ - int boundedVolume = qBound(0, volume, 100); - - if (m_muteVolume >= 0) { - m_muteVolume = boundedVolume; - - emit volumeChanged(m_muteVolume); - } else if (m_audio) { - m_audio->put_Volume(volumeToDecibels(volume)); - - emit volumeChanged(boundedVolume); - } -} - -bool DirectShowPlayerControl::isMuted() const -{ - return m_muteVolume >= 0; -} - -void DirectShowPlayerControl::setMuted(bool muted) -{ - if (muted && m_muteVolume < 0) { - if (m_audio) { - long dB = 0; - - m_audio->get_Volume(&dB); - - m_muteVolume = decibelsToVolume(dB); - - m_audio->put_Volume(-10000); - } else { - m_muteVolume = 0; - } - - emit mutedChanged(muted); - } else if (!muted && m_muteVolume >= 0) { - if (m_audio) { - m_audio->put_Volume(volumeToDecibels(m_muteVolume)); - } - m_muteVolume = -1; - - emit mutedChanged(muted); - } -} - -int DirectShowPlayerControl::bufferStatus() const -{ - return m_service->bufferStatus(); -} - -bool DirectShowPlayerControl::isAudioAvailable() const -{ - return m_streamTypes & DirectShowPlayerService::AudioStream; -} - -bool DirectShowPlayerControl::isVideoAvailable() const -{ - return m_streamTypes & DirectShowPlayerService::VideoStream; -} - -bool DirectShowPlayerControl::isSeekable() const -{ - return m_seekable; -} - -QMediaTimeRange DirectShowPlayerControl::availablePlaybackRanges() const -{ - return m_service->availablePlaybackRanges(); -} - -qreal DirectShowPlayerControl::playbackRate() const -{ - return m_playbackRate; -} - -void DirectShowPlayerControl::setPlaybackRate(qreal rate) -{ - if (m_playbackRate != rate) { - m_service->setRate(rate); - - emit playbackRateChanged(m_playbackRate = rate); - } -} - -QMediaContent DirectShowPlayerControl::media() const -{ - return m_media; -} - -const QIODevice *DirectShowPlayerControl::mediaStream() const -{ - return m_stream; -} - -void DirectShowPlayerControl::setMedia(const QMediaContent &media, QIODevice *stream) -{ - m_media = media; - m_stream = stream; - - m_updateProperties &= PlaybackRateProperty; - - m_service->load(media, stream); - - emit mediaChanged(m_media); - emitPropertyChanges(); -} - -void DirectShowPlayerControl::play() -{ - if (m_status == QMediaPlayer::NoMedia) - return; - if (m_status == QMediaPlayer::InvalidMedia) { - setMedia(m_media, m_stream); - if (m_error != QMediaPlayer::NoError) - return; - } - m_service->play(); - emit stateChanged(m_state = QMediaPlayer::PlayingState); -} - -void DirectShowPlayerControl::pause() -{ - if (m_status == QMediaPlayer::NoMedia) - return; - if (m_status == QMediaPlayer::InvalidMedia) { - setMedia(m_media, m_stream); - if (m_error != QMediaPlayer::NoError) - return; - } - m_service->pause(); - emit stateChanged(m_state = QMediaPlayer::PausedState); -} - -void DirectShowPlayerControl::stop() -{ - m_service->stop(); - emit stateChanged(m_state = QMediaPlayer::StoppedState); -} - -void DirectShowPlayerControl::customEvent(QEvent *event) -{ - if (event->type() == QEvent::Type(PropertiesChanged)) { - emitPropertyChanges(); - - event->accept(); - } else { - QMediaPlayerControl::customEvent(event); - } -} - -void DirectShowPlayerControl::emitPropertyChanges() -{ - int properties = m_updateProperties; - m_updateProperties = 0; - - if ((properties & ErrorProperty) && m_error != QMediaPlayer::NoError) - emit error(m_error, m_errorString); - - if (properties & PlaybackRateProperty) - emit playbackRateChanged(m_playbackRate); - - if (properties & StreamTypesProperty) { - emit audioAvailableChanged(m_streamTypes & DirectShowPlayerService::AudioStream); - emit videoAvailableChanged(m_streamTypes & DirectShowPlayerService::VideoStream); - } - - if (properties & PositionProperty) - emit positionChanged(m_position); - - if (properties & DurationProperty) - emit durationChanged(m_duration); - - if (properties & SeekableProperty) - emit seekableChanged(m_seekable); - - if (properties & StatusProperty) - emit mediaStatusChanged(m_status); - - if (properties & StateProperty) - emit stateChanged(m_state); -} - -void DirectShowPlayerControl::scheduleUpdate(int properties) -{ - if (m_updateProperties == 0) - QCoreApplication::postEvent(this, new QEvent(QEvent::Type(PropertiesChanged))); - - m_updateProperties |= properties; -} - -void DirectShowPlayerControl::updateState(QMediaPlayer::State state) -{ - if (m_state != state) { - m_state = state; - - scheduleUpdate(StateProperty); - } -} - -void DirectShowPlayerControl::updateStatus(QMediaPlayer::MediaStatus status) -{ - if (m_status != status) { - m_status = status; - - scheduleUpdate(StatusProperty); - } -} - -void DirectShowPlayerControl::updateMediaInfo(qint64 duration, int streamTypes, bool seekable) -{ - int properties = 0; - - if (m_duration != duration) { - m_duration = duration; - - properties |= DurationProperty; - } - if (m_streamTypes != streamTypes) { - m_streamTypes = streamTypes; - - properties |= StreamTypesProperty; - } - - if (m_seekable != seekable) { - m_seekable = seekable; - - properties |= SeekableProperty; - } - - if (properties != 0) - scheduleUpdate(properties); -} - -void DirectShowPlayerControl::updatePlaybackRate(qreal rate) -{ - if (m_playbackRate != rate) { - m_playbackRate = rate; - - scheduleUpdate(PlaybackRateProperty); - } -} - -void DirectShowPlayerControl::updateAudioOutput(IBaseFilter *filter) -{ - if (m_audio) - m_audio->Release(); - - m_audio = com_cast<IBasicAudio>(filter, IID_IBasicAudio); -} - -void DirectShowPlayerControl::updateError(QMediaPlayer::Error error, const QString &errorString) -{ - m_error = error; - m_errorString = errorString; - - if (m_error != QMediaPlayer::NoError) - scheduleUpdate(ErrorProperty); -} - -void DirectShowPlayerControl::updatePosition(qint64 position) -{ - if (m_position != position) { - m_position = position; - - scheduleUpdate(PositionProperty); - } -} diff --git a/src/plugins/directshow/player/directshowplayercontrol.h b/src/plugins/directshow/player/directshowplayercontrol.h deleted file mode 100644 index eee0867..0000000 --- a/src/plugins/directshow/player/directshowplayercontrol.h +++ /dev/null @@ -1,146 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DIRECTSHOWPLAYERCONTROL_H -#define DIRECTSHOWPLAYERCONTROL_H - -#include "qmediacontent.h" -#include "qmediaplayercontrol.h" - -#include <QtCore/qcoreevent.h> - -#include "directshowplayerservice.h" - -QT_USE_NAMESPACE - -class DirectShowPlayerControl : public QMediaPlayerControl -{ - Q_OBJECT -public: - DirectShowPlayerControl(DirectShowPlayerService *service, QObject *parent = 0); - ~DirectShowPlayerControl(); - - QMediaPlayer::State state() const; - - QMediaPlayer::MediaStatus mediaStatus() const; - - qint64 duration() const; - - qint64 position() const; - void setPosition(qint64 position); - - int volume() const; - void setVolume(int volume); - - bool isMuted() const; - void setMuted(bool muted); - - int bufferStatus() const; - - bool isAudioAvailable() const; - bool isVideoAvailable() const; - - bool isSeekable() const; - - QMediaTimeRange availablePlaybackRanges() const; - - qreal playbackRate() const; - void setPlaybackRate(qreal rate); - - QMediaContent media() const; - const QIODevice *mediaStream() const; - void setMedia(const QMediaContent &media, QIODevice *stream); - - void play(); - void pause(); - void stop(); - - void updateState(QMediaPlayer::State state); - void updateStatus(QMediaPlayer::MediaStatus status); - void updateMediaInfo(qint64 duration, int streamTypes, bool seekable); - void updatePlaybackRate(qreal rate); - void updateAudioOutput(IBaseFilter *filter); - void updateError(QMediaPlayer::Error error, const QString &errorString); - void updatePosition(qint64 position); - -protected: - void customEvent(QEvent *event); - -private: - enum Properties - { - StateProperty = 0x01, - StatusProperty = 0x02, - StreamTypesProperty = 0x04, - DurationProperty = 0x08, - PlaybackRateProperty = 0x10, - SeekableProperty = 0x20, - ErrorProperty = 0x40, - PositionProperty = 0x80 - }; - - enum Event - { - PropertiesChanged = QEvent::User - }; - - void scheduleUpdate(int properties); - void emitPropertyChanges(); - - DirectShowPlayerService *m_service; - IBasicAudio *m_audio; - QIODevice *m_stream; - int m_updateProperties; - QMediaPlayer::State m_state; - QMediaPlayer::MediaStatus m_status; - QMediaPlayer::Error m_error; - int m_streamTypes; - int m_muteVolume; - qint64 m_position; - qint64 m_duration; - qreal m_playbackRate; - bool m_seekable; - QMediaContent m_media; - QString m_errorString; - -}; - -#endif diff --git a/src/plugins/directshow/player/directshowplayerservice.cpp b/src/plugins/directshow/player/directshowplayerservice.cpp deleted file mode 100644 index 2ba142c..0000000 --- a/src/plugins/directshow/player/directshowplayerservice.cpp +++ /dev/null @@ -1,1408 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "directshowplayerservice.h" - -#include "directshowaudioendpointcontrol.h" -#include "directshowiosource.h" -#include "directshowmetadatacontrol.h" -#include "directshowplayercontrol.h" -#include "directshowvideorenderercontrol.h" -#ifndef Q_WS_SIMULATOR -#include "vmr9videowindowcontrol.h" -#endif - -#include "qmediacontent.h" - -#include <QtCore/qcoreapplication.h> -#include <QtCore/qdatetime.h> -#include <QtCore/qthread.h> -#include <QtCore/qvarlengtharray.h> - -Q_GLOBAL_STATIC(DirectShowEventLoop, qt_directShowEventLoop) - - -// QMediaPlayer uses millisecond time units, direct show uses 100 nanosecond units. -static const int qt_directShowTimeScale = 10000; - -class DirectShowPlayerServiceThread : public QThread -{ -public: - DirectShowPlayerServiceThread(DirectShowPlayerService *service) - : m_service(service) - { - } - -protected: - void run() { m_service->run(); } - -private: - DirectShowPlayerService *m_service; -}; - -DirectShowPlayerService::DirectShowPlayerService(QObject *parent) - : QMediaService(parent) - , m_playerControl(0) - , m_metaDataControl(0) - , m_videoRendererControl(0) -#ifndef Q_WS_SIMULATOR - , m_videoWindowControl(0) -#endif - , m_audioEndpointControl(0) - , m_taskThread(0) - , m_loop(qt_directShowEventLoop()) - , m_pendingTasks(0) - , m_executingTask(0) - , m_executedTasks(0) - , m_taskHandle(::CreateEvent(0, 0, 0, 0)) - , m_eventHandle(0) - , m_graphStatus(NoMedia) - , m_stream(0) - , m_graph(0) - , m_source(0) - , m_audioOutput(0) - , m_videoOutput(0) - , m_rate(1.0) - , m_position(0) - , m_duration(0) - , m_buffering(false) - , m_seekable(false) - , m_atEnd(false) -{ - CoInitialize(NULL); - m_playerControl = new DirectShowPlayerControl(this); - m_metaDataControl = new DirectShowMetaDataControl(this); - m_audioEndpointControl = new DirectShowAudioEndpointControl(this); - - m_taskThread = new DirectShowPlayerServiceThread(this); - m_taskThread->start(); -} - -DirectShowPlayerService::~DirectShowPlayerService() -{ - { - QMutexLocker locker(&m_mutex); - - releaseGraph(); - - m_pendingTasks = Shutdown; - ::SetEvent(m_taskHandle); - } - - m_taskThread->wait(); - delete m_taskThread; - - if (m_audioOutput) { - m_audioOutput->Release(); - m_audioOutput = 0; - } - - if (m_videoOutput) { - m_videoOutput->Release(); - m_videoOutput = 0; - } - - delete m_playerControl; - delete m_audioEndpointControl; - delete m_metaDataControl; - delete m_videoRendererControl; -#ifndef Q_WS_SIMULATOR - delete m_videoWindowControl; -#endif - - ::CloseHandle(m_taskHandle); - CoUninitialize(); -} - -QMediaControl *DirectShowPlayerService::requestControl(const char *name) -{ - if (qstrcmp(name, QMediaPlayerControl_iid) == 0) { - return m_playerControl; - } else if (qstrcmp(name, QAudioEndpointSelector_iid) == 0) { - return m_audioEndpointControl; - } else if (qstrcmp(name, QMetaDataReaderControl_iid) == 0) { - return m_metaDataControl; - } else if (qstrcmp(name, QVideoRendererControl_iid) == 0) { -#ifndef Q_WS_SIMULATOR - if (!m_videoRendererControl && !m_videoWindowControl) { -#else - if (!m_videoRendererControl) { -#endif - m_videoRendererControl = new DirectShowVideoRendererControl(m_loop); - - connect(m_videoRendererControl, SIGNAL(filterChanged()), - this, SLOT(videoOutputChanged())); - - return m_videoRendererControl; - } -#ifndef Q_WS_SIMULATOR - } else if (qstrcmp(name, QVideoWindowControl_iid) == 0) { - if (!m_videoRendererControl && !m_videoWindowControl) { - m_videoWindowControl = new Vmr9VideoWindowControl; - - setVideoOutput(m_videoWindowControl->filter()); - - return m_videoWindowControl; - } -#endif - } - return 0; -} - -void DirectShowPlayerService::releaseControl(QMediaControl *control) -{ - if (!control) { - qWarning("QMediaService::releaseControl():" - " Attempted release of null control"); - } else if (control == m_videoRendererControl) { - setVideoOutput(0); - - delete m_videoRendererControl; - - m_videoRendererControl = 0; -#ifndef Q_WS_SIMULATOR - } else if (control == m_videoWindowControl) { - setVideoOutput(0); - - delete m_videoWindowControl; - - m_videoWindowControl = 0; -#endif - } -} - -void DirectShowPlayerService::load(const QMediaContent &media, QIODevice *stream) -{ - QMutexLocker locker(&m_mutex); - - m_pendingTasks = 0; - - if (m_graph) - releaseGraph(); - - m_resources = media.resources(); - m_stream = stream; - m_error = QMediaPlayer::NoError; - m_errorString = QString(); - m_position = 0; - m_duration = 0; - m_streamTypes = 0; - m_executedTasks = 0; - m_buffering = false; - m_seekable = false; - m_atEnd = false; - m_metaDataControl->updateGraph(0, 0); - - if (m_resources.isEmpty() && !stream) { - m_pendingTasks = 0; - m_graphStatus = NoMedia; - - m_url.clear(); - } else if (stream && (!stream->isReadable() || stream->isSequential())) { - m_pendingTasks = 0; - m_graphStatus = InvalidMedia; - m_error = QMediaPlayer::ResourceError; - } else { - // {36b73882-c2c8-11cf-8b46-00805f6cef60} - static const GUID iid_IFilterGraph2 = { - 0x36b73882, 0xc2c8, 0x11cf, {0x8b, 0x46, 0x00, 0x80, 0x5f, 0x6c, 0xef, 0x60} }; - m_graphStatus = Loading; - - m_graph = com_new<IFilterGraph2>(CLSID_FilterGraph, iid_IFilterGraph2); - - if (stream) - m_pendingTasks = SetStreamSource; - else - m_pendingTasks = SetUrlSource; - - ::SetEvent(m_taskHandle); - } - - m_playerControl->updateError(m_error, m_errorString); - m_playerControl->updateMediaInfo(m_duration, m_streamTypes, m_seekable); - m_playerControl->updateState(QMediaPlayer::StoppedState); - m_playerControl->updatePosition(m_position); - updateStatus(); -} - -void DirectShowPlayerService::doSetUrlSource(QMutexLocker *locker) -{ - IBaseFilter *source = 0; - - QMediaResource resource = m_resources.takeFirst(); - QUrl url = resource.url(); - - HRESULT hr = E_FAIL; - - if (url.scheme() == QLatin1String("http") || url.scheme() == QLatin1String("https")) { - static const GUID clsid_WMAsfReader = { - 0x187463a0, 0x5bb7, 0x11d3, {0xac, 0xbe, 0x00, 0x80, 0xc7, 0x5e, 0x24, 0x6e} }; - - // {56a868a6-0ad4-11ce-b03a-0020af0ba770} - static const GUID iid_IFileSourceFilter = { - 0x56a868a6, 0x0ad4, 0x11ce, {0xb0, 0x3a, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70} }; - - if (IFileSourceFilter *fileSource = com_new<IFileSourceFilter>( - clsid_WMAsfReader, iid_IFileSourceFilter)) { - locker->unlock(); - hr = fileSource->Load(reinterpret_cast<const OLECHAR *>(url.toString().utf16()), 0); - - if (SUCCEEDED(hr)) { - source = com_cast<IBaseFilter>(fileSource, IID_IBaseFilter); - - if (!SUCCEEDED(hr = m_graph->AddFilter(source, L"Source")) && source) { - source->Release(); - source = 0; - } - } - fileSource->Release(); - locker->relock(); - } - } else if (url.scheme() == QLatin1String("qrc")) { - DirectShowRcSource *rcSource = new DirectShowRcSource(m_loop); - - locker->unlock(); - if (rcSource->open(url) && SUCCEEDED(hr = m_graph->AddFilter(rcSource, L"Source"))) - source = rcSource; - else - rcSource->Release(); - locker->relock(); - } - - if (!SUCCEEDED(hr)) { - locker->unlock(); - hr = m_graph->AddSourceFilter( - reinterpret_cast<const OLECHAR *>(url.toString().utf16()), L"Source", &source); - locker->relock(); - } - - if (SUCCEEDED(hr)) { - m_executedTasks = SetSource; - m_pendingTasks |= Render; - - if (m_audioOutput) - m_pendingTasks |= SetAudioOutput; - if (m_videoOutput) - m_pendingTasks |= SetVideoOutput; - - if (m_rate != 1.0) - m_pendingTasks |= SetRate; - - m_source = source; - } else if (!m_resources.isEmpty()) { - m_pendingTasks |= SetUrlSource; - } else { - m_pendingTasks = 0; - m_graphStatus = InvalidMedia; - - switch (hr) { - case VFW_E_UNKNOWN_FILE_TYPE: - m_error = QMediaPlayer::FormatError; - m_errorString = QString(); - break; - case E_OUTOFMEMORY: - case VFW_E_CANNOT_LOAD_SOURCE_FILTER: - case VFW_E_NOT_FOUND: - m_error = QMediaPlayer::ResourceError; - m_errorString = QString(); - break; - default: - m_error = QMediaPlayer::ResourceError; - m_errorString = QString(); - qWarning("DirectShowPlayerService::doSetUrlSource: Unresolved error code %x", uint(hr)); - break; - } - - QCoreApplication::postEvent(this, new QEvent(QEvent::Type(Error))); - } -} - -void DirectShowPlayerService::doSetStreamSource(QMutexLocker *locker) -{ - DirectShowIOSource *source = new DirectShowIOSource(m_loop); - source->setDevice(m_stream); - - if (SUCCEEDED(m_graph->AddFilter(source, L"Source"))) { - m_executedTasks = SetSource; - m_pendingTasks |= Render; - - if (m_audioOutput) - m_pendingTasks |= SetAudioOutput; - if (m_videoOutput) - m_pendingTasks |= SetVideoOutput; - - if (m_rate != 1.0) - m_pendingTasks |= SetRate; - - m_source = source; - } else { - source->Release(); - - m_pendingTasks = 0; - m_graphStatus = InvalidMedia; - - m_error = QMediaPlayer::ResourceError; - m_errorString = QString(); - - QCoreApplication::postEvent(this, new QEvent(QEvent::Type(Error))); - } -} - -void DirectShowPlayerService::doRender(QMutexLocker *locker) -{ - m_pendingTasks |= m_executedTasks & (Play | Pause); - - if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) { - control->Stop(); - control->Release(); - } - - if (m_pendingTasks & SetAudioOutput) { - m_graph->AddFilter(m_audioOutput, L"AudioOutput"); - - m_pendingTasks ^= SetAudioOutput; - m_executedTasks |= SetAudioOutput; - } - if (m_pendingTasks & SetVideoOutput) { - m_graph->AddFilter(m_videoOutput, L"VideoOutput"); - - m_pendingTasks ^= SetVideoOutput; - m_executedTasks |= SetVideoOutput; - } - - IFilterGraph2 *graph = m_graph; - graph->AddRef(); - - QVarLengthArray<IBaseFilter *, 16> filters; - m_source->AddRef(); - filters.append(m_source); - - bool rendered = false; - - HRESULT renderHr = S_OK; - - while (!filters.isEmpty()) { - IEnumPins *pins = 0; - IBaseFilter *filter = filters[filters.size() - 1]; - filters.removeLast(); - - if (!(m_pendingTasks & ReleaseFilters) && SUCCEEDED(filter->EnumPins(&pins))) { - int outputs = 0; - for (IPin *pin = 0; pins->Next(1, &pin, 0) == S_OK; pin->Release()) { - PIN_DIRECTION direction; - if (pin->QueryDirection(&direction) == S_OK && direction == PINDIR_OUTPUT) { - ++outputs; - - IPin *peer = 0; - if (pin->ConnectedTo(&peer) == S_OK) { - PIN_INFO peerInfo; - if (SUCCEEDED(peer->QueryPinInfo(&peerInfo))) - filters.append(peerInfo.pFilter); - peer->Release(); - } else { - locker->unlock(); - HRESULT hr; - if (SUCCEEDED(hr = graph->RenderEx( - pin, /*AM_RENDEREX_RENDERTOEXISTINGRENDERERS*/ 1, 0))) { - rendered = true; - } else if (renderHr == S_OK || renderHr == VFW_E_NO_DECOMPRESSOR){ - renderHr = hr; - } - locker->relock(); - } - } - } - - pins->Release(); - - if (outputs == 0) - rendered = true; - } - filter->Release(); - } - - if (m_audioOutput && !isConnected(m_audioOutput, PINDIR_INPUT)) { - graph->RemoveFilter(m_audioOutput); - - m_executedTasks &= ~SetAudioOutput; - } - - if (m_videoOutput && !isConnected(m_videoOutput, PINDIR_INPUT)) { - graph->RemoveFilter(m_videoOutput); - - m_executedTasks &= ~SetVideoOutput; - } - - graph->Release(); - - if (!(m_pendingTasks & ReleaseFilters)) { - if (rendered) { - if (!(m_executedTasks & FinalizeLoad)) - m_pendingTasks |= FinalizeLoad; - } else { - m_pendingTasks = 0; - - m_graphStatus = InvalidMedia; - - if (!m_audioOutput && !m_videoOutput) { - m_error = QMediaPlayer::ResourceError; - m_errorString = QString(); - } else { - switch (renderHr) { - case VFW_E_UNSUPPORTED_AUDIO: - case VFW_E_UNSUPPORTED_VIDEO: - case VFW_E_UNSUPPORTED_STREAM: - m_error = QMediaPlayer::FormatError; - m_errorString = QString(); - break; - default: - m_error = QMediaPlayer::ResourceError; - m_errorString = QString(); - qWarning("DirectShowPlayerService::doRender: Unresolved error code %x", - uint(renderHr)); - } - } - - QCoreApplication::postEvent(this, new QEvent(QEvent::Type(Error))); - } - - m_executedTasks |= Render; - } - - m_loop->wake(); -} - -void DirectShowPlayerService::doFinalizeLoad(QMutexLocker *locker) -{ - if (m_graphStatus != Loaded) { - if (IMediaEvent *event = com_cast<IMediaEvent>(m_graph, IID_IMediaEvent)) { - event->GetEventHandle(reinterpret_cast<OAEVENT *>(&m_eventHandle)); - event->Release(); - } - if (IMediaSeeking *seeking = com_cast<IMediaSeeking>(m_graph, IID_IMediaSeeking)) { - LONGLONG duration = 0; - seeking->GetDuration(&duration); - m_duration = duration / qt_directShowTimeScale; - - DWORD capabilities = 0; - seeking->GetCapabilities(&capabilities); - m_seekable = capabilities & AM_SEEKING_CanSeekAbsolute; - - seeking->Release(); - } - } - - if ((m_executedTasks & SetOutputs) == SetOutputs) { - m_streamTypes = AudioStream | VideoStream; - } else { - m_streamTypes = findStreamTypes(m_source); - } - - m_executedTasks |= FinalizeLoad; - - m_graphStatus = Loaded; - - QCoreApplication::postEvent(this, new QEvent(QEvent::Type(FinalizedLoad))); -} - -void DirectShowPlayerService::releaseGraph() -{ - if (m_graph) { - if (m_executingTask != 0) { - // {8E1C39A1-DE53-11cf-AA63-0080C744528D} - static const GUID iid_IAMOpenProgress = { - 0x8E1C39A1, 0xDE53, 0x11cf, {0xAA, 0x63, 0x00, 0x80, 0xC7, 0x44, 0x52, 0x8D} }; - - if (IAMOpenProgress *progress = com_cast<IAMOpenProgress>( - m_graph, iid_IAMOpenProgress)) { - progress->AbortOperation(); - progress->Release(); - } - m_graph->Abort(); - } - - m_pendingTasks = ReleaseGraph; - - ::SetEvent(m_taskHandle); - - m_loop->wait(&m_mutex); - } -} - -void DirectShowPlayerService::doReleaseGraph(QMutexLocker *locker) -{ - Q_UNUSED(locker); - - if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) { - control->Stop(); - control->Release(); - } - - if (m_source) { - m_source->Release(); - m_source = 0; - } - - m_eventHandle = 0; - - m_graph->Release(); - m_graph = 0; - - m_loop->wake(); -} - -int DirectShowPlayerService::findStreamTypes(IBaseFilter *source) const -{ - QVarLengthArray<IBaseFilter *, 16> filters; - source->AddRef(); - filters.append(source); - - int streamTypes = 0; - - while (!filters.isEmpty()) { - IEnumPins *pins = 0; - IBaseFilter *filter = filters[filters.size() - 1]; - filters.removeLast(); - - if (SUCCEEDED(filter->EnumPins(&pins))) { - for (IPin *pin = 0; pins->Next(1, &pin, 0) == S_OK; pin->Release()) { - PIN_DIRECTION direction; - if (pin->QueryDirection(&direction) == S_OK && direction == PINDIR_OUTPUT) { - AM_MEDIA_TYPE connectionType; - if (SUCCEEDED(pin->ConnectionMediaType(&connectionType))) { - IPin *peer = 0; - - if (connectionType.majortype == MEDIATYPE_Audio) { - streamTypes |= AudioStream; - } else if (connectionType.majortype == MEDIATYPE_Video) { - streamTypes |= VideoStream; - } else if (SUCCEEDED(pin->ConnectedTo(&peer))) { - PIN_INFO peerInfo; - if (SUCCEEDED(peer->QueryPinInfo(&peerInfo))) - filters.append(peerInfo.pFilter); - peer->Release(); - } - } else { - streamTypes |= findStreamType(pin); - } - } - } - } - filter->Release(); - } - return streamTypes; -} - -int DirectShowPlayerService::findStreamType(IPin *pin) const -{ - IEnumMediaTypes *types; - - if (SUCCEEDED(pin->EnumMediaTypes(&types))) { - bool video = false; - bool audio = false; - bool other = false; - - for (AM_MEDIA_TYPE *type = 0; - types->Next(1, &type, 0) == S_OK; - DirectShowMediaType::deleteType(type)) { - if (type->majortype == MEDIATYPE_Audio) - audio = true; - else if (type->majortype == MEDIATYPE_Video) - video = true; - else - other = true; - } - types->Release(); - - if (other) - return 0; - else if (audio && !video) - return AudioStream; - else if (!audio && video) - return VideoStream; - else - return 0; - } else { - return 0; - } -} - -void DirectShowPlayerService::play() -{ - QMutexLocker locker(&m_mutex); - - m_pendingTasks &= ~Pause; - m_pendingTasks |= Play; - - if (m_executedTasks & Render) { - if (m_executedTasks & Stop) { - m_atEnd = false; - m_position = 0; - m_pendingTasks |= Seek; - m_executedTasks ^= Stop; - } - - ::SetEvent(m_taskHandle); - } - - updateStatus(); -} - -void DirectShowPlayerService::doPlay(QMutexLocker *locker) -{ - if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) { - locker->unlock(); - HRESULT hr = control->Run(); - locker->relock(); - - control->Release(); - - if (SUCCEEDED(hr)) { - m_executedTasks |= Play; - - QCoreApplication::postEvent(this, new QEvent(QEvent::Type(StatusChange))); - } else { - m_error = QMediaPlayer::ResourceError; - m_errorString = QString(); - qWarning("DirectShowPlayerService::doPlay: Unresolved error code %x", uint(hr)); - - QCoreApplication::postEvent(this, new QEvent(QEvent::Type(Error))); - } - } -} - -void DirectShowPlayerService::pause() -{ - QMutexLocker locker(&m_mutex); - - m_pendingTasks &= ~Play; - m_pendingTasks |= Pause; - - if (m_executedTasks & Render) { - if (m_executedTasks & Stop) { - m_atEnd = false; - m_position = 0; - m_pendingTasks |= Seek; - m_executedTasks ^= Stop; - } - - ::SetEvent(m_taskHandle); - } - - updateStatus(); -} - -void DirectShowPlayerService::doPause(QMutexLocker *locker) -{ - if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) { - locker->unlock(); - HRESULT hr = control->Pause(); - locker->relock(); - - control->Release(); - - if (SUCCEEDED(hr)) { - if (IMediaSeeking *seeking = com_cast<IMediaSeeking>(m_graph, IID_IMediaSeeking)) { - LONGLONG position = 0; - - seeking->GetCurrentPosition(&position); - seeking->Release(); - - m_position = position / qt_directShowTimeScale; - } else { - m_position = 0; - } - - m_executedTasks |= Pause; - - QCoreApplication::postEvent(this, new QEvent(QEvent::Type(StatusChange))); - } else { - m_error = QMediaPlayer::ResourceError; - m_errorString = QString(); - qWarning("DirectShowPlayerService::doPause: Unresolved error code %x", uint(hr)); - - QCoreApplication::postEvent(this, new QEvent(QEvent::Type(Error))); - } - } -} - -void DirectShowPlayerService::stop() -{ - QMutexLocker locker(&m_mutex); - - m_pendingTasks &= ~(Play | Pause | Seek); - - if ((m_executingTask | m_executedTasks) & (Play | Pause | Seek)) { - m_pendingTasks |= Stop; - - ::SetEvent(m_taskHandle); - - m_loop->wait(&m_mutex); - } - - updateStatus(); -} - -void DirectShowPlayerService::doStop(QMutexLocker *locker) -{ - if (m_executedTasks & (Play | Pause)) { - if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) { - control->Stop(); - control->Release(); - } - - m_position = 0; - m_pendingTasks |= Seek; - - m_executedTasks &= ~(Play | Pause); - - QCoreApplication::postEvent(this, new QEvent(QEvent::Type(StatusChange))); - } - - m_executedTasks |= Stop; - - m_loop->wake(); -} - -void DirectShowPlayerService::setRate(qreal rate) -{ - QMutexLocker locker(&m_mutex); - - m_rate = rate; - - m_pendingTasks |= SetRate; - - if (m_executedTasks & FinalizeLoad) - ::SetEvent(m_taskHandle); -} - -void DirectShowPlayerService::doSetRate(QMutexLocker *locker) -{ - if (IMediaSeeking *seeking = com_cast<IMediaSeeking>(m_graph, IID_IMediaSeeking)) { - // Cache current values as we can't query IMediaSeeking during a seek due to the - // possibility of a deadlock when flushing the VideoSurfaceFilter. - LONGLONG currentPosition = 0; - seeking->GetCurrentPosition(¤tPosition); - m_position = currentPosition / qt_directShowTimeScale; - - LONGLONG minimum = 0; - LONGLONG maximum = 0; - m_playbackRange = SUCCEEDED(seeking->GetAvailable(&minimum, &maximum)) - ? QMediaTimeRange(minimum / qt_directShowTimeScale, maximum / qt_directShowTimeScale) - : QMediaTimeRange(); - - locker->unlock(); - HRESULT hr = seeking->SetRate(m_rate); - locker->relock(); - - if (!SUCCEEDED(hr)) { - double rate = 0.0; - m_rate = seeking->GetRate(&rate) - ? rate - : 1.0; - } - - seeking->Release(); - } else if (m_rate != 1.0) { - m_rate = 1.0; - } - QCoreApplication::postEvent(this, new QEvent(QEvent::Type(RateChange))); -} - -qint64 DirectShowPlayerService::position() const -{ - QMutexLocker locker(const_cast<QMutex *>(&m_mutex)); - - if (m_graphStatus == Loaded) { - if (m_executingTask == Seek || m_executingTask == SetRate || (m_pendingTasks & Seek)) { - return m_position; - } else if (IMediaSeeking *seeking = com_cast<IMediaSeeking>(m_graph, IID_IMediaSeeking)) { - LONGLONG position = 0; - - seeking->GetCurrentPosition(&position); - seeking->Release(); - - const_cast<qint64 &>(m_position) = position / qt_directShowTimeScale; - - return m_position; - } - } - return 0; -} - -QMediaTimeRange DirectShowPlayerService::availablePlaybackRanges() const -{ - QMutexLocker locker(const_cast<QMutex *>(&m_mutex)); - - if (m_graphStatus == Loaded) { - if (m_executingTask == Seek || m_executingTask == SetRate || (m_pendingTasks & Seek)) { - return m_playbackRange; - } else if (IMediaSeeking *seeking = com_cast<IMediaSeeking>(m_graph, IID_IMediaSeeking)) { - LONGLONG minimum = 0; - LONGLONG maximum = 0; - - HRESULT hr = seeking->GetAvailable(&minimum, &maximum); - seeking->Release(); - - if (SUCCEEDED(hr)) - return QMediaTimeRange(minimum, maximum); - } - } - return QMediaTimeRange(); -} - -void DirectShowPlayerService::seek(qint64 position) -{ - QMutexLocker locker(&m_mutex); - - m_position = position; - - m_pendingTasks |= Seek; - - if (m_executedTasks & FinalizeLoad) - ::SetEvent(m_taskHandle); -} - -void DirectShowPlayerService::doSeek(QMutexLocker *locker) -{ - if (IMediaSeeking *seeking = com_cast<IMediaSeeking>(m_graph, IID_IMediaSeeking)) { - LONGLONG seekPosition = LONGLONG(m_position) * qt_directShowTimeScale; - - // Cache current values as we can't query IMediaSeeking during a seek due to the - // possibility of a deadlock when flushing the VideoSurfaceFilter. - LONGLONG currentPosition = 0; - seeking->GetCurrentPosition(¤tPosition); - m_position = currentPosition / qt_directShowTimeScale; - - LONGLONG minimum = 0; - LONGLONG maximum = 0; - m_playbackRange = SUCCEEDED(seeking->GetAvailable(&minimum, &maximum)) - ? QMediaTimeRange( - minimum / qt_directShowTimeScale, maximum / qt_directShowTimeScale) - : QMediaTimeRange(); - - locker->unlock(); - seeking->SetPositions( - &seekPosition, AM_SEEKING_AbsolutePositioning, 0, AM_SEEKING_NoPositioning); - locker->relock(); - - seeking->GetCurrentPosition(¤tPosition); - m_position = currentPosition / qt_directShowTimeScale; - - seeking->Release(); - } else { - m_position = 0; - } - - QCoreApplication::postEvent(this, new QEvent(QEvent::Type(PositionChange))); -} - -int DirectShowPlayerService::bufferStatus() const -{ -#ifndef QT_NO_WMSDK - QMutexLocker locker(const_cast<QMutex *>(&m_mutex)); - - if (IWMReaderAdvanced2 *reader = com_cast<IWMReaderAdvanced2>( - m_source, IID_IWMReaderAdvanced2)) { - DWORD percentage = 0; - - reader->GetBufferProgress(&percentage, 0); - reader->Release(); - - return percentage; - } else { - return 0; - } -#else - return 0; -#endif -} - -void DirectShowPlayerService::setAudioOutput(IBaseFilter *filter) -{ - QMutexLocker locker(&m_mutex); - - if (m_graph) { - if (m_audioOutput) { - if (m_executedTasks & SetAudioOutput) { - m_pendingTasks |= ReleaseAudioOutput; - - ::SetEvent(m_taskHandle); - - m_loop->wait(&m_mutex); - } - m_audioOutput->Release(); - } - - m_audioOutput = filter; - - if (m_audioOutput) { - m_audioOutput->AddRef(); - - m_pendingTasks |= SetAudioOutput; - - if (m_executedTasks & SetSource) { - m_pendingTasks |= Render; - - ::SetEvent(m_taskHandle); - } - } else { - m_pendingTasks &= ~ SetAudioOutput; - } - } else { - if (m_audioOutput) - m_audioOutput->Release(); - - m_audioOutput = filter; - - if (m_audioOutput) - m_audioOutput->AddRef(); - } - - m_playerControl->updateAudioOutput(m_audioOutput); -} - -void DirectShowPlayerService::doReleaseAudioOutput(QMutexLocker *locker) -{ - m_pendingTasks |= m_executedTasks & (Play | Pause); - - if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) { - control->Stop(); - control->Release(); - } - - IBaseFilter *decoder = getConnected(m_audioOutput, PINDIR_INPUT); - if (!decoder) { - decoder = m_audioOutput; - decoder->AddRef(); - } - - // {DCFBDCF6-0DC2-45f5-9AB2-7C330EA09C29} - static const GUID iid_IFilterChain = { - 0xDCFBDCF6, 0x0DC2, 0x45f5, {0x9A, 0xB2, 0x7C, 0x33, 0x0E, 0xA0, 0x9C, 0x29} }; - - if (IFilterChain *chain = com_cast<IFilterChain>(m_graph, iid_IFilterChain)) { - chain->RemoveChain(decoder, m_audioOutput); - chain->Release(); - } else { - m_graph->RemoveFilter(m_audioOutput); - } - - decoder->Release(); - - m_executedTasks &= ~SetAudioOutput; - - m_loop->wake(); -} - -void DirectShowPlayerService::setVideoOutput(IBaseFilter *filter) -{ - QMutexLocker locker(&m_mutex); - - if (m_graph) { - if (m_videoOutput) { - if (m_executedTasks & SetVideoOutput) { - m_pendingTasks |= ReleaseVideoOutput; - - ::SetEvent(m_taskHandle); - - m_loop->wait(&m_mutex); - } - m_videoOutput->Release(); - } - - m_videoOutput = filter; - - if (m_videoOutput) { - m_videoOutput->AddRef(); - - m_pendingTasks |= SetVideoOutput; - - if (m_executedTasks & SetSource) { - m_pendingTasks |= Render; - - ::SetEvent(m_taskHandle); - } - } - } else { - if (m_videoOutput) - m_videoOutput->Release(); - - m_videoOutput = filter; - - if (m_videoOutput) - m_videoOutput->AddRef(); - } -} - -void DirectShowPlayerService::doReleaseVideoOutput(QMutexLocker *locker) -{ - m_pendingTasks |= m_executedTasks & (Play | Pause); - - if (IMediaControl *control = com_cast<IMediaControl>(m_graph, IID_IMediaControl)) { - control->Stop(); - control->Release(); - } - - IBaseFilter *intermediate = 0; - if (!SUCCEEDED(m_graph->FindFilterByName(L"Color Space Converter", &intermediate))) { - intermediate = m_videoOutput; - intermediate->AddRef(); - } - - IBaseFilter *decoder = getConnected(intermediate, PINDIR_INPUT); - if (!decoder) { - decoder = intermediate; - decoder->AddRef(); - } - - // {DCFBDCF6-0DC2-45f5-9AB2-7C330EA09C29} - static const GUID iid_IFilterChain = { - 0xDCFBDCF6, 0x0DC2, 0x45f5, {0x9A, 0xB2, 0x7C, 0x33, 0x0E, 0xA0, 0x9C, 0x29} }; - - if (IFilterChain *chain = com_cast<IFilterChain>(m_graph, iid_IFilterChain)) { - chain->RemoveChain(decoder, m_videoOutput); - chain->Release(); - } else { - m_graph->RemoveFilter(m_videoOutput); - } - - intermediate->Release(); - decoder->Release(); - - m_executedTasks &= ~SetVideoOutput; - - m_loop->wake(); -} - -void DirectShowPlayerService::customEvent(QEvent *event) -{ - if (event->type() == QEvent::Type(FinalizedLoad)) { - QMutexLocker locker(&m_mutex); - - m_playerControl->updateMediaInfo(m_duration, m_streamTypes, m_seekable); - m_metaDataControl->updateGraph(m_graph, m_source); - - updateStatus(); - } else if (event->type() == QEvent::Type(Error)) { - QMutexLocker locker(&m_mutex); - - if (m_error != QMediaPlayer::NoError) { - m_playerControl->updateError(m_error, m_errorString); - m_playerControl->updateMediaInfo(m_duration, m_streamTypes, m_seekable); - m_playerControl->updateState(QMediaPlayer::StoppedState); - updateStatus(); - } - } else if (event->type() == QEvent::Type(RateChange)) { - QMutexLocker locker(&m_mutex); - - m_playerControl->updatePlaybackRate(m_rate); - } else if (event->type() == QEvent::Type(StatusChange)) { - QMutexLocker locker(&m_mutex); - - updateStatus(); - m_playerControl->updatePosition(m_position); - } else if (event->type() == QEvent::Type(DurationChange)) { - QMutexLocker locker(&m_mutex); - - m_playerControl->updateMediaInfo(m_duration, m_streamTypes, m_seekable); - } else if (event->type() == QEvent::Type(EndOfMedia)) { - QMutexLocker locker(&m_mutex); - - if (m_atEnd) { - m_playerControl->updateState(QMediaPlayer::StoppedState); - m_playerControl->updateStatus(QMediaPlayer::EndOfMedia); - m_playerControl->updatePosition(m_position); - } - } else if (event->type() == QEvent::Type(PositionChange)) { - QMutexLocker locker(&m_mutex); - - if (m_playerControl->mediaStatus() == QMediaPlayer::EndOfMedia) - m_playerControl->updateStatus(QMediaPlayer::LoadedMedia); - m_playerControl->updatePosition(m_position); - } else { - QMediaService::customEvent(event); - } -} - -void DirectShowPlayerService::videoOutputChanged() -{ - setVideoOutput(m_videoRendererControl->filter()); -} - -void DirectShowPlayerService::graphEvent(QMutexLocker *locker) -{ - if (IMediaEvent *event = com_cast<IMediaEvent>(m_graph, IID_IMediaEvent)) { - long eventCode; - LONG_PTR param1; - LONG_PTR param2; - - while (event->GetEvent(&eventCode, ¶m1, ¶m2, 0) == S_OK) { - switch (eventCode) { - case EC_BUFFERING_DATA: - m_buffering = param1; - - QCoreApplication::postEvent(this, new QEvent(QEvent::Type(StatusChange))); - break; - case EC_COMPLETE: - m_executedTasks &= ~(Play | Pause); - m_executedTasks |= Stop; - - m_buffering = false; - m_atEnd = true; - - if (IMediaSeeking *seeking = com_cast<IMediaSeeking>(m_graph, IID_IMediaSeeking)) { - LONGLONG position = 0; - - seeking->GetCurrentPosition(&position); - seeking->Release(); - - m_position = position / qt_directShowTimeScale; - } - - QCoreApplication::postEvent(this, new QEvent(QEvent::Type(EndOfMedia))); - break; - case EC_LENGTH_CHANGED: - if (IMediaSeeking *seeking = com_cast<IMediaSeeking>(m_graph, IID_IMediaSeeking)) { - LONGLONG duration = 0; - seeking->GetDuration(&duration); - m_duration = duration / qt_directShowTimeScale; - - DWORD capabilities = 0; - seeking->GetCapabilities(&capabilities); - m_seekable = capabilities & AM_SEEKING_CanSeekAbsolute; - - seeking->Release(); - - QCoreApplication::postEvent(this, new QEvent(QEvent::Type(DurationChange))); - } - break; - default: - break; - } - - event->FreeEventParams(eventCode, param1, param2); - } - event->Release(); - } -} - -void DirectShowPlayerService::updateStatus() -{ - switch (m_graphStatus) { - case NoMedia: - m_playerControl->updateStatus(QMediaPlayer::NoMedia); - break; - case Loading: - m_playerControl->updateStatus(QMediaPlayer::LoadingMedia); - break; - case Loaded: - if ((m_pendingTasks | m_executingTask | m_executedTasks) & (Play | Pause)) { - if (m_buffering) - m_playerControl->updateStatus(QMediaPlayer::BufferingMedia); - else - m_playerControl->updateStatus(QMediaPlayer::BufferedMedia); - } else { - m_playerControl->updateStatus(QMediaPlayer::LoadedMedia); - } - break; - case InvalidMedia: - m_playerControl->updateStatus(QMediaPlayer::InvalidMedia); - break; - default: - m_playerControl->updateStatus(QMediaPlayer::UnknownMediaStatus); - } -} - -bool DirectShowPlayerService::isConnected(IBaseFilter *filter, PIN_DIRECTION direction) const -{ - bool connected = false; - - IEnumPins *pins = 0; - - if (SUCCEEDED(filter->EnumPins(&pins))) { - for (IPin *pin = 0; pins->Next(1, &pin, 0) == S_OK; pin->Release()) { - PIN_DIRECTION dir; - if (SUCCEEDED(pin->QueryDirection(&dir)) && dir == direction) { - IPin *peer = 0; - if (SUCCEEDED(pin->ConnectedTo(&peer))) { - connected = true; - - peer->Release(); - } - } - } - pins->Release(); - } - return connected; -} - -IBaseFilter *DirectShowPlayerService::getConnected( - IBaseFilter *filter, PIN_DIRECTION direction) const -{ - IBaseFilter *connected = 0; - - IEnumPins *pins = 0; - - if (SUCCEEDED(filter->EnumPins(&pins))) { - for (IPin *pin = 0; pins->Next(1, &pin, 0) == S_OK; pin->Release()) { - PIN_DIRECTION dir; - if (SUCCEEDED(pin->QueryDirection(&dir)) && dir == direction) { - IPin *peer = 0; - if (SUCCEEDED(pin->ConnectedTo(&peer))) { - PIN_INFO info; - - if (SUCCEEDED(peer->QueryPinInfo(&info))) { - if (connected) { - qWarning("DirectShowPlayerService::getConnected: " - "Multiple connected filters"); - connected->Release(); - } - connected = info.pFilter; - } - peer->Release(); - } - } - } - pins->Release(); - } - return connected; -} - -void DirectShowPlayerService::run() -{ - QMutexLocker locker(&m_mutex); - - for (;;) { - ::ResetEvent(m_taskHandle); - - while (m_pendingTasks == 0) { - DWORD result = 0; - - locker.unlock(); - if (m_eventHandle) { - HANDLE handles[] = { m_taskHandle, m_eventHandle }; - - result = ::WaitForMultipleObjects(2, handles, false, INFINITE); - } else { - result = ::WaitForSingleObject(m_taskHandle, INFINITE); - } - locker.relock(); - - if (result == WAIT_OBJECT_0 + 1) { - graphEvent(&locker); - } - } - - if (m_pendingTasks & ReleaseGraph) { - m_pendingTasks ^= ReleaseGraph; - m_executingTask = ReleaseGraph; - - doReleaseGraph(&locker); - //if the graph is released, we should not process other operations later - if (m_pendingTasks & Shutdown) { - m_pendingTasks = 0; - return; - } - m_pendingTasks = 0; - } else if (m_pendingTasks & Shutdown) { - return; - } else if (m_pendingTasks & ReleaseAudioOutput) { - m_pendingTasks ^= ReleaseAudioOutput; - m_executingTask = ReleaseAudioOutput; - - doReleaseAudioOutput(&locker); - } else if (m_pendingTasks & ReleaseVideoOutput) { - m_pendingTasks ^= ReleaseVideoOutput; - m_executingTask = ReleaseVideoOutput; - - doReleaseVideoOutput(&locker); - } else if (m_pendingTasks & SetUrlSource) { - m_pendingTasks ^= SetUrlSource; - m_executingTask = SetUrlSource; - - doSetUrlSource(&locker); - } else if (m_pendingTasks & SetStreamSource) { - m_pendingTasks ^= SetStreamSource; - m_executingTask = SetStreamSource; - - doSetStreamSource(&locker); - } else if (m_pendingTasks & Render) { - m_pendingTasks ^= Render; - m_executingTask = Render; - - doRender(&locker); - } else if (!(m_executedTasks & Render)) { - m_pendingTasks &= ~(FinalizeLoad | SetRate | Stop | Pause | Seek | Play); - } else if (m_pendingTasks & FinalizeLoad) { - m_pendingTasks ^= FinalizeLoad; - m_executingTask = FinalizeLoad; - - doFinalizeLoad(&locker); - } else if (m_pendingTasks & Stop) { - m_pendingTasks ^= Stop; - m_executingTask = Stop; - - doStop(&locker); - } else if (m_pendingTasks & SetRate) { - m_pendingTasks ^= SetRate; - m_executingTask = SetRate; - - doSetRate(&locker); - } else if (m_pendingTasks & Pause) { - m_pendingTasks ^= Pause; - m_executingTask = Pause; - - doPause(&locker); - } else if (m_pendingTasks & Seek) { - m_pendingTasks ^= Seek; - m_executingTask = Seek; - - doSeek(&locker); - } else if (m_pendingTasks & Play) { - m_pendingTasks ^= Play; - m_executingTask = Play; - - doPlay(&locker); - } - m_executingTask = 0; - } -} diff --git a/src/plugins/directshow/player/directshowplayerservice.h b/src/plugins/directshow/player/directshowplayerservice.h deleted file mode 100644 index 0f36bdf..0000000 --- a/src/plugins/directshow/player/directshowplayerservice.h +++ /dev/null @@ -1,219 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DIRECTSHOWPLAYERSERVICE_H -#define DIRECTSHOWPLAYERSERVICE_H - -#include "qmediaplayer.h" -#include "qmediaresource.h" -#include "qmediaservice.h" -#include "qmediatimerange.h" - -#include "directshoweventloop.h" -#include "directshowglobal.h" - -#include <QtCore/qcoreevent.h> -#include <QtCore/qmutex.h> -#include <QtCore/qurl.h> -#include <QtCore/qwaitcondition.h> - -class DirectShowAudioEndpointControl; -class DirectShowMetaDataControl; -class DirectShowPlayerControl; -class DirectShowVideoRendererControl; -#ifndef Q_WS_SIMULATOR -class Vmr9VideoWindowControl; -#endif - -QT_BEGIN_NAMESPACE -class QMediaContent; -QT_END_NAMESPACE - -QT_USE_NAMESPACE - -class DirectShowPlayerService : public QMediaService -{ - Q_OBJECT -public: - enum StreamType - { - AudioStream = 0x01, - VideoStream = 0x02 - }; - - DirectShowPlayerService(QObject *parent = 0); - ~DirectShowPlayerService(); - - QMediaControl* requestControl(const char *name); - void releaseControl(QMediaControl *control); - - void load(const QMediaContent &media, QIODevice *stream); - void play(); - void pause(); - void stop(); - - qint64 position() const; - QMediaTimeRange availablePlaybackRanges() const; - - void seek(qint64 position); - void setRate(qreal rate); - - int bufferStatus() const; - - void setAudioOutput(IBaseFilter *filter); - void setVideoOutput(IBaseFilter *filter); - -protected: - void customEvent(QEvent *event); - -private Q_SLOTS: - void videoOutputChanged(); - -private: - void releaseGraph(); - void updateStatus(); - - int findStreamTypes(IBaseFilter *source) const; - int findStreamType(IPin *pin) const; - - bool isConnected(IBaseFilter *filter, PIN_DIRECTION direction) const; - IBaseFilter *getConnected(IBaseFilter *filter, PIN_DIRECTION direction) const; - - void run(); - - void doSetUrlSource(QMutexLocker *locker); - void doSetStreamSource(QMutexLocker *locker); - void doRender(QMutexLocker *locker); - void doFinalizeLoad(QMutexLocker *locker); - void doSetRate(QMutexLocker *locker); - void doSeek(QMutexLocker *locker); - void doPlay(QMutexLocker *locker); - void doPause(QMutexLocker *locker); - void doStop(QMutexLocker *locker); - void doReleaseAudioOutput(QMutexLocker *locker); - void doReleaseVideoOutput(QMutexLocker *locker); - void doReleaseGraph(QMutexLocker *locker); - - void graphEvent(QMutexLocker *locker); - - enum Task - { - Shutdown = 0x0001, - SetUrlSource = 0x0002, - SetStreamSource = 0x0004, - SetSource = SetUrlSource | SetStreamSource, - SetAudioOutput = 0x0008, - SetVideoOutput = 0x0010, - SetOutputs = SetAudioOutput | SetVideoOutput, - Render = 0x0020, - FinalizeLoad = 0x0040, - SetRate = 0x0080, - Seek = 0x0100, - Play = 0x0200, - Pause = 0x0400, - Stop = 0x0800, - ReleaseGraph = 0x1000, - ReleaseAudioOutput = 0x2000, - ReleaseVideoOutput = 0x4000, - ReleaseFilters = ReleaseGraph | ReleaseAudioOutput | ReleaseVideoOutput - }; - - enum Event - { - FinalizedLoad = QEvent::User, - Error, - RateChange, - Started, - Paused, - DurationChange, - StatusChange, - EndOfMedia, - PositionChange - }; - - enum GraphStatus - { - NoMedia, - Loading, - Loaded, - InvalidMedia - }; - - DirectShowPlayerControl *m_playerControl; - DirectShowMetaDataControl *m_metaDataControl; - DirectShowVideoRendererControl *m_videoRendererControl; -#ifndef Q_WS_SIMULATOR - Vmr9VideoWindowControl *m_videoWindowControl; -#endif - DirectShowAudioEndpointControl *m_audioEndpointControl; - - QThread *m_taskThread; - DirectShowEventLoop *m_loop; - int m_pendingTasks; - int m_executingTask; - int m_executedTasks; - HANDLE m_taskHandle; - HANDLE m_eventHandle; - GraphStatus m_graphStatus; - QMediaPlayer::Error m_error; - QIODevice *m_stream; - IFilterGraph2 *m_graph; - IBaseFilter *m_source; - IBaseFilter *m_audioOutput; - IBaseFilter *m_videoOutput; - int m_streamTypes; - qreal m_rate; - qint64 m_position; - qint64 m_duration; - bool m_buffering; - bool m_seekable; - bool m_atEnd; - QMediaTimeRange m_playbackRange; - QUrl m_url; - QMediaResourceList m_resources; - QString m_errorString; - QMutex m_mutex; - - friend class DirectShowPlayerServiceThread; -}; - - -#endif diff --git a/src/plugins/directshow/player/directshowsamplescheduler.cpp b/src/plugins/directshow/player/directshowsamplescheduler.cpp deleted file mode 100644 index 6874132..0000000 --- a/src/plugins/directshow/player/directshowsamplescheduler.cpp +++ /dev/null @@ -1,437 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "directshowsamplescheduler.h" - -#include <QtCore/qcoreapplication.h> -#include <QtCore/qcoreevent.h> - -class DirectShowTimedSample -{ -public: - DirectShowTimedSample(IMediaSample *sample) - : m_next(0) - , m_sample(sample) - , m_cookie(0) - , m_lastSample(false) - { - m_sample->AddRef(); - } - - ~DirectShowTimedSample() - { - m_sample->Release(); - } - - IMediaSample *sample() const { return m_sample; } - - DirectShowTimedSample *nextSample() const { return m_next; } - void setNextSample(DirectShowTimedSample *sample) { Q_ASSERT(!m_next); m_next = sample; } - - DirectShowTimedSample *remove() { - DirectShowTimedSample *next = m_next; delete this; return next; } - - bool schedule(IReferenceClock *clock, REFERENCE_TIME startTime, HANDLE handle); - void unschedule(IReferenceClock *clock); - - bool isReady(IReferenceClock *clock) const; - - bool isLast() const { return m_lastSample; } - void setLast() { m_lastSample = true; } - -private: - DirectShowTimedSample *m_next; - IMediaSample *m_sample; - DWORD_PTR m_cookie; - bool m_lastSample; -}; - -bool DirectShowTimedSample::schedule( - IReferenceClock *clock, REFERENCE_TIME startTime, HANDLE handle) -{ - REFERENCE_TIME sampleStartTime; - REFERENCE_TIME sampleEndTime; - if (m_sample->GetTime(&sampleStartTime, &sampleEndTime) == S_OK) { - if (clock->AdviseTime( - startTime, sampleStartTime, reinterpret_cast<HEVENT>(handle), &m_cookie) == S_OK) { - return true; - } - } - return false; -} - -void DirectShowTimedSample::unschedule(IReferenceClock *clock) -{ - clock->Unadvise(m_cookie); -} - -bool DirectShowTimedSample::isReady(IReferenceClock *clock) const -{ - REFERENCE_TIME sampleStartTime; - REFERENCE_TIME sampleEndTime; - REFERENCE_TIME currentTime; - if (m_sample->GetTime(&sampleStartTime, &sampleEndTime) == S_OK) { - if (clock->GetTime(¤tTime) == S_OK) - return currentTime >= sampleStartTime; - } - return true; -} - -DirectShowSampleScheduler::DirectShowSampleScheduler(IUnknown *pin, QObject *parent) - : QObject(parent) - , m_pin(pin) - , m_clock(0) - , m_allocator(0) - , m_head(0) - , m_tail(0) - , m_maximumSamples(1) - , m_state(Stopped) - , m_startTime(0) - , m_timeoutEvent(::CreateEvent(0, 0, 0, 0)) - , m_flushEvent(::CreateEvent(0, 0, 0, 0)) -{ - m_semaphore.release(m_maximumSamples); -} - -DirectShowSampleScheduler::~DirectShowSampleScheduler() -{ - ::CloseHandle(m_timeoutEvent); - ::CloseHandle(m_flushEvent); - - Q_ASSERT(!m_clock); - Q_ASSERT(!m_allocator); -} - -HRESULT DirectShowSampleScheduler::QueryInterface(REFIID riid, void **ppvObject) -{ - return m_pin->QueryInterface(riid, ppvObject); -} - -ULONG DirectShowSampleScheduler::AddRef() -{ - return m_pin->AddRef(); -} - -ULONG DirectShowSampleScheduler::Release() -{ - return m_pin->Release(); -} - -// IMemInputPin -HRESULT DirectShowSampleScheduler::GetAllocator(IMemAllocator **ppAllocator) -{ - if (!ppAllocator) { - return E_POINTER; - } else { - QMutexLocker locker(&m_mutex); - - if (!m_allocator) { - return VFW_E_NO_ALLOCATOR; - } else { - *ppAllocator = m_allocator; - - return S_OK; - } - } -} - -HRESULT DirectShowSampleScheduler::NotifyAllocator(IMemAllocator *pAllocator, BOOL bReadOnly) -{ - Q_UNUSED(bReadOnly); - - HRESULT hr; - ALLOCATOR_PROPERTIES properties; - - if (!pAllocator) { - if (m_allocator) - m_allocator->Release(); - - m_allocator = 0; - - return S_OK; - } else if ((hr = pAllocator->GetProperties(&properties)) != S_OK) { - return hr; - } else { - if (properties.cBuffers == 1) { - ALLOCATOR_PROPERTIES actual; - - properties.cBuffers = 2; - if ((hr = pAllocator->SetProperties(&properties, &actual)) != S_OK) - return hr; - } - - QMutexLocker locker(&m_mutex); - - if (m_allocator) - m_allocator->Release(); - - m_allocator = pAllocator; - m_allocator->AddRef(); - - return S_OK; - } -} - -HRESULT DirectShowSampleScheduler::GetAllocatorRequirements(ALLOCATOR_PROPERTIES *pProps) -{ - if (!pProps) - return E_POINTER; - - pProps->cBuffers = 2; - - return S_OK; -} - -HRESULT DirectShowSampleScheduler::Receive(IMediaSample *pSample) -{ - if (!pSample) - return E_POINTER; - - m_semaphore.acquire(1); - - QMutexLocker locker(&m_mutex); - - if (m_state & Flushing) { - m_semaphore.release(1); - - return S_FALSE; - } else if (m_state == Stopped) { - m_semaphore.release(); - - return VFW_E_WRONG_STATE; - } else { - DirectShowTimedSample *timedSample = new DirectShowTimedSample(pSample); - - if (m_tail) - m_tail->setNextSample(timedSample); - else - m_head = timedSample; - - m_tail = timedSample; - - if (m_state == Running) { - if (!timedSample->schedule(m_clock, m_startTime, m_timeoutEvent)) { - // Timing information is unavailable, so schedule frames immediately. - QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest)); - } else { - locker.unlock(); - HANDLE handles[] = { m_flushEvent, m_timeoutEvent }; - DWORD result = ::WaitForMultipleObjects(2, handles, FALSE, INFINITE); - locker.relock(); - - if (result == WAIT_OBJECT_0 + 1) - QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest)); - } - } else if (m_tail == m_head) { - // If this is the first frame make it available. - QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest)); - - if (m_state == Paused) { - ::ResetEvent(m_timeoutEvent); - - locker.unlock(); - HANDLE handles[] = { m_flushEvent, m_timeoutEvent }; - ::WaitForMultipleObjects(2, handles, FALSE, INFINITE); - locker.relock(); - } - } - - return S_OK; - } -} - -HRESULT DirectShowSampleScheduler::ReceiveMultiple( - IMediaSample **pSamples, long nSamples, long *nSamplesProcessed) -{ - if (!pSamples || !nSamplesProcessed) - return E_POINTER; - - for (*nSamplesProcessed = 0; *nSamplesProcessed < nSamples; ++(*nSamplesProcessed)) { - HRESULT hr = Receive(pSamples[*nSamplesProcessed]); - - if (hr != S_OK) - return hr; - } - return S_OK; -} - -HRESULT DirectShowSampleScheduler::ReceiveCanBlock() -{ - return S_OK; -} - -void DirectShowSampleScheduler::run(REFERENCE_TIME startTime) -{ - QMutexLocker locker(&m_mutex); - - m_state = (m_state & Flushing) | Running; - m_startTime = startTime; - - for (DirectShowTimedSample *sample = m_head; sample; sample = sample->nextSample()) { - sample->schedule(m_clock, m_startTime, m_timeoutEvent); - } - - if (!(m_state & Flushing)) - ::ResetEvent(m_flushEvent); - - if (!m_head) - ::SetEvent(m_timeoutEvent); - -} - -void DirectShowSampleScheduler::pause() -{ - QMutexLocker locker(&m_mutex); - - m_state = (m_state & Flushing) | Paused; - - for (DirectShowTimedSample *sample = m_head; sample; sample = sample->nextSample()) - sample->unschedule(m_clock); - - if (!(m_state & Flushing)) - ::ResetEvent(m_flushEvent); -} - -void DirectShowSampleScheduler::stop() -{ - QMutexLocker locker(&m_mutex); - - m_state = m_state & Flushing; - - for (DirectShowTimedSample *sample = m_head; sample; sample = sample->remove()) { - sample->unschedule(m_clock); - - m_semaphore.release(1); - } - - m_head = 0; - m_tail = 0; - - ::SetEvent(m_flushEvent); -} - -void DirectShowSampleScheduler::setFlushing(bool flushing) -{ - QMutexLocker locker(&m_mutex); - - const bool isFlushing = m_state & Flushing; - - if (isFlushing != flushing) { - if (flushing) { - m_state |= Flushing; - - for (DirectShowTimedSample *sample = m_head; sample; sample = sample->remove()) { - sample->unschedule(m_clock); - - m_semaphore.release(1); - } - m_head = 0; - m_tail = 0; - - ::SetEvent(m_flushEvent); - } else { - m_state &= ~Flushing; - - if (m_state != Stopped) - ::ResetEvent(m_flushEvent); - } - } -} - -void DirectShowSampleScheduler::setClock(IReferenceClock *clock) -{ - QMutexLocker locker(&m_mutex); - - if (m_clock) - m_clock->Release(); - - m_clock = clock; - - if (m_clock) - m_clock->AddRef(); -} - -IMediaSample *DirectShowSampleScheduler::takeSample(bool *eos) -{ - QMutexLocker locker(&m_mutex); - - if (m_head && m_head->isReady(m_clock)) { - IMediaSample *sample = m_head->sample(); - sample->AddRef(); - - *eos = m_head->isLast(); - - m_head = m_head->remove(); - - if (!m_head) - m_tail = 0; - - m_semaphore.release(1); - - return sample; - } else { - return 0; - } -} - -bool DirectShowSampleScheduler::scheduleEndOfStream() -{ - QMutexLocker locker(&m_mutex); - - if (m_tail) { - m_tail->setLast(); - - return true; - } else { - return false; - } -} - -bool DirectShowSampleScheduler::event(QEvent *event) -{ - if (event->type() == QEvent::UpdateRequest) { - emit sampleReady(); - - return true; - } else { - return QObject::event(event); - } -} diff --git a/src/plugins/directshow/player/directshowsamplescheduler.h b/src/plugins/directshow/player/directshowsamplescheduler.h deleted file mode 100644 index c861776..0000000 --- a/src/plugins/directshow/player/directshowsamplescheduler.h +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DIRECTSHOWSAMPLESCHEDULER_H -#define DIRECTSHOWSAMPLESCHEDULER_H - -#include <QtCore/qmutex.h> -#include <QtCore/qobject.h> -#include <QtCore/qsemaphore.h> - -#include <dshow.h> - -class DirectShowTimedSample; - -class DirectShowSampleScheduler : public QObject, public IMemInputPin -{ - Q_OBJECT -public: - - enum State - { - Stopped = 0x00, - Running = 0x01, - Paused = 0x02, - RunMask = 0x03, - Flushing = 0x04 - }; - - DirectShowSampleScheduler(IUnknown *pin, QObject *parent = 0); - ~DirectShowSampleScheduler(); - - // IUnknown - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); - ULONG STDMETHODCALLTYPE AddRef(); - ULONG STDMETHODCALLTYPE Release(); - - // IMemInputPin - HRESULT STDMETHODCALLTYPE GetAllocator(IMemAllocator **ppAllocator); - HRESULT STDMETHODCALLTYPE NotifyAllocator(IMemAllocator *pAllocator, BOOL bReadOnly); - HRESULT STDMETHODCALLTYPE GetAllocatorRequirements(ALLOCATOR_PROPERTIES *pProps); - - HRESULT STDMETHODCALLTYPE Receive(IMediaSample *pSample); - HRESULT STDMETHODCALLTYPE ReceiveMultiple(IMediaSample **pSamples, long nSamples, long *nSamplesProcessed); - HRESULT STDMETHODCALLTYPE ReceiveCanBlock(); - - void run(REFERENCE_TIME startTime); - void pause(); - void stop(); - void setFlushing(bool flushing); - - IReferenceClock *clock() const { return m_clock; } - void setClock(IReferenceClock *clock); - - bool schedule(IMediaSample *sample); - bool scheduleEndOfStream(); - - IMediaSample *takeSample(bool *eos); - - bool event(QEvent *event); - -Q_SIGNALS: - void sampleReady(); - -private: - IUnknown *m_pin; - IReferenceClock *m_clock; - IMemAllocator *m_allocator; - DirectShowTimedSample *m_head; - DirectShowTimedSample *m_tail; - int m_maximumSamples; - int m_state; - REFERENCE_TIME m_startTime; - HANDLE m_timeoutEvent; - HANDLE m_flushEvent; - QSemaphore m_semaphore; - QMutex m_mutex; -}; - -#endif diff --git a/src/plugins/directshow/player/directshowvideorenderercontrol.cpp b/src/plugins/directshow/player/directshowvideorenderercontrol.cpp deleted file mode 100644 index 38ec30d..0000000 --- a/src/plugins/directshow/player/directshowvideorenderercontrol.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "directshowvideorenderercontrol.h" - -#include "videosurfacefilter.h" - -DirectShowVideoRendererControl::DirectShowVideoRendererControl(DirectShowEventLoop *loop, QObject *parent) - : QVideoRendererControl(parent) - , m_loop(loop) - , m_surface(0) - , m_filter(0) -{ -} - -DirectShowVideoRendererControl::~DirectShowVideoRendererControl() -{ - delete m_filter; -} - -QAbstractVideoSurface *DirectShowVideoRendererControl::surface() const -{ - return m_surface; -} - -void DirectShowVideoRendererControl::setSurface(QAbstractVideoSurface *surface) -{ - if (surface != m_surface) { - m_surface = surface; - - VideoSurfaceFilter *existingFilter = m_filter; - - if (surface) { - m_filter = new VideoSurfaceFilter(surface, m_loop); - } else { - m_filter = 0; - } - - emit filterChanged(); - - delete existingFilter; - } -} - -IBaseFilter *DirectShowVideoRendererControl::filter() -{ - return m_filter; -} diff --git a/src/plugins/directshow/player/directshowvideorenderercontrol.h b/src/plugins/directshow/player/directshowvideorenderercontrol.h deleted file mode 100644 index 8a597d4..0000000 --- a/src/plugins/directshow/player/directshowvideorenderercontrol.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DIRECTSHOWVIDEORENDERERCONTROL_H -#define DIRECTSHOWVIDEORENDERERCONTROL_H - -#include "qvideorenderercontrol.h" - -#include <dshow.h> - -class DirectShowEventLoop; -class VideoSurfaceFilter; - -QT_USE_NAMESPACE - -class DirectShowVideoRendererControl : public QVideoRendererControl -{ - Q_OBJECT -public: - DirectShowVideoRendererControl(DirectShowEventLoop *loop, QObject *parent = 0); - ~DirectShowVideoRendererControl(); - - QAbstractVideoSurface *surface() const; - void setSurface(QAbstractVideoSurface *surface); - - IBaseFilter *filter(); - -Q_SIGNALS: - void filterChanged(); - -private: - DirectShowEventLoop *m_loop; - QAbstractVideoSurface *m_surface; - VideoSurfaceFilter *m_filter; -}; - -#endif diff --git a/src/plugins/directshow/player/mediasamplevideobuffer.cpp b/src/plugins/directshow/player/mediasamplevideobuffer.cpp deleted file mode 100644 index 36bc127..0000000 --- a/src/plugins/directshow/player/mediasamplevideobuffer.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "mediasamplevideobuffer.h" - -MediaSampleVideoBuffer::MediaSampleVideoBuffer(IMediaSample *sample, int bytesPerLine) - : QAbstractVideoBuffer(NoHandle) - , m_sample(sample) - , m_bytesPerLine(bytesPerLine) - , m_mapMode(NotMapped) -{ - m_sample->AddRef(); -} - -MediaSampleVideoBuffer::~MediaSampleVideoBuffer() -{ - m_sample->Release(); -} - -uchar *MediaSampleVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine) -{ - if (m_mapMode == NotMapped && mode != NotMapped) { - if (numBytes) - *numBytes = m_sample->GetActualDataLength(); - - if (bytesPerLine) - *bytesPerLine = m_bytesPerLine; - - BYTE *bytes = 0; - - if (m_sample->GetPointer(&bytes) == S_OK) { - m_mapMode = mode; - - return reinterpret_cast<uchar *>(bytes); - } - } - return 0; -} - -void MediaSampleVideoBuffer::unmap() -{ - m_mapMode = NotMapped; -} - -QAbstractVideoBuffer::MapMode MediaSampleVideoBuffer::mapMode() const -{ - return m_mapMode; -} diff --git a/src/plugins/directshow/player/mediasamplevideobuffer.h b/src/plugins/directshow/player/mediasamplevideobuffer.h deleted file mode 100644 index a041019..0000000 --- a/src/plugins/directshow/player/mediasamplevideobuffer.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MEDIASAMPLEVIDEOBUFFER_H -#define MEDIASAMPLEVIDEOBUFFER_H - -#include <qabstractvideobuffer.h> - -#include <dshow.h> - -class MediaSampleVideoBuffer : public QAbstractVideoBuffer -{ -public: - MediaSampleVideoBuffer(IMediaSample *sample, int bytesPerLine); - ~MediaSampleVideoBuffer(); - - IMediaSample *sample() { return m_sample; } - - uchar *map(MapMode mode, int *numBytes, int *bytesPerLine); - void unmap(); - - MapMode mapMode() const; - -private: - IMediaSample *m_sample; - int m_bytesPerLine; - MapMode m_mapMode; -}; - - -#endif diff --git a/src/plugins/directshow/player/player.pri b/src/plugins/directshow/player/player.pri deleted file mode 100644 index a058b06..0000000 --- a/src/plugins/directshow/player/player.pri +++ /dev/null @@ -1,47 +0,0 @@ -INCLUDEPATH += $$PWD - -DEFINES += QMEDIA_DIRECTSHOW_PLAYER - -HEADERS += \ - $$PWD/directshowaudioendpointcontrol.h \ - $$PWD/directshoweventloop.h \ - $$PWD/directshowglobal.h \ - $$PWD/directshowioreader.h \ - $$PWD/directshowiosource.h \ - $$PWD/directshowmediatype.h \ - $$PWD/directshowmediatypelist.h \ - $$PWD/directshowmetadatacontrol.h \ - $$PWD/directshowpinenum.h \ - $$PWD/directshowplayercontrol.h \ - $$PWD/directshowplayerservice.h \ - $$PWD/directshowsamplescheduler.h \ - $$PWD/directshowvideorenderercontrol.h \ - $$PWD/mediasamplevideobuffer.h \ - $$PWD/videosurfacefilter.h - -SOURCES += \ - $$PWD/directshowaudioendpointcontrol.cpp \ - $$PWD/directshoweventloop.cpp \ - $$PWD/directshowioreader.cpp \ - $$PWD/directshowiosource.cpp \ - $$PWD/directshowmediatype.cpp \ - $$PWD/directshowmediatypelist.cpp \ - $$PWD/directshowmetadatacontrol.cpp \ - $$PWD/directshowpinenum.cpp \ - $$PWD/directshowplayercontrol.cpp \ - $$PWD/directshowplayerservice.cpp \ - $$PWD/directshowsamplescheduler.cpp \ - $$PWD/directshowvideorenderercontrol.cpp \ - $$PWD/mediasamplevideobuffer.cpp \ - $$PWD/videosurfacefilter.cpp - -!simulator { -HEADERS += \ - $$PWD/vmr9videowindowcontrol.h - -SOURCES += \ - $$PWD/vmr9videowindowcontrol.cpp -} - -LIBS += -lstrmiids -ldmoguids -luuid -lmsdmo -lole32 -loleaut32 -lgdi32 - diff --git a/src/plugins/directshow/player/videosurfacefilter.cpp b/src/plugins/directshow/player/videosurfacefilter.cpp deleted file mode 100644 index 6f34bc4..0000000 --- a/src/plugins/directshow/player/videosurfacefilter.cpp +++ /dev/null @@ -1,631 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "videosurfacefilter.h" - -#include "directshoweventloop.h" -#include "directshowglobal.h" -#include "directshowpinenum.h" -#include "mediasamplevideobuffer.h" - -#include <QtCore/qcoreapplication.h> -#include <QtCore/qcoreevent.h> -#include <QtCore/qthread.h> -#include <qabstractvideosurface.h> - -#include <initguid.h> - -// { e23cad72-153d-406c-bf3f-4c4b523d96f2 } -DEFINE_GUID(CLSID_VideoSurfaceFilter, -0xe23cad72, 0x153d, 0x406c, 0xbf, 0x3f, 0x4c, 0x4b, 0x52, 0x3d, 0x96, 0xf2); - -VideoSurfaceFilter::VideoSurfaceFilter( - QAbstractVideoSurface *surface, DirectShowEventLoop *loop, QObject *parent) - : QObject(parent) - , m_ref(1) - , m_state(State_Stopped) - , m_surface(surface) - , m_loop(loop) - , m_graph(0) - , m_peerPin(0) - , m_bytesPerLine(0) - , m_startResult(S_OK) - , m_pinId(QString::fromLatin1("reference")) - , m_sampleScheduler(static_cast<IPin *>(this)) -{ - connect(surface, SIGNAL(supportedFormatsChanged()), this, SLOT(supportedFormatsChanged())); - connect(&m_sampleScheduler, SIGNAL(sampleReady()), this, SLOT(sampleReady())); -} - -VideoSurfaceFilter::~VideoSurfaceFilter() -{ - Q_ASSERT(m_ref == 1); -} - -HRESULT VideoSurfaceFilter::QueryInterface(REFIID riid, void **ppvObject) -{ - // 2dd74950-a890-11d1-abe8-00a0c905f375 - static const GUID iid_IAmFilterMiscFlags = { - 0x2dd74950, 0xa890, 0x11d1, {0xab, 0xe8, 0x00, 0xa0, 0xc9, 0x05, 0xf3, 0x75} }; - - if (!ppvObject) { - return E_POINTER; - } else if (riid == IID_IUnknown - || riid == IID_IPersist - || riid == IID_IMediaFilter - || riid == IID_IBaseFilter) { - *ppvObject = static_cast<IBaseFilter *>(this); - } else if (riid == iid_IAmFilterMiscFlags) { - *ppvObject = static_cast<IAMFilterMiscFlags *>(this); - } else if (riid == IID_IPin) { - *ppvObject = static_cast<IPin *>(this); - } else if (riid == IID_IMemInputPin) { - *ppvObject = static_cast<IMemInputPin *>(&m_sampleScheduler); - } else { - *ppvObject = 0; - - return E_NOINTERFACE; - } - - AddRef(); - - return S_OK; -} - -ULONG VideoSurfaceFilter::AddRef() -{ - return InterlockedIncrement(&m_ref); -} - -ULONG VideoSurfaceFilter::Release() -{ - ULONG ref = InterlockedDecrement(&m_ref); - - Q_ASSERT(ref != 0); - - return ref; -} - -HRESULT VideoSurfaceFilter::GetClassID(CLSID *pClassID) -{ - *pClassID = CLSID_VideoSurfaceFilter; - - return S_OK; -} - -HRESULT VideoSurfaceFilter::Run(REFERENCE_TIME tStart) -{ - m_state = State_Running; - - m_sampleScheduler.run(tStart); - - return S_OK; -} - -HRESULT VideoSurfaceFilter::Pause() -{ - m_state = State_Paused; - - m_sampleScheduler.pause(); - - return S_OK; -} - -HRESULT VideoSurfaceFilter::Stop() -{ - m_state = State_Stopped; - - m_sampleScheduler.stop(); - - return S_OK; -} - -HRESULT VideoSurfaceFilter::GetState(DWORD dwMilliSecsTimeout, FILTER_STATE *pState) -{ - if (!pState) - return E_POINTER; - - *pState = m_state; - - return S_OK; -} - -HRESULT VideoSurfaceFilter::SetSyncSource(IReferenceClock *pClock) -{ - - m_sampleScheduler.setClock(pClock); - - return S_OK; -} - -HRESULT VideoSurfaceFilter::GetSyncSource(IReferenceClock **ppClock) -{ - if (!ppClock) { - return E_POINTER; - } else { - *ppClock = m_sampleScheduler.clock(); - - if (*ppClock) { - (*ppClock)->AddRef(); - - return S_OK; - } else { - return S_FALSE; - } - } -} - -HRESULT VideoSurfaceFilter::EnumPins(IEnumPins **ppEnum) -{ - if (ppEnum) { - *ppEnum = new DirectShowPinEnum(QList<IPin *>() << this); - - return S_OK; - } else { - return E_POINTER; - } -} - -HRESULT VideoSurfaceFilter::FindPin(LPCWSTR pId, IPin **ppPin) -{ - if (!ppPin || !pId) { - return E_POINTER; - } else if (QString::fromWCharArray(pId) == m_pinId) { - AddRef(); - - *ppPin = this; - - return S_OK; - } else { - return VFW_E_NOT_FOUND; - } -} - -HRESULT VideoSurfaceFilter::JoinFilterGraph(IFilterGraph *pGraph, LPCWSTR pName) -{ - m_graph = pGraph; - m_name = QString::fromWCharArray(pName); - - return S_OK; -} - -HRESULT VideoSurfaceFilter::QueryFilterInfo(FILTER_INFO *pInfo) -{ - if (pInfo) { - QString name = m_name; - - if (name.length() >= MAX_FILTER_NAME) - name.truncate(MAX_FILTER_NAME - 1); - - int length = name.toWCharArray(pInfo->achName); - pInfo->achName[length] = '\0'; - - if (m_graph) - m_graph->AddRef(); - - pInfo->pGraph = m_graph; - - return S_OK; - } else { - return E_POINTER; - } -} - -HRESULT VideoSurfaceFilter::QueryVendorInfo(LPWSTR *pVendorInfo) -{ - Q_UNUSED(pVendorInfo); - - return E_NOTIMPL; -} - -ULONG VideoSurfaceFilter::GetMiscFlags() -{ - return AM_FILTER_MISC_FLAGS_IS_RENDERER; -} - - -HRESULT VideoSurfaceFilter::Connect(IPin *pReceivePin, const AM_MEDIA_TYPE *pmt) -{ - // This is an input pin, you shouldn't be calling Connect on it. - return E_POINTER; -} - -HRESULT VideoSurfaceFilter::ReceiveConnection(IPin *pConnector, const AM_MEDIA_TYPE *pmt) -{ - if (!pConnector) { - return E_POINTER; - } else if (!pmt) { - return E_POINTER; - } else { - HRESULT hr; - QMutexLocker locker(&m_mutex); - - if (m_peerPin) { - hr = VFW_E_ALREADY_CONNECTED; - } else if (pmt->majortype != MEDIATYPE_Video) { - hr = VFW_E_TYPE_NOT_ACCEPTED; - } else { - m_surfaceFormat = DirectShowMediaType::formatFromType(*pmt); - m_bytesPerLine = DirectShowMediaType::bytesPerLine(m_surfaceFormat); - - if (thread() == QThread::currentThread()) { - hr = start(); - } else { - m_loop->postEvent(this, new QEvent(QEvent::Type(StartSurface))); - - m_wait.wait(&m_mutex); - - hr = m_startResult; - } - } - if (hr == S_OK) { - m_peerPin = pConnector; - m_peerPin->AddRef(); - - DirectShowMediaType::copy(&m_mediaType, *pmt); - } - return hr; - } -} - -HRESULT VideoSurfaceFilter::start() -{ - if (!m_surface->isFormatSupported(m_surfaceFormat)) { - return VFW_E_TYPE_NOT_ACCEPTED; - } - if (!m_surface->start(m_surfaceFormat)) { - return VFW_E_TYPE_NOT_ACCEPTED; - } else { - return S_OK; - } -} - -HRESULT VideoSurfaceFilter::Disconnect() -{ - QMutexLocker locker(&m_mutex); - - if (!m_peerPin) - return S_FALSE; - - if (thread() == QThread::currentThread()) { - stop(); - } else { - m_loop->postEvent(this, new QEvent(QEvent::Type(StopSurface))); - - m_wait.wait(&m_mutex); - } - - m_mediaType.clear(); - - m_sampleScheduler.NotifyAllocator(0, FALSE); - - m_peerPin->Release(); - m_peerPin = 0; - - return S_OK; -} - -void VideoSurfaceFilter::stop() -{ - m_surface->stop(); -} - -HRESULT VideoSurfaceFilter::ConnectedTo(IPin **ppPin) -{ - if (!ppPin) { - return E_POINTER; - } else { - QMutexLocker locker(&m_mutex); - - if (!m_peerPin) { - return VFW_E_NOT_CONNECTED; - } else { - m_peerPin->AddRef(); - - *ppPin = m_peerPin; - - return S_OK; - } - } -} - -HRESULT VideoSurfaceFilter::ConnectionMediaType(AM_MEDIA_TYPE *pmt) -{ - if (!pmt) { - return E_POINTER; - } else { - QMutexLocker locker(&m_mutex); - - if (!m_peerPin) { - return VFW_E_NOT_CONNECTED; - } else { - DirectShowMediaType::copy(pmt, m_mediaType); - - return S_OK; - } - } -} - -HRESULT VideoSurfaceFilter::QueryPinInfo(PIN_INFO *pInfo) -{ - if (!pInfo) { - return E_POINTER; - } else { - AddRef(); - - pInfo->pFilter = this; - pInfo->dir = PINDIR_INPUT; - - const int bytes = qMin(MAX_FILTER_NAME, (m_pinId.length() + 1) * 2); - - qMemCopy(pInfo->achName, m_pinId.utf16(), bytes); - - return S_OK; - } -} - -HRESULT VideoSurfaceFilter::QueryId(LPWSTR *Id) -{ - if (!Id) { - return E_POINTER; - } else { - const int bytes = (m_pinId.length() + 1) * 2; - - *Id = static_cast<LPWSTR>(::CoTaskMemAlloc(bytes)); - - qMemCopy(*Id, m_pinId.utf16(), bytes); - - return S_OK; - } -} - -HRESULT VideoSurfaceFilter::QueryAccept(const AM_MEDIA_TYPE *pmt) -{ - return !m_surface->isFormatSupported(DirectShowMediaType::formatFromType(*pmt)) - ? S_OK - : S_FALSE; -} - -HRESULT VideoSurfaceFilter::EnumMediaTypes(IEnumMediaTypes **ppEnum) -{ - if (!ppEnum) { - return E_POINTER; - } else { - QMutexLocker locker(&m_mutex); - - *ppEnum = createMediaTypeEnum(); - - return S_OK; - } -} - -HRESULT VideoSurfaceFilter::QueryInternalConnections(IPin **apPin, ULONG *nPin) -{ - Q_UNUSED(apPin); - Q_UNUSED(nPin); - - return E_NOTIMPL; -} - -HRESULT VideoSurfaceFilter::EndOfStream() -{ - QMutexLocker locker(&m_mutex); - - if (!m_sampleScheduler.scheduleEndOfStream()) { - if (IMediaEventSink *sink = com_cast<IMediaEventSink>(m_graph, IID_IMediaEventSink)) { - sink->Notify( - EC_COMPLETE, - S_OK, - reinterpret_cast<LONG_PTR>(static_cast<IBaseFilter *>(this))); - sink->Release(); - } - } - - return S_OK; -} - -HRESULT VideoSurfaceFilter::BeginFlush() -{ - QMutexLocker locker(&m_mutex); - - m_sampleScheduler.setFlushing(true); - - if (thread() == QThread::currentThread()) { - flush(); - } else { - m_loop->postEvent(this, new QEvent(QEvent::Type(FlushSurface))); - - m_wait.wait(&m_mutex); - } - - return S_OK; -} - -HRESULT VideoSurfaceFilter::EndFlush() -{ - QMutexLocker locker(&m_mutex); - - m_sampleScheduler.setFlushing(false); - - return S_OK; -} - -void VideoSurfaceFilter::flush() -{ - m_surface->present(QVideoFrame()); - - m_wait.wakeAll(); -} - -HRESULT VideoSurfaceFilter::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) -{ - Q_UNUSED(tStart); - Q_UNUSED(tStop); - Q_UNUSED(dRate); - - return S_OK; -} - -HRESULT VideoSurfaceFilter::QueryDirection(PIN_DIRECTION *pPinDir) -{ - if (!pPinDir) { - return E_POINTER; - } else { - *pPinDir = PINDIR_INPUT; - - return S_OK; - } -} - -int VideoSurfaceFilter::currentMediaTypeToken() -{ - QMutexLocker locker(&m_mutex); - - return DirectShowMediaTypeList::currentMediaTypeToken(); -} - -HRESULT VideoSurfaceFilter::nextMediaType( - int token, int *index, ULONG count, AM_MEDIA_TYPE **types, ULONG *fetchedCount) -{ - QMutexLocker locker(&m_mutex); - - return DirectShowMediaTypeList::nextMediaType(token, index, count, types, fetchedCount); - -} - -HRESULT VideoSurfaceFilter::skipMediaType(int token, int *index, ULONG count) -{ - QMutexLocker locker(&m_mutex); - - return DirectShowMediaTypeList::skipMediaType(token, index, count); -} - -HRESULT VideoSurfaceFilter::cloneMediaType(int token, int index, IEnumMediaTypes **enumeration) -{ - QMutexLocker locker(&m_mutex); - - return DirectShowMediaTypeList::cloneMediaType(token, index, enumeration); -} - -void VideoSurfaceFilter::customEvent(QEvent *event) -{ - if (event->type() == StartSurface) { - QMutexLocker locker(&m_mutex); - - m_startResult = start(); - - m_wait.wakeAll(); - } else if (event->type() == StopSurface) { - QMutexLocker locker(&m_mutex); - - stop(); - - m_wait.wakeAll(); - } else if (event->type() == FlushSurface) { - QMutexLocker locker(&m_mutex); - - flush(); - - m_wait.wakeAll(); - } else { - QObject::customEvent(event); - } -} - -void VideoSurfaceFilter::supportedFormatsChanged() -{ - QMutexLocker locker(&m_mutex); - - // MEDIASUBTYPE_None; - static const GUID none = { - 0xe436eb8e, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70} }; - - QList<QVideoFrame::PixelFormat> formats = m_surface->supportedPixelFormats(); - - QVector<AM_MEDIA_TYPE> mediaTypes; - mediaTypes.reserve(formats.count()); - - AM_MEDIA_TYPE type; - type.majortype = MEDIATYPE_Video; - type.bFixedSizeSamples = TRUE; - type.bTemporalCompression = FALSE; - type.lSampleSize = 0; - type.formattype = GUID_NULL; - type.pUnk = 0; - type.cbFormat = 0; - type.pbFormat = 0; - - foreach (QVideoFrame::PixelFormat format, formats) { - type.subtype = DirectShowMediaType::convertPixelFormat(format); - - if (type.subtype != none) - mediaTypes.append(type); - } - - setMediaTypes(mediaTypes); -} - -void VideoSurfaceFilter::sampleReady() -{ - bool eos = false; - - IMediaSample *sample = m_sampleScheduler.takeSample(&eos); - - if (sample) { - m_surface->present(QVideoFrame( - new MediaSampleVideoBuffer(sample, m_bytesPerLine), - m_surfaceFormat.frameSize(), - m_surfaceFormat.pixelFormat())); - - sample->Release(); - - if (eos) { - if (IMediaEventSink *sink = com_cast<IMediaEventSink>(m_graph, IID_IMediaEventSink)) { - sink->Notify( - EC_COMPLETE, - S_OK, - reinterpret_cast<LONG_PTR>(static_cast<IBaseFilter *>(this))); - sink->Release(); - } - } - } -} - diff --git a/src/plugins/directshow/player/videosurfacefilter.h b/src/plugins/directshow/player/videosurfacefilter.h deleted file mode 100644 index eac15c8..0000000 --- a/src/plugins/directshow/player/videosurfacefilter.h +++ /dev/null @@ -1,176 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef VIDEOSURFACEFILTER_H -#define VIDEOSURFACEFILTER_H - -#include "directshowglobal.h" -#include "directshowmediatypelist.h" -#include "directshowsamplescheduler.h" -#include "directshowmediatype.h" - -#include <QtCore/qbasictimer.h> -#include <QtCore/qcoreevent.h> -#include <QtCore/qmutex.h> -#include <QtCore/qsemaphore.h> -#include <QtCore/qstring.h> -#include <QtCore/qwaitcondition.h> - -#include <dshow.h> - -QT_BEGIN_NAMESPACE -class QAbstractVideoSurface; -QT_END_NAMESPACE - -class DirectShowEventLoop; - -class VideoSurfaceFilter - : public QObject - , public DirectShowMediaTypeList - , public IBaseFilter - , public IAMFilterMiscFlags - , public IPin -{ - Q_OBJECT -public: - VideoSurfaceFilter( - QAbstractVideoSurface *surface, DirectShowEventLoop *loop, QObject *parent = 0); - ~VideoSurfaceFilter(); - - // IUnknown - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); - ULONG STDMETHODCALLTYPE AddRef(); - ULONG STDMETHODCALLTYPE Release(); - - // IPersist - HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pClassID); - - // IMediaFilter - HRESULT STDMETHODCALLTYPE Run(REFERENCE_TIME tStart); - HRESULT STDMETHODCALLTYPE Pause(); - HRESULT STDMETHODCALLTYPE Stop(); - - HRESULT STDMETHODCALLTYPE GetState(DWORD dwMilliSecsTimeout, FILTER_STATE *pState); - - HRESULT STDMETHODCALLTYPE SetSyncSource(IReferenceClock *pClock); - HRESULT STDMETHODCALLTYPE GetSyncSource(IReferenceClock **ppClock); - - // IBaseFilter - HRESULT STDMETHODCALLTYPE EnumPins(IEnumPins **ppEnum); - HRESULT STDMETHODCALLTYPE FindPin(LPCWSTR Id, IPin **ppPin); - - HRESULT STDMETHODCALLTYPE JoinFilterGraph(IFilterGraph *pGraph, LPCWSTR pName); - - HRESULT STDMETHODCALLTYPE QueryFilterInfo(FILTER_INFO *pInfo); - HRESULT STDMETHODCALLTYPE QueryVendorInfo(LPWSTR *pVendorInfo); - - // IAMFilterMiscFlags - ULONG STDMETHODCALLTYPE GetMiscFlags(); - - // IPin - HRESULT STDMETHODCALLTYPE Connect(IPin *pReceivePin, const AM_MEDIA_TYPE *pmt); - HRESULT STDMETHODCALLTYPE ReceiveConnection(IPin *pConnector, const AM_MEDIA_TYPE *pmt); - HRESULT STDMETHODCALLTYPE Disconnect(); - HRESULT STDMETHODCALLTYPE ConnectedTo(IPin **ppPin); - - HRESULT STDMETHODCALLTYPE ConnectionMediaType(AM_MEDIA_TYPE *pmt); - - HRESULT STDMETHODCALLTYPE QueryPinInfo(PIN_INFO *pInfo); - HRESULT STDMETHODCALLTYPE QueryId(LPWSTR *Id); - - HRESULT STDMETHODCALLTYPE QueryAccept(const AM_MEDIA_TYPE *pmt); - - HRESULT STDMETHODCALLTYPE EnumMediaTypes(IEnumMediaTypes **ppEnum); - - HRESULT STDMETHODCALLTYPE QueryInternalConnections(IPin **apPin, ULONG *nPin); - - HRESULT STDMETHODCALLTYPE EndOfStream(); - - HRESULT STDMETHODCALLTYPE BeginFlush(); - HRESULT STDMETHODCALLTYPE EndFlush(); - - HRESULT STDMETHODCALLTYPE NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate); - - HRESULT STDMETHODCALLTYPE QueryDirection(PIN_DIRECTION *pPinDir); - - int currentMediaTypeToken(); - HRESULT nextMediaType( - int token, int *index, ULONG count, AM_MEDIA_TYPE **types, ULONG *fetchedCount); - HRESULT skipMediaType(int token, int *index, ULONG count); - HRESULT cloneMediaType(int token, int index, IEnumMediaTypes **enumeration); - -protected: - void customEvent(QEvent *event); - -private Q_SLOTS: - void supportedFormatsChanged(); - void sampleReady(); - -private: - HRESULT start(); - void stop(); - void flush(); - - enum - { - StartSurface = QEvent::User, - StopSurface, - FlushSurface - }; - - LONG m_ref; - FILTER_STATE m_state; - QAbstractVideoSurface *m_surface; - DirectShowEventLoop *m_loop; - IFilterGraph *m_graph; - IPin *m_peerPin; - int m_bytesPerLine; - HRESULT m_startResult; - QString m_name; - QString m_pinId; - DirectShowMediaType m_mediaType; - QVideoSurfaceFormat m_surfaceFormat; - QMutex m_mutex; - QWaitCondition m_wait; - DirectShowSampleScheduler m_sampleScheduler; -}; - -#endif diff --git a/src/plugins/directshow/player/vmr9videowindowcontrol.cpp b/src/plugins/directshow/player/vmr9videowindowcontrol.cpp deleted file mode 100644 index 9d16c23..0000000 --- a/src/plugins/directshow/player/vmr9videowindowcontrol.cpp +++ /dev/null @@ -1,329 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "vmr9videowindowcontrol.h" - -#include "directshowglobal.h" - -Vmr9VideoWindowControl::Vmr9VideoWindowControl(QObject *parent) - : QVideoWindowControl(parent) - , m_filter(com_new<IBaseFilter>(CLSID_VideoMixingRenderer9, IID_IBaseFilter)) - , m_windowId(0) - , m_dirtyValues(0) - , m_aspectRatioMode(Qt::KeepAspectRatio) - , m_brightness(0) - , m_contrast(0) - , m_hue(0) - , m_saturation(0) - , m_fullScreen(false) -{ - if (IVMRFilterConfig9 *config = com_cast<IVMRFilterConfig9>(m_filter, IID_IVMRFilterConfig9)) { - config->SetRenderingMode(VMR9Mode_Windowless); - config->SetNumberOfStreams(1); - config->Release(); - } -} - -Vmr9VideoWindowControl::~Vmr9VideoWindowControl() -{ - if (m_filter) - m_filter->Release(); -} - - -WId Vmr9VideoWindowControl::winId() const -{ - return m_windowId; - -} - -void Vmr9VideoWindowControl::setWinId(WId id) -{ - m_windowId = id; - - if (QWidget *widget = QWidget::find(m_windowId)) { - const QColor color = widget->palette().color(QPalette::Window); - - m_windowColor = RGB(color.red(), color.green(), color.blue()); - } - - if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>( - m_filter, IID_IVMRWindowlessControl9)) { - control->SetVideoClippingWindow(m_windowId); - control->SetBorderColor(m_windowColor); - control->Release(); - } -} - -QRect Vmr9VideoWindowControl::displayRect() const -{ - return m_displayRect; -} - -void Vmr9VideoWindowControl::setDisplayRect(const QRect &rect) -{ - m_displayRect = rect; - - if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>( - m_filter, IID_IVMRWindowlessControl9)) { - RECT sourceRect = { 0, 0, 0, 0 }; - RECT displayRect = { rect.left(), rect.top(), rect.right() + 1, rect.bottom() + 1 }; - - control->GetNativeVideoSize(&sourceRect.right, &sourceRect.bottom, 0, 0); - - if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) { - QSize clippedSize = rect.size(); - clippedSize.scale(sourceRect.right, sourceRect.bottom, Qt::KeepAspectRatio); - - sourceRect.left = (sourceRect.right - clippedSize.width()) / 2; - sourceRect.top = (sourceRect.bottom - clippedSize.height()) / 2; - sourceRect.right = sourceRect.left + clippedSize.width(); - sourceRect.bottom = sourceRect.top + clippedSize.height(); - } - - control->SetVideoPosition(&sourceRect, &displayRect); - control->Release(); - } -} - -bool Vmr9VideoWindowControl::isFullScreen() const -{ - return m_fullScreen; -} - -void Vmr9VideoWindowControl::setFullScreen(bool fullScreen) -{ - emit fullScreenChanged(m_fullScreen = fullScreen); -} - -void Vmr9VideoWindowControl::repaint() -{ - PAINTSTRUCT paint; - - if (HDC dc = ::BeginPaint(m_windowId, &paint)) { - HRESULT hr = E_FAIL; - - if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>( - m_filter, IID_IVMRWindowlessControl9)) { - hr = control->RepaintVideo(m_windowId, dc); - control->Release(); - } - - if (!SUCCEEDED(hr)) { - HPEN pen = ::CreatePen(PS_SOLID, 1, m_windowColor); - HBRUSH brush = ::CreateSolidBrush(m_windowColor); - ::SelectObject(dc, pen); - ::SelectObject(dc, brush); - - ::Rectangle( - dc, - m_displayRect.left(), - m_displayRect.top(), - m_displayRect.right() + 1, - m_displayRect.bottom() + 1); - - ::DeleteObject(pen); - ::DeleteObject(brush); - } - ::EndPaint(m_windowId, &paint); - } -} - -QSize Vmr9VideoWindowControl::nativeSize() const -{ - QSize size; - - if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>( - m_filter, IID_IVMRWindowlessControl9)) { - LONG width; - LONG height; - - if (control->GetNativeVideoSize(&width, &height, 0, 0) == S_OK) - size = QSize(width, height); - control->Release(); - } - return size; -} - -Qt::AspectRatioMode Vmr9VideoWindowControl::aspectRatioMode() const -{ - return m_aspectRatioMode; -} - -void Vmr9VideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode) -{ - m_aspectRatioMode = mode; - - if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>( - m_filter, IID_IVMRWindowlessControl9)) { - switch (mode) { - case Qt::IgnoreAspectRatio: - control->SetAspectRatioMode(VMR9ARMode_None); - break; - case Qt::KeepAspectRatio: - control->SetAspectRatioMode(VMR9ARMode_LetterBox); - break; - case Qt::KeepAspectRatioByExpanding: - control->SetAspectRatioMode(VMR9ARMode_LetterBox); - setDisplayRect(m_displayRect); - break; - default: - break; - } - control->Release(); - } -} - -int Vmr9VideoWindowControl::brightness() const -{ - return m_brightness; -} - -void Vmr9VideoWindowControl::setBrightness(int brightness) -{ - m_brightness = brightness; - - m_dirtyValues |= ProcAmpControl9_Brightness; - - setProcAmpValues(); - - emit brightnessChanged(brightness); -} - -int Vmr9VideoWindowControl::contrast() const -{ - return m_contrast; -} - -void Vmr9VideoWindowControl::setContrast(int contrast) -{ - m_contrast = contrast; - - m_dirtyValues |= ProcAmpControl9_Contrast; - - setProcAmpValues(); - - emit contrastChanged(contrast); -} - -int Vmr9VideoWindowControl::hue() const -{ - return m_hue; -} - -void Vmr9VideoWindowControl::setHue(int hue) -{ - m_hue = hue; - - m_dirtyValues |= ProcAmpControl9_Hue; - - setProcAmpValues(); - - emit hueChanged(hue); -} - -int Vmr9VideoWindowControl::saturation() const -{ - return m_saturation; -} - -void Vmr9VideoWindowControl::setSaturation(int saturation) -{ - m_saturation = saturation; - - m_dirtyValues |= ProcAmpControl9_Saturation; - - setProcAmpValues(); - - emit saturationChanged(saturation); -} - -void Vmr9VideoWindowControl::setProcAmpValues() -{ - if (IVMRMixerControl9 *control = com_cast<IVMRMixerControl9>(m_filter, IID_IVMRMixerControl9)) { - VMR9ProcAmpControl procAmp; - procAmp.dwSize = sizeof(VMR9ProcAmpControl); - procAmp.dwFlags = m_dirtyValues; - - if (m_dirtyValues & ProcAmpControl9_Brightness) { - procAmp.Brightness = scaleProcAmpValue( - control, ProcAmpControl9_Brightness, m_brightness); - } - if (m_dirtyValues & ProcAmpControl9_Contrast) { - procAmp.Contrast = scaleProcAmpValue( - control, ProcAmpControl9_Contrast, m_contrast); - } - if (m_dirtyValues & ProcAmpControl9_Hue) { - procAmp.Hue = scaleProcAmpValue( - control, ProcAmpControl9_Hue, m_hue); - } - if (m_dirtyValues & ProcAmpControl9_Saturation) { - procAmp.Saturation = scaleProcAmpValue( - control, ProcAmpControl9_Saturation, m_saturation); - } - - if (SUCCEEDED(control->SetProcAmpControl(0, &procAmp))) { - m_dirtyValues = 0; - } - - control->Release(); - } -} - -float Vmr9VideoWindowControl::scaleProcAmpValue( - IVMRMixerControl9 *control, VMR9ProcAmpControlFlags property, int value) const -{ - float scaledValue = 0.0; - - VMR9ProcAmpControlRange range; - range.dwSize = sizeof(VMR9ProcAmpControlRange); - range.dwProperty = property; - - if (SUCCEEDED(control->GetProcAmpControlRange(0, &range))) { - scaledValue = range.DefaultValue; - if (value > 0) - scaledValue += float(value) * (range.MaxValue - range.DefaultValue) / 100; - else if (value < 0) - scaledValue -= float(value) * (range.MinValue - range.DefaultValue) / 100; - } - - return scaledValue; -} diff --git a/src/plugins/directshow/player/vmr9videowindowcontrol.h b/src/plugins/directshow/player/vmr9videowindowcontrol.h deleted file mode 100644 index 1e56bb6..0000000 --- a/src/plugins/directshow/player/vmr9videowindowcontrol.h +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef VMR9VIDEOWINDOWCONTROL_H -#define VMR9VIDEOWINDOWCONTROL_H - -#include "qvideowindowcontrol.h" - -#include <dshow.h> -#include <d3d9.h> -#include <vmr9.h> - -QT_USE_NAMESPACE - -class Vmr9VideoWindowControl : public QVideoWindowControl -{ - Q_OBJECT -public: - Vmr9VideoWindowControl(QObject *parent = 0); - ~Vmr9VideoWindowControl(); - - IBaseFilter *filter() const { return m_filter; } - - WId winId() const; - void setWinId(WId id); - - QRect displayRect() const; - void setDisplayRect(const QRect &rect); - - bool isFullScreen() const; - void setFullScreen(bool fullScreen); - - void repaint(); - - QSize nativeSize() const; - - Qt::AspectRatioMode aspectRatioMode() const; - void setAspectRatioMode(Qt::AspectRatioMode mode); - - int brightness() const; - void setBrightness(int brightness); - - int contrast() const; - void setContrast(int contrast); - - int hue() const; - void setHue(int hue); - - int saturation() const; - void setSaturation(int saturation); - -private: - void setProcAmpValues(); - float scaleProcAmpValue( - IVMRMixerControl9 *control, VMR9ProcAmpControlFlags property, int value) const; - - IBaseFilter *m_filter; - WId m_windowId; - COLORREF m_windowColor; - DWORD m_dirtyValues; - Qt::AspectRatioMode m_aspectRatioMode; - QRect m_displayRect; - int m_brightness; - int m_contrast; - int m_hue; - int m_saturation; - bool m_fullScreen; -}; - -#endif diff --git a/src/plugins/gstreamer/camerabin/camerabin.pri b/src/plugins/gstreamer/camerabin/camerabin.pri deleted file mode 100644 index 5c266e7..0000000 --- a/src/plugins/gstreamer/camerabin/camerabin.pri +++ /dev/null @@ -1,50 +0,0 @@ -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 diff --git a/src/plugins/gstreamer/camerabin/camerabinaudioencoder.cpp b/src/plugins/gstreamer/camerabin/camerabinaudioencoder.cpp deleted file mode 100644 index c1f2df9..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinaudioencoder.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "camerabinaudioencoder.h" -#include "camerabincontainer.h" -#include "qgstcodecsinfo.h" - -#include <QtCore/qdebug.h> - -CameraBinAudioEncoder::CameraBinAudioEncoder(QObject *parent) - :QAudioEncoderControl(parent), - m_codecs(QGstCodecsInfo::AudioEncoder) -{ -} - -CameraBinAudioEncoder::~CameraBinAudioEncoder() -{ -} - -QStringList CameraBinAudioEncoder::supportedAudioCodecs() const -{ - return m_codecs.supportedCodecs(); -} - -QString CameraBinAudioEncoder::codecDescription(const QString &codecName) const -{ - return m_codecs.codecDescription(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; -} - -GstEncodingProfile *CameraBinAudioEncoder::createProfile() -{ - QString codec = m_audioSettings.codec(); - GstCaps *caps; - - if (codec.isEmpty()) - caps = gst_caps_new_any(); - else - caps = gst_caps_from_string(codec.toLatin1()); - - return (GstEncodingProfile *)gst_encoding_audio_profile_new( - caps, - NULL, //preset - NULL, //restriction - 0); //presence -} diff --git a/src/plugins/gstreamer/camerabin/camerabinaudioencoder.h b/src/plugins/gstreamer/camerabin/camerabinaudioencoder.h deleted file mode 100644 index 5468fde..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinaudioencoder.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef 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 <gst/pbutils/pbutils.h> -#include <gst/pbutils/encoding-profile.h> - -#include <qaudioformat.h> -#include "qgstcodecsinfo.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&); - - void setActualAudioSettings(const QAudioEncoderSettings&); - void resetActualSettings(); - - GstEncodingProfile *createProfile(); - -Q_SIGNALS: - void settingsChanged(); - -private: - QGstCodecsInfo m_codecs; - QMap<QString,QStringList> m_codecOptions; - QMap<QString, QMap<QString, QVariant> > m_options; - - QAudioEncoderSettings m_audioSettings; - QAudioEncoderSettings m_userSettings; -}; - -#endif diff --git a/src/plugins/gstreamer/camerabin/camerabincapturebufferformat.cpp b/src/plugins/gstreamer/camerabin/camerabincapturebufferformat.cpp deleted file mode 100644 index 0611d8b..0000000 --- a/src/plugins/gstreamer/camerabin/camerabincapturebufferformat.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "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); - } -} diff --git a/src/plugins/gstreamer/camerabin/camerabincapturebufferformat.h b/src/plugins/gstreamer/camerabin/camerabincapturebufferformat.h deleted file mode 100644 index af119e0..0000000 --- a/src/plugins/gstreamer/camerabin/camerabincapturebufferformat.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef 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 diff --git a/src/plugins/gstreamer/camerabin/camerabincapturedestination.cpp b/src/plugins/gstreamer/camerabin/camerabincapturedestination.cpp deleted file mode 100644 index 7472d29..0000000 --- a/src/plugins/gstreamer/camerabin/camerabincapturedestination.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "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); - } -} diff --git a/src/plugins/gstreamer/camerabin/camerabincapturedestination.h b/src/plugins/gstreamer/camerabin/camerabincapturedestination.h deleted file mode 100644 index 387c3ee..0000000 --- a/src/plugins/gstreamer/camerabin/camerabincapturedestination.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef 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 diff --git a/src/plugins/gstreamer/camerabin/camerabincontainer.cpp b/src/plugins/gstreamer/camerabin/camerabincontainer.cpp deleted file mode 100644 index d0d27fb..0000000 --- a/src/plugins/gstreamer/camerabin/camerabincontainer.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "camerabincontainer.h" -#include <QtCore/qregexp.h> - -#include <QtCore/qdebug.h> - -CameraBinContainer::CameraBinContainer(QObject *parent) - :QMediaContainerControl(parent), - m_supportedContainers(QGstCodecsInfo::Muxer) -{ - //extension for containers hard to guess from mimetype - m_fileExtensions["video/x-matroska"] = "mkv"; - m_fileExtensions["video/quicktime"] = "mov"; - m_fileExtensions["video/x-msvideo"] = "avi"; - m_fileExtensions["video/msvideo"] = "avi"; - m_fileExtensions["audio/mpeg"] = "mp3"; - m_fileExtensions["application/x-shockwave-flash"] = "swf"; - m_fileExtensions["application/x-pn-realmedia"] = "rm"; -} - -QStringList CameraBinContainer::supportedContainers() const -{ - return m_supportedContainers.supportedCodecs(); -} - -QString CameraBinContainer::containerDescription(const QString &formatMimeType) const -{ - return m_supportedContainers.codecDescription(formatMimeType); -} - -QString CameraBinContainer::containerMimeType() const -{ - return m_format; -} - -void CameraBinContainer::setContainerMimeType(const QString &formatMimeType) -{ - m_format = formatMimeType; - - if (m_userFormat != formatMimeType) { - m_userFormat = formatMimeType; - emit settingsChanged(); - } -} - -void CameraBinContainer::setActualContainer(const QString &formatMimeType) -{ - m_format = formatMimeType; -} - -void CameraBinContainer::resetActualContainer() -{ - m_format = m_userFormat; -} - -GstEncodingContainerProfile *CameraBinContainer::createProfile() -{ - GstCaps *caps; - - if (m_format.isEmpty()) - caps = gst_caps_new_any(); - else - caps = gst_caps_from_string(m_format.toLatin1()); - - return (GstEncodingContainerProfile *)gst_encoding_container_profile_new( - "camerabin2_profile", - (gchar *)"custom camera profile", - caps, - NULL); //preset -} - -/*! - Suggest file extension for current container mimetype. - */ -QString CameraBinContainer::suggestedFileExtension() const -{ - QString format = m_format.left(m_format.indexOf(',')); - QString extension = m_fileExtensions.value(format); - - if (!extension.isEmpty() || format.isEmpty()) - return extension; - - QRegExp rx("[-/]([\\w]+)$"); - - if (rx.indexIn(format) != -1) - extension = rx.cap(1); - - return extension; -} diff --git a/src/plugins/gstreamer/camerabin/camerabincontainer.h b/src/plugins/gstreamer/camerabin/camerabincontainer.h deleted file mode 100644 index 5eaa19f..0000000 --- a/src/plugins/gstreamer/camerabin/camerabincontainer.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef CAMERABINMEDIACONTAINERCONTROL_H -#define CAMERABINMEDIACONTAINERCONTROL_H - -#include <qmediacontainercontrol.h> -#include <QtCore/qstringlist.h> -#include <QtCore/qset.h> - -#include <gst/gst.h> -#include <gst/pbutils/pbutils.h> -#include <gst/pbutils/encoding-profile.h> - -#include "qgstcodecsinfo.h" - -QT_USE_NAMESPACE - -class CameraBinContainer : public QMediaContainerControl -{ -Q_OBJECT -public: - CameraBinContainer(QObject *parent); - virtual ~CameraBinContainer() {} - - virtual QStringList supportedContainers() const; - virtual QString containerDescription(const QString &formatMimeType) const; - - virtual QString containerMimeType() const; - virtual void setContainerMimeType(const QString &formatMimeType); - - void setActualContainer(const QString &formatMimeType); - void resetActualContainer(); - - QString suggestedFileExtension() const; - - GstEncodingContainerProfile *createProfile(); - -Q_SIGNALS: - void settingsChanged(); - -private: - QString m_format; // backend selected format, using m_userFormat - QString m_userFormat; - QMap<QString, QString> m_fileExtensions; - - QGstCodecsInfo m_supportedContainers; -}; - -#endif // CAMERABINMEDIACONTAINERCONTROL_H diff --git a/src/plugins/gstreamer/camerabin/camerabincontrol.cpp b/src/plugins/gstreamer/camerabin/camerabincontrol.cpp deleted file mode 100644 index f40133d..0000000 --- a/src/plugins/gstreamer/camerabin/camerabincontrol.cpp +++ /dev/null @@ -1,341 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "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, 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); - - 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 -{ - 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); -} diff --git a/src/plugins/gstreamer/camerabin/camerabincontrol.h b/src/plugins/gstreamer/camerabin/camerabincontrol.h deleted file mode 100644 index 3f90ca4..0000000 --- a/src/plugins/gstreamer/camerabin/camerabincontrol.h +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef 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 diff --git a/src/plugins/gstreamer/camerabin/camerabinexposure.cpp b/src/plugins/gstreamer/camerabin/camerabinexposure.cpp deleted file mode 100644 index 4c7b8aa..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinexposure.cpp +++ /dev/null @@ -1,232 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "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(); -} diff --git a/src/plugins/gstreamer/camerabin/camerabinexposure.h b/src/plugins/gstreamer/camerabin/camerabinexposure.h deleted file mode 100644 index 4be21d3..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinexposure.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef 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 diff --git a/src/plugins/gstreamer/camerabin/camerabinflash.cpp b/src/plugins/gstreamer/camerabin/camerabinflash.cpp deleted file mode 100644 index 0882747..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinflash.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "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; -} - diff --git a/src/plugins/gstreamer/camerabin/camerabinflash.h b/src/plugins/gstreamer/camerabin/camerabinflash.h deleted file mode 100644 index 40b9724..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinflash.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef 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 - diff --git a/src/plugins/gstreamer/camerabin/camerabinfocus.cpp b/src/plugins/gstreamer/camerabin/camerabinfocus.cpp deleted file mode 100644 index b989c50..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinfocus.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "camerabinfocus.h" -#include "camerabinsession.h" - -#include <gst/interfaces/photography.h> - -#include <QDebug> -#include <QtCore/qmetaobject.h> - -//#define CAMERABIN_DEBUG 1 -#define ZOOM_PROPERTY "zoom" -#define MAX_ZOOM_PROPERTY "max-zoom" - -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))); -} - -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 -{ - gfloat zoomFactor = 1.0; - g_object_get(GST_BIN(m_session->cameraBin()), MAX_ZOOM_PROPERTY, &zoomFactor, NULL); - return zoomFactor; -} - -qreal CameraBinFocus::opticalZoom() const -{ - return 1.0; -} - -qreal CameraBinFocus::digitalZoom() const -{ - gfloat zoomFactor = 1.0; - g_object_get(GST_BIN(m_session->cameraBin()), ZOOM_PROPERTY, &zoomFactor, NULL); - return zoomFactor; -} - -void CameraBinFocus::zoomTo(qreal optical, qreal digital) -{ - Q_UNUSED(optical); - digital = qBound(qreal(1.0), digital, maximumDigitalZoom()); - g_object_set(GST_BIN(m_session->cameraBin()), ZOOM_PROPERTY, digital, NULL); - 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:" - << m_focusStatus - << "New:" - << status << 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_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); -} diff --git a/src/plugins/gstreamer/camerabin/camerabinfocus.h b/src/plugins/gstreamer/camerabin/camerabinfocus.h deleted file mode 100644 index df9448a..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinfocus.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef 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); - -private: - CameraBinSession *m_session; - QCameraFocus::FocusMode m_focusMode; - QCamera::LockStatus m_focusStatus; - QCameraFocusZone::FocusZoneStatus m_focusZoneStatus; -}; - -#endif // CAMERABINFOCUSCONTROL_H diff --git a/src/plugins/gstreamer/camerabin/camerabinimagecapture.cpp b/src/plugins/gstreamer/camerabin/camerabinimagecapture.cpp deleted file mode 100644 index 874361e..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinimagecapture.cpp +++ /dev/null @@ -1,339 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "camerabinimagecapture.h" -#include "camerabincapturedestination.h" -#include "camerabincapturebufferformat.h" -#include "camerabinsession.h" -#include <private/qgstvideobuffer_p.h> -#include <private/qvideosurfacegstsink_p.h> -#include <private/qgstutils_p.h> -#include <QtCore/qdebug.h> -#include <QtCore/qbuffer.h> -#include <QtGui/qimagereader.h> - -//#define DEBUG_CAPTURE - -#define IMAGE_DONE_SIGNAL "image-done" - -Q_DECLARE_METATYPE(QVideoFrame) -Q_DECLARE_METATYPE(QtMultimedia::MetaData) - -namespace -{ -class CameraRegisterMetaTypes -{ -public: - CameraRegisterMetaTypes() - { - qRegisterMetaType<QVideoFrame>("QVideoFrame"); - qRegisterMetaType<QtMultimedia::MetaData>("QtMultimedia::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))); - - m_session->bus()->installMessageFilter(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::metadataEventProbe(GstPad *pad, GstEvent *event, CameraBinImageCapture *self) -{ - Q_UNUSED(pad); - - 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<QtMultimedia::MetaData, QVariant> tags; - tags[QtMultimedia::ISOSpeedRatings] = extendedTags.value("capturing-iso-speed"); - tags[QtMultimedia::DigitalZoomRatio] = extendedTags.value("capturing-digital-zoom-ratio"); - tags[QtMultimedia::ExposureTime] = extendedTags.value("capturing-shutter-speed"); - tags[QtMultimedia::WhiteBalance] = extendedTags.value("capturing-white-balance"); - tags[QtMultimedia::Flash] = extendedTags.value("capturing-flash-fired"); - tags[QtMultimedia::FocalLengthIn35mmFilm] = extendedTags.value("capturing-focal-length"); - tags[QtMultimedia::MeteringMode] = extendedTags.value("capturing-metering-mode"); - tags[QtMultimedia::ExposureMode] = extendedTags.value("capturing-exposure-mode"); - tags[QtMultimedia::FNumber] = extendedTags.value("capturing-focal-ratio"); - tags[QtMultimedia::ExposureMode] = extendedTags.value("capturing-exposure-mode"); - - QMapIterator<QtMultimedia::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(QtMultimedia::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; -} - -bool CameraBinImageCapture::processBusMessage(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 false; - - 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); - } - } - } else if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ELEMENT) { - if (GST_MESSAGE_SRC(gm) == (GstObject *)m_session->cameraBin()) { - const GstStructure *structure = gst_message_get_structure(gm); - - if (gst_structure_has_name (structure, "image-done")) { - const gchar *fileName = gst_structure_get_string (structure, "filename"); -#ifdef DEBUG_CAPTURE - qDebug() << "Image saved" << fileName; -#endif - - if (m_session->captureDestinationControl()->captureDestination() & QCameraImageCapture::CaptureToFile) { - emit imageSaved(m_requestId, 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.exists() && info.isFile() && info.size() == 0) { - QFile(info.absoluteFilePath()).remove(); - } - } - } - } - } - - return false; -} - diff --git a/src/plugins/gstreamer/camerabin/camerabinimagecapture.h b/src/plugins/gstreamer/camerabin/camerabinimagecapture.h deleted file mode 100644 index 4a902e9..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinimagecapture.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef CAMERABINIMAGECAPTURECONTROL_H -#define CAMERABINIMAGECAPTURECONTROL_H - -#include <qcameraimagecapturecontrol.h> -#include "camerabinsession.h" - -QT_USE_NAMESPACE - -class CameraBinImageCapture : public QCameraImageCaptureControl, public QGstreamerBusMessageFilter -{ - Q_OBJECT - Q_INTERFACES(QGstreamerBusMessageFilter) -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(); - - bool processBusMessage(const QGstreamerMessage &message); - -private slots: - void updateState(); - -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 *); - - CameraBinSession *m_session; - bool m_ready; - int m_requestId; - GstElement *m_jpegEncoderElement; - GstElement *m_metadataMuxerElement; -}; - -#endif // CAMERABINCAPTURECORNTROL_H diff --git a/src/plugins/gstreamer/camerabin/camerabinimageencoder.cpp b/src/plugins/gstreamer/camerabin/camerabinimageencoder.cpp deleted file mode 100644 index c020400..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinimageencoder.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "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(); -} diff --git a/src/plugins/gstreamer/camerabin/camerabinimageencoder.h b/src/plugins/gstreamer/camerabin/camerabinimageencoder.h deleted file mode 100644 index 6d49b2f..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinimageencoder.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef 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 diff --git a/src/plugins/gstreamer/camerabin/camerabinimageprocessing.cpp b/src/plugins/gstreamer/camerabin/camerabinimageprocessing.cpp deleted file mode 100644 index b219146..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinimageprocessing.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "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(); -} - diff --git a/src/plugins/gstreamer/camerabin/camerabinimageprocessing.h b/src/plugins/gstreamer/camerabin/camerabinimageprocessing.h deleted file mode 100644 index ffee55b..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinimageprocessing.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef 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 diff --git a/src/plugins/gstreamer/camerabin/camerabinlocks.cpp b/src/plugins/gstreamer/camerabin/camerabinlocks.cpp deleted file mode 100644 index cc0e3eb..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinlocks.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "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); -} diff --git a/src/plugins/gstreamer/camerabin/camerabinlocks.h b/src/plugins/gstreamer/camerabin/camerabinlocks.h deleted file mode 100644 index 07cb9d1..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinlocks.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef 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 diff --git a/src/plugins/gstreamer/camerabin/camerabinmetadata.cpp b/src/plugins/gstreamer/camerabin/camerabinmetadata.cpp deleted file mode 100644 index 235f5b0..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinmetadata.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "camerabinmetadata.h" - -#include <gst/gst.h> -#include <gst/gstversion.h> - -struct QGstreamerMetaDataKeyLookup -{ - QtMultimedia::MetaData key; - const char *token; -}; - -static const QGstreamerMetaDataKeyLookup qt_gstreamerMetaDataKeys[] = -{ - { QtMultimedia::Title, GST_TAG_TITLE }, - //{ QtMultimedia::SubTitle, 0 }, - //{ QtMultimedia::Author, 0 }, - { QtMultimedia::Comment, GST_TAG_COMMENT }, - { QtMultimedia::Description, GST_TAG_DESCRIPTION }, - //{ QtMultimedia::Category, 0 }, - { QtMultimedia::Genre, GST_TAG_GENRE }, - //{ QtMultimedia::Year, 0 }, - //{ QtMultimedia::UserRating, 0 }, - - { QtMultimedia::Language, GST_TAG_LANGUAGE_CODE }, - - { QtMultimedia::Publisher, GST_TAG_ORGANIZATION }, - { QtMultimedia::Copyright, GST_TAG_COPYRIGHT }, - //{ QtMultimedia::ParentalRating, 0 }, - //{ QtMultimedia::RatingOrganisation, 0 }, - - // Media - //{ QtMultimedia::Size, 0 }, - //{ QtMultimedia::MediaType, 0 }, - { QtMultimedia::Duration, GST_TAG_DURATION }, - - // Audio - { QtMultimedia::AudioBitRate, GST_TAG_BITRATE }, - { QtMultimedia::AudioCodec, GST_TAG_AUDIO_CODEC }, - //{ QtMultimedia::ChannelCount, 0 }, - //{ QtMultimedia::SampleRate, 0 }, - - // Music - { QtMultimedia::AlbumTitle, GST_TAG_ALBUM }, - { QtMultimedia::AlbumArtist, GST_TAG_ARTIST}, - { QtMultimedia::ContributingArtist, GST_TAG_PERFORMER }, -#if (GST_VERSION_MAJOR >= 0) && (GST_VERSION_MINOR >= 10) && (GST_VERSION_MICRO >= 19) - { QtMultimedia::Composer, GST_TAG_COMPOSER }, -#endif - //{ QtMultimedia::Conductor, 0 }, - //{ QtMultimedia::Lyrics, 0 }, - //{ QtMultimedia::Mood, 0 }, - { QtMultimedia::TrackNumber, GST_TAG_TRACK_NUMBER }, - - //{ QtMultimedia::CoverArtUrlSmall, 0 }, - //{ QtMultimedia::CoverArtUrlLarge, 0 }, - - // Image/Video - //{ QtMultimedia::Resolution, 0 }, - //{ QtMultimedia::PixelAspectRatio, 0 }, - - // Video - //{ QtMultimedia::VideoFrameRate, 0 }, - //{ QtMultimedia::VideoBitRate, 0 }, - { QtMultimedia::VideoCodec, GST_TAG_VIDEO_CODEC }, - - //{ QtMultimedia::PosterUrl, 0 }, - - // Movie - //{ QtMultimedia::ChapterNumber, 0 }, - //{ QtMultimedia::Director, 0 }, - { QtMultimedia::LeadPerformer, GST_TAG_PERFORMER }, - //{ QtMultimedia::Writer, 0 }, - - // Photos - //{ QtMultimedia::CameraManufacturer, 0 }, - //{ QtMultimedia::CameraModel, 0 }, - //{ QtMultimedia::Event, 0 }, - //{ QtMultimedia::Subject, 0 } -}; - -CameraBinMetaData::CameraBinMetaData(QObject *parent) - :QMetaDataWriterControl(parent) -{ -} - -QVariant CameraBinMetaData::metaData(QtMultimedia::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(QtMultimedia::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<QtMultimedia::MetaData> CameraBinMetaData::availableMetaData() const -{ - static QMap<QByteArray, QtMultimedia::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<QtMultimedia::MetaData> res; - foreach (const QByteArray &key, m_values.keys()) { - QtMultimedia::MetaData tag = keysMap.value(key, QtMultimedia::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; -} diff --git a/src/plugins/gstreamer/camerabin/camerabinmetadata.h b/src/plugins/gstreamer/camerabin/camerabinmetadata.h deleted file mode 100644 index 16a86a6..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinmetadata.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef 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(QtMultimedia::MetaData key) const; - void setMetaData(QtMultimedia::MetaData key, const QVariant &value); - QList<QtMultimedia::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 diff --git a/src/plugins/gstreamer/camerabin/camerabinrecorder.cpp b/src/plugins/gstreamer/camerabin/camerabinrecorder.cpp deleted file mode 100644 index ff97c3f..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinrecorder.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "camerabinrecorder.h" -#include "camerabinaudioencoder.h" -#include "camerabinvideoencoder.h" -#include "camerabincontainer.h" -#include <QtCore/QDebug> - -#include <gst/pbutils/encoding-profile.h> - -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) { - m_session->recordVideo(); - emit stateChanged(m_state = QMediaRecorder::RecordingState); - } else - emit error(QMediaRecorder::ResourceError, tr("Service has not been started")); -} - -void CameraBinRecorder::pause() -{ - emit error(QMediaRecorder::ResourceError, tr("QMediaRecorder::pause() is not supported by camerabin2.")); -} - -void CameraBinRecorder::stop() -{ - if (m_session->state() == QCamera::ActiveState) { - m_session->stopVideoRecording(); - emit stateChanged(m_state = QMediaRecorder::StoppedState); - } -} - -void CameraBinRecorder::applySettings() -{ - GstEncodingContainerProfile *containerProfile = m_session->mediaContainerControl()->createProfile(); - - if (containerProfile) { - GstEncodingProfile *audioProfile = m_session->audioEncodeControl()->createProfile(); - GstEncodingProfile *videoProfile = m_session->videoEncodeControl()->createProfile(); - - gst_encoding_container_profile_add_profile(containerProfile, audioProfile); - gst_encoding_container_profile_add_profile(containerProfile, videoProfile); - } - - g_object_set (G_OBJECT(m_session->cameraBin()), "video-profile", containerProfile, NULL); -} - -bool CameraBinRecorder::isMuted() const -{ - return m_session->isMuted(); -} - -void CameraBinRecorder::setMuted(bool muted) -{ - m_session->setMuted(muted); -} diff --git a/src/plugins/gstreamer/camerabin/camerabinrecorder.h b/src/plugins/gstreamer/camerabin/camerabinrecorder.h deleted file mode 100644 index f68c4ee..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinrecorder.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef 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; - - 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 diff --git a/src/plugins/gstreamer/camerabin/camerabinresourcepolicy.cpp b/src/plugins/gstreamer/camerabin/camerabinresourcepolicy.cpp deleted file mode 100644 index df5583d..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinresourcepolicy.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "camerabinresourcepolicy.h" - -//#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 -} diff --git a/src/plugins/gstreamer/camerabin/camerabinresourcepolicy.h b/src/plugins/gstreamer/camerabin/camerabinresourcepolicy.h deleted file mode 100644 index bd483bf..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinresourcepolicy.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef 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 diff --git a/src/plugins/gstreamer/camerabin/camerabinservice.cpp b/src/plugins/gstreamer/camerabin/camerabinservice.cpp deleted file mode 100644 index f0aaca7..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinservice.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "camerabinservice.h" -#include "camerabinsession.h" -#include "camerabinrecorder.h" -#include "camerabincontainer.h" -#include "camerabinaudioencoder.h" -#include "camerabinvideoencoder.h" -#include "camerabinimageencoder.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 <private/qgstreamerbushelper_p.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_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 - -#if defined(Q_WS_X11) && !defined(QT_NO_XVIDEO) - -#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); - -#endif - - } - - 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_6) - new CameraButtonListener(this); -#endif -} - -CameraBinService::~CameraBinService() -{ -} - -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; - } else if (qstrcmp(name, QVideoWindowControl_iid) == 0) { - m_videoOutput = m_videoWindow; - } else if (qstrcmp(name, QVideoWidgetControl_iid) == 0) { - m_videoOutput = m_videoWidgetControl; - } - - if (m_videoOutput) { - m_captureSession->setViewfinder(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("camerabin2"); - if (factory) { - gst_object_unref(GST_OBJECT(factory)); - return true; - } - - return false; -} diff --git a/src/plugins/gstreamer/camerabin/camerabinservice.h b/src/plugins/gstreamer/camerabin/camerabinservice.h deleted file mode 100644 index 5513dd8..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinservice.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef 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 diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.cpp b/src/plugins/gstreamer/camerabin/camerabinsession.cpp deleted file mode 100644 index 996e149..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinsession.cpp +++ /dev/null @@ -1,1216 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "camerabinsession.h" -#include "camerabinrecorder.h" -#include "camerabincontainer.h" -#include "camerabinaudioencoder.h" -#include "camerabinvideoencoder.h" -#include "camerabinimageencoder.h" -#include "camerabinexposure.h" -#include "camerabinflash.h" -#include "camerabinfocus.h" -#include "camerabinimageprocessing.h" -#include "camerabinlocks.h" -#include "camerabincapturedestination.h" -#include "camerabincapturebufferformat.h" -#include <private/qgstreamerbushelper_p.h> -#include "qgstreamervideorendererinterface.h" -#include <qmediarecorder.h> -#include <gst/interfaces/photography.h> -#include <gst/gsttagsetter.h> -#include <gst/gstversion.h> - -#include <QtCore/qdebug.h> -#include <QCoreApplication> -#include <QtCore/qmetaobject.h> -#include <QtGui/qdesktopservices.h> - -#include <QtGui/qimage.h> - -//#define CAMERABIN_DEBUG 1 -//#define CAMERABIN_DEBUG_DUMP_BIN 1 -#define ENUM_NAME(c,e,v) (c::staticMetaObject.enumerator(c::staticMetaObject.indexOfEnumerator(e)).valueToKey((v))) - -#define FILENAME_PROPERTY "location" -#define MODE_PROPERTY "mode" -#define MUTE_PROPERTY "mute" -#define IMAGE_PP_PROPERTY "image-post-processing" -#define IMAGE_ENCODER_PROPERTY "image-encoder" -#define VIDEO_PP_PROPERTY "video-post-processing" -#define VIEWFINDER_SINK_PROPERTY "viewfinder-sink" -#define CAMERA_SOURCE_PROPERTY "camera-source" -#define AUDIO_SOURCE_PROPERTY "audio-source" -#define SUPPORTED_IMAGE_CAPTURE_CAPS_PROPERTY "image-capture-supported-caps" -#define SUPPORTED_VIDEO_CAPTURE_CAPS_PROPERTY "video-capture-supported-caps" -#define FILTER_CAPS_PROPERTY "filter-caps" -#define PREVIEW_CAPS_PROPERTY "preview-caps" - -#define CAPTURE_START "start-capture" -#define CAPTURE_STOP "stop-capture" -#define SET_VIDEO_RESOLUTION_FPS "set-video-resolution-fps" -#define SET_IMAGE_RESOLUTION "set-image-resolution" - -#define CAMERABIN_IMAGE_MODE 1 -#define CAMERABIN_VIDEO_MODE 2 - -#define gstRef(element) { gst_object_ref(GST_OBJECT(element)); gst_object_sink(GST_OBJECT(element)); } -#define gstUnref(element) { if (element) { gst_object_unref(GST_OBJECT(element)); element = 0; } } - -#define PREVIEW_CAPS_4_3 \ - "video/x-raw-rgb, width = (int) 640, height = (int) 480" - -#define VIEWFINDER_RESOLUTION_4x3 QSize(640, 480) -#define VIEWFINDER_RESOLUTION_3x2 QSize(720, 480) -#define VIEWFINDER_RESOLUTION_16x9 QSize(800, 450) - -//using GST_STATE_READY for QCamera::LoadedState -//may not work reliably at least with some webcams. - -//#define USE_READY_STATE_ON_LOADED - - -CameraBinSession::CameraBinSession(QObject *parent) - :QObject(parent), - m_recordingActive(false), - m_state(QCamera::UnloadedState), - m_pendingState(QCamera::UnloadedState), - m_pendingResolutionUpdate(false), - m_muted(false), - m_busy(false), - m_captureMode(QCamera::CaptureStillImage), - m_audioInputFactory(0), - m_videoInputFactory(0), - m_viewfinder(0), - m_viewfinderInterface(0), - m_videoSrc(0), - m_viewfinderElement(0), - m_viewfinderHasChanged(true), - m_videoInputHasChanged(true), - m_audioSrc(0), - m_audioConvert(0), - m_capsFilter(0), - m_fileSink(0), - m_audioEncoder(0), - m_muxer(0) -{ - m_camerabin = gst_element_factory_make("camerabin2", "camerabin2"); - g_signal_connect(G_OBJECT(m_camerabin), "notify::idle", G_CALLBACK(updateBusyStatus), this); - gstRef(m_camerabin); - - m_bus = gst_element_get_bus(m_camerabin); - - m_busHelper = new QGstreamerBusHelper(m_bus, this); - m_busHelper->installMessageFilter(this); - - m_audioEncodeControl = new CameraBinAudioEncoder(this); - m_videoEncodeControl = new CameraBinVideoEncoder(this); - m_imageEncodeControl = new CameraBinImageEncoder(this); - m_recorderControl = new CameraBinRecorder(this); - m_mediaContainerControl = new CameraBinContainer(this); - m_cameraExposureControl = new CameraBinExposure(this); - m_cameraFlashControl = new CameraBinFlash(this); - m_cameraFocusControl = new CameraBinFocus(this); - m_imageProcessingControl = new CameraBinImageProcessing(this); - m_cameraLocksControl = new CameraBinLocks(this); - m_captureDestinationControl = new CameraBinCaptureDestination(this); - m_captureBufferFormatControl = new CameraBinCaptureBufferFormat(this); - - //post image preview in RGB format - GstCaps *previewCaps = gst_caps_from_string("video/x-raw-rgb"); - g_object_set(G_OBJECT(m_camerabin), PREVIEW_CAPS_PROPERTY, previewCaps, NULL); - gst_caps_unref(previewCaps); -} - -CameraBinSession::~CameraBinSession() -{ - if (m_camerabin) { - if (m_viewfinderInterface) - m_viewfinderInterface->stopRenderer(); - - gst_element_set_state(m_camerabin, GST_STATE_NULL); - gst_element_get_state(m_camerabin, NULL, NULL, GST_CLOCK_TIME_NONE); - gstUnref(m_camerabin); - gstUnref(m_viewfinderElement); - } -} - -GstPhotography *CameraBinSession::photography() -{ - if (GST_IS_PHOTOGRAPHY(m_camerabin)) { - return GST_PHOTOGRAPHY(m_camerabin); - } - - if (!m_videoSrc) { - m_videoSrc = buildCameraSource(); - - if (m_videoSrc) - g_object_set(m_camerabin, CAMERA_SOURCE_PROPERTY, m_videoSrc, NULL); - else - g_object_get(m_camerabin, CAMERA_SOURCE_PROPERTY, &m_videoSrc, NULL); - - m_videoInputHasChanged = false; - } - - if (m_videoSrc && GST_IS_PHOTOGRAPHY(m_videoSrc)) - return GST_PHOTOGRAPHY(m_videoSrc); - - return 0; -} - -CameraBinSession::CameraRole CameraBinSession::cameraRole() const -{ - return BackCamera; -} - -/* - Configure camera during Loaded->Active states stansition. -*/ -bool CameraBinSession::setupCameraBin() -{ - if (m_videoInputHasChanged) { - m_videoSrc = buildCameraSource(); - - if (m_videoSrc) - g_object_set(m_camerabin, CAMERA_SOURCE_PROPERTY, m_videoSrc, NULL); - else - g_object_get(m_camerabin, CAMERA_SOURCE_PROPERTY, &m_videoSrc, NULL); - - m_videoInputHasChanged = false; - } - - - if (m_viewfinderHasChanged) { - if (m_viewfinderElement) - gst_object_unref(GST_OBJECT(m_viewfinderElement)); - - m_viewfinderElement = m_viewfinderInterface ? m_viewfinderInterface->videoSink() : 0; -#if CAMERABIN_DEBUG - qDebug() << Q_FUNC_INFO << "Viewfinder changed, reconfigure."; -#endif - m_viewfinderHasChanged = false; - if (!m_viewfinderElement) { - qWarning() << "Staring camera without viewfinder available"; - m_viewfinderElement = gst_element_factory_make("fakesink", NULL); - } - gst_object_ref(GST_OBJECT(m_viewfinderElement)); - gst_element_set_state(m_camerabin, GST_STATE_NULL); - g_object_set(G_OBJECT(m_camerabin), VIEWFINDER_SINK_PROPERTY, m_viewfinderElement, NULL); - } - - return true; -} - -static GstCaps *resolutionToCaps(const QSize &resolution, - const QPair<int, int> &rate = qMakePair<int,int>(0,0)) -{ - if (resolution.isEmpty()) - return gst_caps_new_any(); - - GstCaps *caps = 0; - if (rate.second > 0) { - caps = gst_caps_new_full(gst_structure_new("video/x-raw-yuv", - "width", G_TYPE_INT, resolution.width(), - "height", G_TYPE_INT, resolution.height(), - "framerate", GST_TYPE_FRACTION, rate.first, rate.second, - NULL), - gst_structure_new("video/x-raw-rgb", - "width", G_TYPE_INT, resolution.width(), - "height", G_TYPE_INT, resolution.height(), - "framerate", GST_TYPE_FRACTION, rate.first, rate.second, - NULL), NULL); - } else { - caps = gst_caps_new_full (gst_structure_new ("video/x-raw-yuv", - "width", G_TYPE_INT, resolution.width(), - "height", G_TYPE_INT, resolution.height(), - NULL), - gst_structure_new ("video/x-raw-rgb", - "width", G_TYPE_INT, resolution.width(), - "height", G_TYPE_INT, resolution.height(), NULL), NULL); - } - return caps; -} - -void CameraBinSession::setupCaptureResolution() -{ - if (m_captureMode == QCamera::CaptureStillImage) { - QSize resolution = m_imageEncodeControl->imageSettings().resolution(); - - //by default select the maximum supported resolution - if (resolution.isEmpty()) { - bool continuous = false; - QList<QSize> resolutions = supportedResolutions(qMakePair<int,int>(0,0), - &continuous, - QCamera::CaptureStillImage); - if (!resolutions.isEmpty()) - resolution = resolutions.last(); - } - - QSize viewfinderResolution = VIEWFINDER_RESOLUTION_4x3; - - if (!resolution.isEmpty()) { - GstCaps *caps = resolutionToCaps(resolution); -#if CAMERABIN_DEBUG - qDebug() << Q_FUNC_INFO << "set image resolution" << resolution << gst_caps_to_string(caps); -#endif - g_object_set(m_camerabin, "image-capture-caps", caps, NULL); - gst_caps_unref(caps); - - if (!resolution.isEmpty()) { - qreal aspectRatio = qreal(resolution.width()) / resolution.height(); - if (aspectRatio < 1.4) - viewfinderResolution = VIEWFINDER_RESOLUTION_4x3; - else if (aspectRatio > 1.7) - viewfinderResolution = VIEWFINDER_RESOLUTION_16x9; - else - viewfinderResolution = VIEWFINDER_RESOLUTION_3x2; - } - } - - //on low res cameras the viewfinder resolution should not be bigger - //then capture resolution - if (viewfinderResolution.width() > resolution.width() && !resolution.isEmpty()) - viewfinderResolution = resolution; - - GstCaps *viewfinderCaps = resolutionToCaps(viewfinderResolution); -#if CAMERABIN_DEBUG - qDebug() << "Set viewfinder resolution" << viewfinderResolution <<gst_caps_to_string(viewfinderCaps); -#endif - g_object_set(m_camerabin, "viewfinder-caps", viewfinderCaps, NULL); - gst_caps_unref(viewfinderCaps); - } - - if (m_captureMode == QCamera::CaptureVideo) { - QSize resolution = m_videoEncodeControl->videoSettings().resolution(); - //qreal framerate = m_videoEncodeControl->videoSettings().frameRate(); - - if (resolution.isEmpty()) { - //select the hightest supported resolution - bool continuous = false; - QList<QSize> resolutions = supportedResolutions(qMakePair<int,int>(0,0), - &continuous, - QCamera::CaptureVideo); - if (!resolutions.isEmpty()) - resolution = resolutions.last(); - } - - GstCaps *caps = resolutionToCaps(resolution /*, framerate*/); //convert to rational -#if CAMERABIN_DEBUG - qDebug() << Q_FUNC_INFO << "set video resolution" << resolution << gst_caps_to_string(caps); -#endif - - g_object_set(m_camerabin, "video-capture-caps", caps, NULL); - gst_caps_unref(caps); - } -} - -GstElement *CameraBinSession::buildCameraSource() -{ -#if CAMERABIN_DEBUG - qDebug() << Q_FUNC_INFO; -#endif - GstElement *videoSrc = 0; - if (m_videoInputFactory) { - videoSrc = m_videoInputFactory->buildElement(); - } else { - QList<QByteArray> candidates; - candidates << "wrappercamerabinsrc"; - QByteArray sourceElementName; - - foreach(sourceElementName, candidates) { - videoSrc = gst_element_factory_make(sourceElementName.constData(), "camera_source"); - if (videoSrc) - break; - } - - if (videoSrc && !m_inputDevice.isEmpty()) { -#if CAMERABIN_DEBUG - qDebug() << "set camera device" << m_inputDevice; -#endif - if (sourceElementName == "subdevsrc") { - if (m_inputDevice == QLatin1String("secondary")) - g_object_set(G_OBJECT(videoSrc), "camera-device", 1, NULL); - else - g_object_set(G_OBJECT(videoSrc), "camera-device", 0, NULL); - } else { - if (g_object_class_find_property(G_OBJECT_GET_CLASS(videoSrc), "device")) - g_object_set(G_OBJECT(videoSrc), - "device", - m_inputDevice.toLocal8Bit().constData(), - NULL); - } - } - } - - return videoSrc; -} - -void CameraBinSession::captureImage(int requestId, const QString &fileName) -{ - QString actualFileName = fileName; - if (actualFileName.isEmpty()) - actualFileName = generateFileName("img_", defaultDir(QCamera::CaptureStillImage), "jpg"); - - m_requestId = requestId; - -#if CAMERABIN_DEBUG - qDebug() << Q_FUNC_INFO << m_requestId << fileName << "actual file name:" << actualFileName; -#endif - - g_object_set(G_OBJECT(m_camerabin), FILENAME_PROPERTY, actualFileName.toLocal8Bit().constData(), NULL); - - g_signal_emit_by_name(G_OBJECT(m_camerabin), CAPTURE_START, NULL); - - m_imageFileName = actualFileName; -} - -void CameraBinSession::setCaptureMode(QCamera::CaptureMode mode) -{ - m_captureMode = mode; - - switch (m_captureMode) { - case QCamera::CaptureStillImage: - g_object_set(m_camerabin, MODE_PROPERTY, CAMERABIN_IMAGE_MODE, NULL); - break; - case QCamera::CaptureVideo: - g_object_set(m_camerabin, MODE_PROPERTY, CAMERABIN_VIDEO_MODE, NULL); - break; - } -} - -QUrl CameraBinSession::outputLocation() const -{ - //return the location service wrote data to, not one set by user, it can be empty. - return m_actualSink; -} - -bool CameraBinSession::setOutputLocation(const QUrl& sink) -{ - m_sink = m_actualSink = sink; - return true; -} - -QDir CameraBinSession::defaultDir(QCamera::CaptureMode mode) const -{ - QStringList dirCandidates; - -#if defined(Q_WS_MAEMO_6) - dirCandidates << QLatin1String("/home/user/MyDocs/DCIM"); - dirCandidates << QLatin1String("/home/user/MyDocs/"); -#endif - - if (mode == QCamera::CaptureVideo) { - dirCandidates << QDesktopServices::storageLocation(QDesktopServices::MoviesLocation); - dirCandidates << QDir::home().filePath("Documents/Video"); - dirCandidates << QDir::home().filePath("Documents/Videos"); - } else { - dirCandidates << QDesktopServices::storageLocation(QDesktopServices::PicturesLocation); - dirCandidates << QDir::home().filePath("Documents/Photo"); - dirCandidates << QDir::home().filePath("Documents/Photos"); - dirCandidates << QDir::home().filePath("Documents/photo"); - dirCandidates << QDir::home().filePath("Documents/photos"); - dirCandidates << QDir::home().filePath("Documents/Images"); - } - - dirCandidates << QDir::home().filePath("Documents"); - dirCandidates << QDir::home().filePath("My Documents"); - dirCandidates << QDir::homePath(); - dirCandidates << QDir::currentPath(); - dirCandidates << QDir::tempPath(); - - foreach (const QString &path, dirCandidates) { - if (QFileInfo(path).isWritable()) - return QDir(path); - } - - return QDir(); -} - -QString CameraBinSession::generateFileName(const QString &prefix, const QDir &dir, const QString &ext) const -{ - int lastClip = 0; - foreach(QString fileName, dir.entryList(QStringList() << QString("%1*.%2").arg(prefix).arg(ext))) { - int imgNumber = fileName.mid(prefix.length(), fileName.size()-prefix.length()-ext.length()-1).toInt(); - lastClip = qMax(lastClip, imgNumber); - } - - QString name = QString("%1%2.%3").arg(prefix) - .arg(lastClip+1, - 4, //fieldWidth - 10, - QLatin1Char('0')) - .arg(ext); - - return dir.absoluteFilePath(name); -} - -void CameraBinSession::setDevice(const QString &device) -{ - if (m_inputDevice != device) { - m_inputDevice = device; - m_videoInputHasChanged = true; - } -} - -void CameraBinSession::setAudioInput(QGstreamerElementFactory *audioInput) -{ - m_audioInputFactory = audioInput; -} - -void CameraBinSession::setVideoInput(QGstreamerElementFactory *videoInput) -{ - m_videoInputFactory = videoInput; - m_videoInputHasChanged = true; -} - -bool CameraBinSession::isReady() const -{ - //it's possible to use QCamera without any viewfinder attached - return !m_viewfinderInterface || m_viewfinderInterface->isReady(); -} - -void CameraBinSession::setViewfinder(QObject *viewfinder) -{ - if (m_viewfinderInterface) - m_viewfinderInterface->stopRenderer(); - - m_viewfinderInterface = qobject_cast<QGstreamerVideoRendererInterface*>(viewfinder); - if (!m_viewfinderInterface) - viewfinder = 0; - - if (m_viewfinder != viewfinder) { - bool oldReady = isReady(); - - if (m_viewfinder) { - disconnect(m_viewfinder, SIGNAL(sinkChanged()), - this, SLOT(handleViewfinderChange())); - disconnect(m_viewfinder, SIGNAL(readyChanged(bool)), - this, SIGNAL(readyChanged(bool))); - - m_busHelper->removeMessageFilter(m_viewfinder); - } - - m_viewfinder = viewfinder; - m_viewfinderHasChanged = true; - - if (m_viewfinder) { - connect(m_viewfinder, SIGNAL(sinkChanged()), - this, SLOT(handleViewfinderChange())); - connect(m_viewfinder, SIGNAL(readyChanged(bool)), - this, SIGNAL(readyChanged(bool))); - - m_busHelper->installMessageFilter(m_viewfinder); - } - - emit viewfinderChanged(); - if (oldReady != isReady()) - emit readyChanged(isReady()); - } -} - -void CameraBinSession::handleViewfinderChange() -{ - //the viewfinder will be reloaded - //shortly when the pipeline is started - m_viewfinderHasChanged = true; - emit viewfinderChanged(); -} - -QCamera::State CameraBinSession::state() const -{ - return m_state; -} - -void CameraBinSession::setState(QCamera::State newState) -{ - if (newState == m_pendingState) - return; - - m_pendingState = newState; - -#if CAMERABIN_DEBUG - qDebug() << Q_FUNC_INFO << newState; -#endif - - switch (newState) { - case QCamera::UnloadedState: - if (m_recordingActive) - stopVideoRecording(); - - if (m_viewfinderInterface) - m_viewfinderInterface->stopRenderer(); - - gst_element_set_state(m_camerabin, GST_STATE_NULL); - m_state = newState; - if (m_busy) - emit busyChanged(m_busy = false); - - emit stateChanged(m_state); - break; - case QCamera::LoadedState: - if (m_recordingActive) - stopVideoRecording(); - - if (m_videoInputHasChanged) { - if (m_viewfinderInterface) - m_viewfinderInterface->stopRenderer(); - - gst_element_set_state(m_camerabin, GST_STATE_NULL); - m_videoSrc = buildCameraSource(); - g_object_set(m_camerabin, CAMERA_SOURCE_PROPERTY, m_videoSrc, NULL); - m_videoInputHasChanged = false; - } -#ifdef USE_READY_STATE_ON_LOADED - gst_element_set_state(m_camerabin, GST_STATE_READY); -#else - m_state = QCamera::LoadedState; - if (m_viewfinderInterface) - m_viewfinderInterface->stopRenderer(); - gst_element_set_state(m_camerabin, GST_STATE_NULL); - emit stateChanged(m_state); -#endif - break; - case QCamera::ActiveState: - if (setupCameraBin()) { - GstState binState = GST_STATE_NULL; - GstState pending = GST_STATE_NULL; - gst_element_get_state(m_camerabin, &binState, &pending, 0); - - if (pending == GST_STATE_VOID_PENDING && binState == GST_STATE_READY) { - m_pendingResolutionUpdate = false; - setupCaptureResolution(); - gst_element_set_state(m_camerabin, GST_STATE_PLAYING); - } else { - m_pendingResolutionUpdate = true; - gst_element_set_state(m_camerabin, GST_STATE_READY); - } - } - } -} - -bool CameraBinSession::isBusy() const -{ - return m_busy; -} - -void CameraBinSession::updateBusyStatus(GObject *o, GParamSpec *p, gpointer d) -{ - Q_UNUSED(p); - CameraBinSession *session = reinterpret_cast<CameraBinSession *>(d); - - bool idle = false; - g_object_get(o, "idle", &idle, NULL); - bool busy = !idle; - - if (session->m_busy != busy) { - session->m_busy = busy; - QMetaObject::invokeMethod(session, "busyChanged", - Qt::QueuedConnection, - Q_ARG(bool, busy)); - } -} - -qint64 CameraBinSession::duration() const -{ - GstFormat format = GST_FORMAT_TIME; - gint64 duration = 0; - - if ( m_camerabin && gst_element_query_position(m_camerabin, &format, &duration)) - return duration / 1000000; - else - return 0; -} - -bool CameraBinSession::isMuted() const -{ - return m_muted; -} - -void CameraBinSession::setMuted(bool muted) -{ - if (m_muted != muted) { - m_muted = muted; - - if (m_camerabin) - g_object_set(G_OBJECT(m_camerabin), MUTE_PROPERTY, m_muted, NULL); - emit mutedChanged(m_muted); - } -} - -void CameraBinSession::setCaptureDevice(const QString &deviceName) -{ - m_captureDevice = deviceName; -} - -void CameraBinSession::setMetaData(const QMap<QByteArray, QVariant> &data) -{ - m_metaData = data; - - if (m_camerabin) { - GstIterator *elements = gst_bin_iterate_all_by_interface(GST_BIN(m_camerabin), GST_TYPE_TAG_SETTER); - GstElement *element = 0; - while (gst_iterator_next(elements, (void**)&element) == GST_ITERATOR_OK) { - QMapIterator<QByteArray, QVariant> it(data); - while (it.hasNext()) { - it.next(); - const QString tagName = it.key(); - const QVariant tagValue = it.value(); - - switch(tagValue.type()) { - case QVariant::String: - gst_tag_setter_add_tags(GST_TAG_SETTER(element), - GST_TAG_MERGE_REPLACE_ALL, - tagName.toUtf8().constData(), - tagValue.toString().toUtf8().constData(), - NULL); - break; - case QVariant::Int: - case QVariant::LongLong: - gst_tag_setter_add_tags(GST_TAG_SETTER(element), - GST_TAG_MERGE_REPLACE_ALL, - tagName.toUtf8().constData(), - tagValue.toInt(), - NULL); - break; - case QVariant::Double: - gst_tag_setter_add_tags(GST_TAG_SETTER(element), - GST_TAG_MERGE_REPLACE_ALL, - tagName.toUtf8().constData(), - tagValue.toDouble(), - NULL); - break; - default: - break; - } - } - } - } -} - -bool CameraBinSession::processSyncMessage(const QGstreamerMessage &message) -{ - GstMessage* gm = message.rawMessage(); - const GstStructure *st; - const GValue *image; - GstBuffer *buffer = NULL; - - if (gm && GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ELEMENT) { - if (m_captureMode == QCamera::CaptureStillImage && - gst_structure_has_name(gm->structure, "preview-image")) { - st = gst_message_get_structure(gm); - - if (gst_structure_has_field_typed(st, "buffer", GST_TYPE_BUFFER)) { - image = gst_structure_get_value(st, "buffer"); - if (image) { - buffer = gst_value_get_buffer(image); - - QImage img; - - GstCaps *caps = gst_buffer_get_caps(buffer); - if (caps) { - GstStructure *structure = gst_caps_get_structure(caps, 0); - gint width = 0; - gint height = 0; -#if CAMERABIN_DEBUG - qDebug() << "Preview caps:" << gst_structure_to_string(structure); -#endif - - if (structure && - gst_structure_get_int(structure, "width", &width) && - gst_structure_get_int(structure, "height", &height) && - width > 0 && height > 0) { - if (qstrcmp(gst_structure_get_name(structure), "video/x-raw-rgb") == 0) { - QImage::Format format = QImage::Format_Invalid; - int bpp = 0; - gst_structure_get_int(structure, "bpp", &bpp); - - if (bpp == 24) - format = QImage::Format_RGB888; - else if (bpp == 32) - format = QImage::Format_RGB32; - - if (format != QImage::Format_Invalid) { - img = QImage((const uchar *)buffer->data, width, height, format); - img.bits(); //detach - } - } - } - gst_caps_unref(caps); - - static int exposedSignalIndex = metaObject()->indexOfSignal("imageExposed(int)"); - metaObject()->method(exposedSignalIndex).invoke(this, - Qt::QueuedConnection, - Q_ARG(int,m_requestId)); - - static int signalIndex = metaObject()->indexOfSignal("imageCaptured(int,QImage)"); - metaObject()->method(signalIndex).invoke(this, - Qt::QueuedConnection, - Q_ARG(int,m_requestId), - Q_ARG(QImage,img)); - } - - } - return true; - } - } - - if (gst_structure_has_name(gm->structure, GST_PHOTOGRAPHY_AUTOFOCUS_DONE)) - m_cameraFocusControl->handleFocusMessage(gm); - } - - return false; -} - -bool CameraBinSession::processBusMessage(const QGstreamerMessage &message) -{ - GstMessage* gm = message.rawMessage(); - - if (gm) { - if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ERROR) { - GError *err; - gchar *debug; - gst_message_parse_error (gm, &err, &debug); - - QString message; - - if (err && err->message) { - message = QString::fromUtf8(err->message); - qWarning() << "CameraBin error:" << message; - } - - //only report error messager from camerabin - if (GST_MESSAGE_SRC(gm) == GST_OBJECT_CAST(m_camerabin)) { - if (message.isEmpty()) - message = tr("Camera error"); - - emit error(int(QMediaRecorder::ResourceError), message); - } - -#ifdef CAMERABIN_DEBUG_DUMP_BIN - _gst_debug_bin_to_dot_file_with_ts(GST_BIN(m_camerabin), - GstDebugGraphDetails(GST_DEBUG_GRAPH_SHOW_ALL /* GST_DEBUG_GRAPH_SHOW_MEDIA_TYPE | GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS | GST_DEBUG_GRAPH_SHOW_STATES*/), - "camerabin_error"); -#endif - - - if (err) - g_error_free (err); - - if (debug) - g_free (debug); - } - - if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_WARNING) { - GError *err; - gchar *debug; - gst_message_parse_warning (gm, &err, &debug); - - if (err && err->message) - qWarning() << "CameraBin warning:" << QString::fromUtf8(err->message); - - if (err) - g_error_free (err); - if (debug) - g_free (debug); - } - - if (GST_MESSAGE_SRC(gm) == GST_OBJECT_CAST(m_camerabin)) { - switch (GST_MESSAGE_TYPE(gm)) { - case GST_MESSAGE_DURATION: - break; - - case GST_MESSAGE_STATE_CHANGED: - { - - GstState oldState; - GstState newState; - GstState pending; - - gst_message_parse_state_changed(gm, &oldState, &newState, &pending); - - -#if CAMERABIN_DEBUG - QStringList states; - states << "GST_STATE_VOID_PENDING" << "GST_STATE_NULL" << "GST_STATE_READY" << "GST_STATE_PAUSED" << "GST_STATE_PLAYING"; - - - qDebug() << QString("state changed: old: %1 new: %2 pending: %3") \ - .arg(states[oldState]) \ - .arg(states[newState]) \ - .arg(states[pending]); -#endif - -#ifdef CAMERABIN_DEBUG_DUMP_BIN - _gst_debug_bin_to_dot_file_with_ts(GST_BIN(m_camerabin), - GstDebugGraphDetails(GST_DEBUG_GRAPH_SHOW_ALL /*GST_DEBUG_GRAPH_SHOW_MEDIA_TYPE | GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS | GST_DEBUG_GRAPH_SHOW_STATES*/), - "camerabin"); -#endif - - switch (newState) { - case GST_STATE_VOID_PENDING: - case GST_STATE_NULL: - if (m_state != QCamera::UnloadedState) - emit stateChanged(m_state = QCamera::UnloadedState); - break; - case GST_STATE_READY: - if (m_pendingResolutionUpdate) { - m_pendingResolutionUpdate = false; - setupCaptureResolution(); - gst_element_set_state(m_camerabin, GST_STATE_PLAYING); - } - if (m_state != QCamera::LoadedState) - emit stateChanged(m_state = QCamera::LoadedState); - break; - case GST_STATE_PAUSED: - case GST_STATE_PLAYING: - emit stateChanged(m_state = QCamera::ActiveState); - break; - } - } - break; - default: - break; - } - //qDebug() << "New session state:" << ENUM_NAME(CameraBinSession,"State",m_state); - } - } - - return false; -} - -void CameraBinSession::recordVideo() -{ - m_recordingActive = true; - m_actualSink = m_sink; - if (m_actualSink.isEmpty()) { - QString ext = m_mediaContainerControl->suggestedFileExtension(); - m_actualSink = generateFileName("clip_", defaultDir(QCamera::CaptureVideo), ext); - } - - g_object_set(G_OBJECT(m_camerabin), FILENAME_PROPERTY, m_actualSink.toEncoded().constData(), NULL); - - g_signal_emit_by_name(G_OBJECT(m_camerabin), CAPTURE_START, NULL); -} - -void CameraBinSession::stopVideoRecording() -{ - m_recordingActive = false; - g_signal_emit_by_name(G_OBJECT(m_camerabin), CAPTURE_STOP, NULL); -} - -//internal, only used by CameraBinSession::supportedFrameRates. -//recursively fills the list of framerates res from value data. -static void readValue(const GValue *value, QList< QPair<int,int> > *res, bool *continuous) -{ - if (GST_VALUE_HOLDS_FRACTION(value)) { - int num = gst_value_get_fraction_numerator(value); - int denum = gst_value_get_fraction_denominator(value); - - *res << QPair<int,int>(num, denum); - } else if (GST_VALUE_HOLDS_FRACTION_RANGE(value)) { - const GValue *rateValueMin = gst_value_get_fraction_range_min(value); - const GValue *rateValueMax = gst_value_get_fraction_range_max(value); - - if (continuous) - *continuous = true; - - readValue(rateValueMin, res, continuous); - readValue(rateValueMax, res, continuous); - } else if (GST_VALUE_HOLDS_LIST(value)) { - for (uint i=0; i<gst_value_list_get_size(value); i++) { - readValue(gst_value_list_get_value(value, i), res, continuous); - } - } -} - -static bool rateLessThan(const QPair<int,int> &r1, const QPair<int,int> &r2) -{ - return r1.first*r2.second < r2.first*r1.second; -} - -QList< QPair<int,int> > CameraBinSession::supportedFrameRates(const QSize &frameSize, bool *continuous) const -{ - QList< QPair<int,int> > res; - - GstCaps *supportedCaps = 0; - g_object_get(G_OBJECT(m_camerabin), - SUPPORTED_VIDEO_CAPTURE_CAPS_PROPERTY, - &supportedCaps, NULL); - - if (!supportedCaps) - return res; - - GstCaps *caps = 0; - - if (frameSize.isEmpty()) { - caps = gst_caps_copy(supportedCaps); - } else { - GstCaps *filter = gst_caps_new_full( - gst_structure_new( - "video/x-raw-rgb", - "width" , G_TYPE_INT , frameSize.width(), - "height" , G_TYPE_INT, frameSize.height(), NULL), - gst_structure_new( - "video/x-raw-yuv", - "width" , G_TYPE_INT, frameSize.width(), - "height" , G_TYPE_INT, frameSize.height(), NULL), - gst_structure_new( - "image/jpeg", - "width" , G_TYPE_INT, frameSize.width(), - "height" , G_TYPE_INT, frameSize.height(), NULL), - NULL); - - caps = gst_caps_intersect(supportedCaps, filter); - gst_caps_unref(filter); - } - gst_caps_unref(supportedCaps); - - //simplify to the list of rates only: - caps = gst_caps_make_writable(caps); - for (uint i=0; i<gst_caps_get_size(caps); i++) { - GstStructure *structure = gst_caps_get_structure(caps, i); - gst_structure_set_name(structure, "video/x-raw-yuv"); - const GValue *oldRate = gst_structure_get_value(structure, "framerate"); - GValue rate; - memset(&rate, 0, sizeof(rate)); - g_value_init(&rate, G_VALUE_TYPE(oldRate)); - g_value_copy(oldRate, &rate); - gst_structure_remove_all_fields(structure); - gst_structure_set_value(structure, "framerate", &rate); - } - gst_caps_do_simplify(caps); - - - for (uint i=0; i<gst_caps_get_size(caps); i++) { - GstStructure *structure = gst_caps_get_structure(caps, i); - const GValue *rateValue = gst_structure_get_value(structure, "framerate"); - readValue(rateValue, &res, continuous); - } - - qSort(res.begin(), res.end(), rateLessThan); - -#if CAMERABIN_DEBUG - qDebug() << "Supported rates:" << gst_caps_to_string(caps); - qDebug() << res; -#endif - - gst_caps_unref(caps); - - return res; -} - -//internal, only used by CameraBinSession::supportedResolutions -//recursively find the supported resolutions range. -static QPair<int,int> valueRange(const GValue *value, bool *continuous) -{ - int minValue = 0; - int maxValue = 0; - - if (g_value_type_compatible(G_VALUE_TYPE(value), G_TYPE_INT)) { - minValue = maxValue = g_value_get_int(value); - } else if (GST_VALUE_HOLDS_INT_RANGE(value)) { - minValue = gst_value_get_int_range_min(value); - maxValue = gst_value_get_int_range_max(value); - *continuous = true; - } else if (GST_VALUE_HOLDS_LIST(value)) { - for (uint i=0; i<gst_value_list_get_size(value); i++) { - QPair<int,int> res = valueRange(gst_value_list_get_value(value, i), continuous); - - if (res.first > 0 && minValue > 0) - minValue = qMin(minValue, res.first); - else //select non 0 valid value - minValue = qMax(minValue, res.first); - - maxValue = qMax(maxValue, res.second); - } - } - - return QPair<int,int>(minValue, maxValue); -} - -static bool resolutionLessThan(const QSize &r1, const QSize &r2) -{ - return r1.width()*r1.height() < r2.width()*r2.height(); -} - - -QList<QSize> CameraBinSession::supportedResolutions(QPair<int,int> rate, - bool *continuous, - QCamera::CaptureMode mode) const -{ - QList<QSize> res; - - if (continuous) - *continuous = false; - - GstCaps *supportedCaps = 0; - g_object_get(G_OBJECT(m_camerabin), - (mode == QCamera::CaptureStillImage) ? - SUPPORTED_IMAGE_CAPTURE_CAPS_PROPERTY : SUPPORTED_VIDEO_CAPTURE_CAPS_PROPERTY, - &supportedCaps, NULL); - - if (!supportedCaps) - return res; - -#if CAMERABIN_DEBUG - qDebug() << "Source caps:" << gst_caps_to_string(supportedCaps); -#endif - - GstCaps *caps = 0; - bool isContinuous = false; - - if (rate.first <= 0 || rate.second <= 0) { - caps = gst_caps_copy(supportedCaps); - } else { - GstCaps *filter = gst_caps_new_full( - gst_structure_new( - "video/x-raw-rgb", - "framerate" , GST_TYPE_FRACTION , rate.first, rate.second, NULL), - gst_structure_new( - "video/x-raw-yuv", - "framerate" , GST_TYPE_FRACTION , rate.first, rate.second, NULL), - gst_structure_new( - "image/jpeg", - "framerate" , GST_TYPE_FRACTION , rate.first, rate.second, NULL), - NULL); - - caps = gst_caps_intersect(supportedCaps, filter); - gst_caps_unref(filter); - } - gst_caps_unref(supportedCaps); - - //simplify to the list of resolutions only: - caps = gst_caps_make_writable(caps); - for (uint i=0; i<gst_caps_get_size(caps); i++) { - GstStructure *structure = gst_caps_get_structure(caps, i); - gst_structure_set_name(structure, "video/x-raw-yuv"); - const GValue *oldW = gst_structure_get_value(structure, "width"); - const GValue *oldH = gst_structure_get_value(structure, "height"); - GValue w; - memset(&w, 0, sizeof(GValue)); - GValue h; - memset(&h, 0, sizeof(GValue)); - g_value_init(&w, G_VALUE_TYPE(oldW)); - g_value_init(&h, G_VALUE_TYPE(oldH)); - g_value_copy(oldW, &w); - g_value_copy(oldH, &h); - gst_structure_remove_all_fields(structure); - gst_structure_set_value(structure, "width", &w); - gst_structure_set_value(structure, "height", &h); - } - gst_caps_do_simplify(caps); - - for (uint i=0; i<gst_caps_get_size(caps); i++) { - GstStructure *structure = gst_caps_get_structure(caps, i); - const GValue *wValue = gst_structure_get_value(structure, "width"); - const GValue *hValue = gst_structure_get_value(structure, "height"); - - QPair<int,int> wRange = valueRange(wValue, &isContinuous); - QPair<int,int> hRange = valueRange(hValue, &isContinuous); - - QSize minSize(wRange.first, hRange.first); - QSize maxSize(wRange.second, hRange.second); - - if (!minSize.isEmpty()) - res << minSize; - - if (minSize != maxSize && !maxSize.isEmpty()) - res << maxSize; - } - - - qSort(res.begin(), res.end(), resolutionLessThan); - - //if the range is continuos, populate is with the common rates - if (isContinuous && res.size() >= 2) { - //fill the ragne with common value - static QList<QSize> commonSizes = - QList<QSize>() << QSize(128, 96) - << QSize(160,120) - << QSize(176, 144) - << QSize(320, 240) - << QSize(352, 288) - << QSize(640, 480) - << QSize(848, 480) - << QSize(854, 480) - << QSize(1024, 768) - << QSize(1280, 720) // HD 720 - << QSize(1280, 1024) - << QSize(1600, 1200) - << QSize(1920, 1080) // HD - << QSize(1920, 1200) - << QSize(2048, 1536) - << QSize(2560, 1600) - << QSize(2580, 1936); - QSize minSize = res.first(); - QSize maxSize = res.last(); - res.clear(); - - foreach (const QSize &candidate, commonSizes) { - int w = candidate.width(); - int h = candidate.height(); - - if (w > maxSize.width() && h > maxSize.height()) - break; - - if (w >= minSize.width() && h >= minSize.height() && - w <= maxSize.width() && h <= maxSize.height()) - res << candidate; - } - - if (res.isEmpty() || res.first() != minSize) - res.prepend(minSize); - - if (res.last() != maxSize) - res.append(maxSize); - } - -#if CAMERABIN_DEBUG - qDebug() << "Supported resolutions:" << gst_caps_to_string(caps); - qDebug() << res; -#endif - - gst_caps_unref(caps); - - if (continuous) - *continuous = isContinuous; - - return res; -} diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.h b/src/plugins/gstreamer/camerabin/camerabinsession.h deleted file mode 100644 index fea1ad5..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinsession.h +++ /dev/null @@ -1,232 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef 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 QGstreamerBusMessageFilter, - public QGstreamerSyncMessageFilter -{ - Q_OBJECT - Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged) - Q_INTERFACES(QGstreamerBusMessageFilter QGstreamerSyncMessageFilter) -public: - enum CameraRole { - FrontCamera, // Secondary camera - BackCamera // Main photo camera - }; - - CameraBinSession(QObject *parent); - ~CameraBinSession(); - - GstPhotography *photography(); - GstElement *cameraBin() { return m_camerabin; } - QGstreamerBusHelper *bus() { return m_busHelper; } - - 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 stopVideoRecording(); - - bool isMuted() const; - - bool processSyncMessage(const QGstreamerMessage &message); - bool processBusMessage(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); - -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 handleViewfinderChange(); - -private: - bool setupCameraBin(); - void setupCaptureResolution(); - GstElement *buildCameraSource(); - 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_camerabin; - GstElement *m_videoSrc; - GstElement *m_viewfinderElement; - bool m_viewfinderHasChanged; - bool m_videoInputHasChanged; - - 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 diff --git a/src/plugins/gstreamer/camerabin/camerabinvideoencoder.cpp b/src/plugins/gstreamer/camerabin/camerabinvideoencoder.cpp deleted file mode 100644 index 1e49000..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinvideoencoder.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "camerabinvideoencoder.h" -#include "camerabinsession.h" -#include "camerabincontainer.h" - -#include <QtCore/qdebug.h> - -CameraBinVideoEncoder::CameraBinVideoEncoder(CameraBinSession *session) - :QVideoEncoderControl(session), - m_session(session), - m_codecs(QGstCodecsInfo::VideoEncoder) -{ -} - -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.supportedCodecs(); -} - -QString CameraBinVideoEncoder::videoCodecDescription(const QString &codecName) const -{ - return m_codecs.codecDescription(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; -} - - -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>(); -} - -GstEncodingProfile *CameraBinVideoEncoder::createProfile() -{ - QString codec = m_videoSettings.codec(); - GstCaps *caps; - - if (codec.isEmpty()) - caps = gst_caps_new_any(); - else - caps = gst_caps_from_string(codec.toLatin1()); - - return (GstEncodingProfile *)gst_encoding_video_profile_new( - caps, - NULL, //preset - NULL, //restriction - 0); //presence -} diff --git a/src/plugins/gstreamer/camerabin/camerabinvideoencoder.h b/src/plugins/gstreamer/camerabin/camerabinvideoencoder.h deleted file mode 100644 index 29fc595..0000000 --- a/src/plugins/gstreamer/camerabin/camerabinvideoencoder.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef 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> -#include <gst/pbutils/pbutils.h> -#include <gst/pbutils/encoding-profile.h> -#include "qgstcodecsinfo.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); - - void setActualVideoSettings(const QVideoEncoderSettings&); - void resetActualSettings(); - - GstEncodingProfile *createProfile(); - -Q_SIGNALS: - void settingsChanged(); - -private: - CameraBinSession *m_session; - - QGstCodecsInfo m_codecs; - QMap<QString,QStringList> m_codecOptions; - QMap<QString, QMap<QString, QVariant> > m_options; - - QVideoEncoderSettings m_videoSettings; // backend selected settings, using m_userSettings - QVideoEncoderSettings m_userSettings; -}; - -#endif diff --git a/src/plugins/gstreamer/camerabuttonlistener_meego.cpp b/src/plugins/gstreamer/camerabuttonlistener_meego.cpp deleted file mode 100644 index 5ee1daf..0000000 --- a/src/plugins/gstreamer/camerabuttonlistener_meego.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "camerabuttonlistener_meego.h" - -#include <QtWidgets/qapplication.h> -#include <QtGui/qevent.h> -#include <QtWidgets/qwidget.h> -#include <QtCore/qdebug.h> - -CameraButtonListener::CameraButtonListener(QObject *parent) : - QObject(parent), - m_focusPressed(false), - m_shutterPressed(false) -{ - m_keys = new MeeGo::QmKeys(this); - connect(m_keys, SIGNAL(keyEvent(MeeGo::QmKeys::Key, MeeGo::QmKeys::State)), - this, SLOT(handleQmKeyEvent(MeeGo::QmKeys::Key,MeeGo::QmKeys::State))); -} - -CameraButtonListener::~CameraButtonListener() -{ -} - -void CameraButtonListener::handleQmKeyEvent(MeeGo::QmKeys::Key key, MeeGo::QmKeys::State state) -{ - if (key == MeeGo::QmKeys::Camera) { - QWidget *window = QApplication::focusWidget(); - - bool focusPressed = (state == MeeGo::QmKeys::KeyHalfDown) || - (state == MeeGo::QmKeys::KeyDown); - - if (m_focusPressed != focusPressed) { - m_focusPressed = focusPressed; - if (window) { - QApplication::postEvent(window, - new QKeyEvent(focusPressed ? QEvent::KeyPress : QEvent::KeyRelease, - Qt::Key_CameraFocus, - Qt::NoModifier)); - } - } - - bool shutterPressed = (state == MeeGo::QmKeys::KeyDown); - if (m_shutterPressed != shutterPressed) { - m_shutterPressed = shutterPressed; - if (window) { - QApplication::postEvent(window, - new QKeyEvent(shutterPressed ? QEvent::KeyPress : QEvent::KeyRelease, - Qt::Key_Camera, - Qt::NoModifier)); - } - } - } -} diff --git a/src/plugins/gstreamer/camerabuttonlistener_meego.h b/src/plugins/gstreamer/camerabuttonlistener_meego.h deleted file mode 100644 index 5f13d07..0000000 --- a/src/plugins/gstreamer/camerabuttonlistener_meego.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef CAMERABUTTONLISTENER_MEEGO_H -#define CAMERABUTTONLISTENER_MEEGO_H - -#include <QtCore/qobject.h> -#include <qmsystem2/qmkeys.h> - -class CameraButtonListener : public QObject -{ - Q_OBJECT -public: - CameraButtonListener(QObject *parent = 0); - ~CameraButtonListener(); - -private slots: - void handleQmKeyEvent(MeeGo::QmKeys::Key key, MeeGo::QmKeys::State state); - -private: - MeeGo::QmKeys *m_keys; - bool m_focusPressed; - bool m_shutterPressed; -}; - -#endif // CAMERABUTTONLISTENER_MEEGO_H diff --git a/src/plugins/gstreamer/gstreamer.pro b/src/plugins/gstreamer/gstreamer.pro deleted file mode 100644 index 28becfb..0000000 --- a/src/plugins/gstreamer/gstreamer.pro +++ /dev/null @@ -1,94 +0,0 @@ - -load(qt_module) - -TARGET = qgstengine -QT += multimedia-private network multimediawidgets-private -PLUGIN_TYPE=mediaservice - -load(qt_plugin) -DESTDIR = $$QT.multimedia.plugins/$${PLUGIN_TYPE} - -LIBS += -lqgsttools_p - -unix:!maemo*:contains(QT_CONFIG, alsa) { -DEFINES += HAVE_ALSA -LIBS += \ - -lasound -} - -CONFIG += link_pkgconfig - -PKGCONFIG += \ - gstreamer-0.10 \ - gstreamer-base-0.10 \ - gstreamer-interfaces-0.10 \ - gstreamer-audio-0.10 \ - gstreamer-video-0.10 \ - gstreamer-pbutils-0.10 - -maemo*:PKGCONFIG +=gstreamer-plugins-bad-0.10 -contains(config_test_gstreamer_appsrc, yes): PKGCONFIG += gstreamer-app-0.10 - -contains(config_test_resourcepolicy, yes) { - DEFINES += HAVE_RESOURCE_POLICY - PKGCONFIG += libresourceqt1 -} - -maemo6 { - HEADERS += camerabuttonlistener_meego.h - SOURCES += camerabuttonlistener_meego.cpp - - PKGCONFIG += qmsystem2 - - isEqual(QT_ARCH,armv6) { - HEADERS += qgstreamergltexturerenderer.h - SOURCES += qgstreamergltexturerenderer.cpp - QT += opengl - LIBS += -lEGL -lgstmeegointerfaces-0.10 - } -} - -# Input -HEADERS += \ - qgstreamervideorendererinterface.h \ - qgstreamerserviceplugin.h \ - qgstreameraudioinputendpointselector.h \ - qgstreamervideorenderer.h \ - qgstreamervideoinputdevicecontrol.h \ - gstvideoconnector.h \ - qgstcodecsinfo.h \ - -SOURCES += \ - qgstreamervideorendererinterface.cpp \ - qgstreamerserviceplugin.cpp \ - qgstreameraudioinputendpointselector.cpp \ - qgstreamervideorenderer.cpp \ - qgstreamervideoinputdevicecontrol.cpp \ - qgstcodecsinfo.cpp \ - gstvideoconnector.c \ - - -!win32:!contains(QT_CONFIG,embedded):!mac:!simulator:!contains(QT_CONFIG, qpa) { - LIBS += -lXv -lX11 -lXext - - HEADERS += \ - qgstreamervideooverlay.h \ - qgstreamervideowindow.h \ - qgstreamervideowidget.h \ - qx11videosurface.h \ - - SOURCES += \ - qgstreamervideooverlay.cpp \ - qgstreamervideowindow.cpp \ - qgstreamervideowidget.cpp \ - qx11videosurface.cpp \ -} -include(mediaplayer/mediaplayer.pri) -include(mediacapture/mediacapture.pri) - -contains(config_test_gstreamer_photography, yes) { - include(camerabin/camerabin.pri) -} - -target.path += $$[QT_INSTALL_PLUGINS]/$${PLUGIN_TYPE} -INSTALLS += target diff --git a/src/plugins/gstreamer/gstvideoconnector.c b/src/plugins/gstreamer/gstvideoconnector.c deleted file mode 100644 index d5b56c7..0000000 --- a/src/plugins/gstreamer/gstvideoconnector.c +++ /dev/null @@ -1,425 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "gstvideoconnector.h" - -/* signals */ -enum -{ - SIGNAL_RESEND_NEW_SEGMENT, - SIGNAL_CONNECTION_FAILED, - LAST_SIGNAL -}; -static guint gst_video_connector_signals[LAST_SIGNAL] = { 0 }; - - -GST_DEBUG_CATEGORY_STATIC (video_connector_debug); -#define GST_CAT_DEFAULT video_connector_debug - -static GstStaticPadTemplate gst_video_connector_sink_factory = -GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS_ANY); - -static GstStaticPadTemplate gst_video_connector_src_factory = -GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS_ANY); - -#define _do_init(bla) \ - GST_DEBUG_CATEGORY_INIT (video_connector_debug, \ - "video-connector", 0, "An identity like element for reconnecting video stream"); - -GST_BOILERPLATE_FULL (GstVideoConnector, gst_video_connector, GstElement, - GST_TYPE_ELEMENT, _do_init); - -static void gst_video_connector_dispose (GObject * object); -static GstFlowReturn gst_video_connector_chain (GstPad * pad, GstBuffer * buf); -static GstFlowReturn gst_video_connector_buffer_alloc (GstPad * pad, - guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf); -static GstStateChangeReturn gst_video_connector_change_state (GstElement * - element, GstStateChange transition); -static gboolean gst_video_connector_handle_sink_event (GstPad * pad, - GstEvent * event); -static gboolean gst_video_connector_new_buffer_probe(GstObject *pad, GstBuffer *buffer, guint * object); -static void gst_video_connector_resend_new_segment(GstElement * element, gboolean emitFailedSignal); -static gboolean gst_video_connector_setcaps (GstPad *pad, GstCaps *caps); -static GstCaps *gst_video_connector_getcaps (GstPad * pad); -static gboolean gst_video_connector_acceptcaps (GstPad * pad, GstCaps * caps); - -static void -gst_video_connector_base_init (gpointer g_class) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - - gst_element_class_set_details_simple (element_class, "Video Connector", - "Generic", - "An identity like element used for reconnecting video stream", - "Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com>"); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_video_connector_sink_factory)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_video_connector_src_factory)); -} - -static void -gst_video_connector_class_init (GstVideoConnectorClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - gobject_class->dispose = gst_video_connector_dispose; - gstelement_class->change_state = gst_video_connector_change_state; - klass->resend_new_segment = gst_video_connector_resend_new_segment; - - gst_video_connector_signals[SIGNAL_RESEND_NEW_SEGMENT] = - g_signal_new ("resend-new-segment", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (GstVideoConnectorClass, resend_new_segment), NULL, NULL, - g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN); - - gst_video_connector_signals[SIGNAL_CONNECTION_FAILED] = - g_signal_new ("connection-failed", G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); -} - -static void -gst_video_connector_init (GstVideoConnector *element, - GstVideoConnectorClass *g_class) -{ - (void) g_class; - element->sinkpad = - gst_pad_new_from_static_template (&gst_video_connector_sink_factory, - "sink"); - gst_pad_set_chain_function(element->sinkpad, - GST_DEBUG_FUNCPTR (gst_video_connector_chain)); - gst_pad_set_event_function(element->sinkpad, - GST_DEBUG_FUNCPTR (gst_video_connector_handle_sink_event)); - gst_pad_set_bufferalloc_function(element->sinkpad, - GST_DEBUG_FUNCPTR (gst_video_connector_buffer_alloc)); - gst_pad_set_setcaps_function(element->sinkpad, - GST_DEBUG_FUNCPTR (gst_video_connector_setcaps)); - gst_pad_set_getcaps_function(element->sinkpad, - GST_DEBUG_FUNCPTR(gst_video_connector_getcaps)); - gst_pad_set_acceptcaps_function(element->sinkpad, - GST_DEBUG_FUNCPTR(gst_video_connector_acceptcaps)); - - gst_element_add_pad (GST_ELEMENT (element), element->sinkpad); - - element->srcpad = - gst_pad_new_from_static_template (&gst_video_connector_src_factory, - "src"); - gst_pad_add_buffer_probe(element->srcpad, - G_CALLBACK(gst_video_connector_new_buffer_probe), element); - gst_element_add_pad (GST_ELEMENT (element), element->srcpad); - - element->relinked = FALSE; - element->failedSignalEmited = FALSE; - gst_segment_init (&element->segment, GST_FORMAT_TIME); - element->latest_buffer = NULL; -} - -static void -gst_video_connector_reset (GstVideoConnector * element) -{ - element->relinked = FALSE; - element->failedSignalEmited = FALSE; - if (element->latest_buffer != NULL) { - gst_buffer_unref (element->latest_buffer); - element->latest_buffer = NULL; - } - gst_segment_init (&element->segment, GST_FORMAT_UNDEFINED); -} - -static void -gst_video_connector_dispose (GObject * object) -{ - GstVideoConnector *element = GST_VIDEO_CONNECTOR (object); - - gst_video_connector_reset (element); - - G_OBJECT_CLASS (parent_class)->dispose (object); -} - -static GstFlowReturn -gst_video_connector_buffer_alloc (GstPad * pad, guint64 offset, guint size, - GstCaps * caps, GstBuffer ** buf) -{ - GstVideoConnector *element; - GstFlowReturn res = GST_FLOW_OK; - element = GST_VIDEO_CONNECTOR (GST_PAD_PARENT (pad)); - - if (!buf) - return GST_FLOW_ERROR; - *buf = NULL; - - GST_OBJECT_LOCK (element); - gst_object_ref(element->srcpad); - GST_OBJECT_UNLOCK (element); - - res = gst_pad_alloc_buffer(element->srcpad, offset, size, caps, buf); - gst_object_unref (element->srcpad); - - GST_DEBUG_OBJECT (element, "buffer alloc finished: %s", gst_flow_get_name (res)); - - return res; -} - -static gboolean -gst_video_connector_setcaps (GstPad *pad, GstCaps *caps) -{ - GstVideoConnector *element; - element = GST_VIDEO_CONNECTOR (GST_PAD_PARENT (pad)); - - /* forward-negotiate */ - gboolean res = gst_pad_set_caps(element->srcpad, caps); - - GST_DEBUG_OBJECT(element, "gst_video_connector_setcaps %s %i", gst_caps_to_string(caps), res); - - if (!res) { - //if set_caps failed, emit "connection-failed" signal - //so colorspace transformation elemnt can be inserted - GST_INFO_OBJECT(element, "gst_video_connector_setcaps failed, emit connection-failed signal"); - g_signal_emit(G_OBJECT(element), gst_video_connector_signals[SIGNAL_CONNECTION_FAILED], 0); - - return gst_pad_set_caps(element->srcpad, caps); - } - - return TRUE; -} - -static GstCaps *gst_video_connector_getcaps (GstPad * pad) -{ - GstVideoConnector *element; - element = GST_VIDEO_CONNECTOR (GST_PAD_PARENT (pad)); - -#if (GST_VERSION_MICRO > 25) - GstCaps *caps = gst_pad_peer_get_caps_reffed(element->srcpad); -#else - GstCaps *caps = gst_pad_peer_get_caps(element->srcpad); -#endif - - if (!caps) - caps = gst_caps_new_any(); - - return caps; -} - -static gboolean gst_video_connector_acceptcaps (GstPad * pad, GstCaps * caps) -{ - GstVideoConnector *element; - element = GST_VIDEO_CONNECTOR (GST_PAD_PARENT (pad)); - - return gst_pad_peer_accept_caps(element->srcpad, caps); -} - -static void -gst_video_connector_resend_new_segment(GstElement * element, gboolean emitFailedSignal) -{ - GST_INFO_OBJECT(element, "New segment requested, failed signal enabled: %i", emitFailedSignal); - GstVideoConnector *connector = GST_VIDEO_CONNECTOR(element); - connector->relinked = TRUE; - if (emitFailedSignal) - connector->failedSignalEmited = FALSE; -} - - -static gboolean gst_video_connector_new_buffer_probe(GstObject *pad, GstBuffer *buffer, guint * object) -{ - (void) pad; - (void) buffer; - - GstVideoConnector *element = GST_VIDEO_CONNECTOR (object); - - /* - If relinking is requested, the current buffer should be rejected and - the new segment + previous buffer should be pushed first - */ - - if (element->relinked) - GST_LOG_OBJECT(element, "rejected buffer because of new segment request"); - - return !element->relinked; -} - - -static GstFlowReturn -gst_video_connector_chain (GstPad * pad, GstBuffer * buf) -{ - GstFlowReturn res; - GstVideoConnector *element; - - element = GST_VIDEO_CONNECTOR (gst_pad_get_parent (pad)); - - do { - /* - Resend the segment message and last buffer to preroll the new sink. - Sinks can be changed multiple times while paused, - while loop allows to send the segment message and preroll - all of them with the same buffer. - */ - while (element->relinked) { - element->relinked = FALSE; - - gint64 pos = element->segment.last_stop; - - if (element->latest_buffer && GST_BUFFER_TIMESTAMP_IS_VALID(element->latest_buffer)) { - pos = GST_BUFFER_TIMESTAMP (element->latest_buffer); - } - - //push a new segment and last buffer - GstEvent *ev = gst_event_new_new_segment (TRUE, - element->segment.rate, - element->segment.format, - pos, //start - element->segment.stop, - pos); - - GST_DEBUG_OBJECT (element, "Pushing new segment event"); - if (!gst_pad_push_event (element->srcpad, ev)) { - GST_WARNING_OBJECT (element, - "Newsegment handling failed in %" GST_PTR_FORMAT, - element->srcpad); - } - - if (element->latest_buffer) { - GST_DEBUG_OBJECT (element, "Pushing latest buffer..."); - gst_buffer_ref(element->latest_buffer); - gst_pad_push(element->srcpad, element->latest_buffer); - } - } - - gst_buffer_ref(buf); - - //it's possible video sink is changed during gst_pad_push blocked by - //pad lock, in this case ( element->relinked == TRUE ) - //the buffer should be rejected by the buffer probe and - //the new segment + prev buffer should be sent before - - GST_LOG_OBJECT (element, "Pushing buffer..."); - res = gst_pad_push (element->srcpad, buf); - GST_LOG_OBJECT (element, "Pushed buffer: %s", gst_flow_get_name (res)); - - //if gst_pad_push failed give the service another chance, - //it may still work with the colorspace element added - if (!element->failedSignalEmited && res == GST_FLOW_NOT_NEGOTIATED) { - element->failedSignalEmited = TRUE; - GST_INFO_OBJECT(element, "gst_pad_push failed, emit connection-failed signal"); - g_signal_emit(G_OBJECT(element), gst_video_connector_signals[SIGNAL_CONNECTION_FAILED], 0); - } - - } while (element->relinked); - - - if (element->latest_buffer) { - gst_buffer_unref (element->latest_buffer); - element->latest_buffer = NULL; - } - - //don't save the last video buffer on maemo6 because of buffers shortage - //with omapxvsink -#ifndef Q_WS_MAEMO_6 - element->latest_buffer = gst_buffer_ref(buf); -#endif - - gst_buffer_unref(buf); - gst_object_unref (element); - - return res; -} - -static GstStateChangeReturn -gst_video_connector_change_state (GstElement * element, - GstStateChange transition) -{ - GstVideoConnector *connector; - GstStateChangeReturn result; - - connector = GST_VIDEO_CONNECTOR(element); - result = GST_ELEMENT_CLASS (parent_class)->change_state(element, transition); - - switch (transition) { - case GST_STATE_CHANGE_PAUSED_TO_READY: - gst_video_connector_reset (connector); - break; - case GST_STATE_CHANGE_READY_TO_PAUSED: - connector->relinked = FALSE; - break; - default: - break; - } - - return result; -} - -static gboolean -gst_video_connector_handle_sink_event (GstPad * pad, GstEvent * event) -{ - if (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT) { - GstVideoConnector *element = GST_VIDEO_CONNECTOR (gst_pad_get_parent (pad)); - - gboolean update; - GstFormat format; - gdouble rate, arate; - gint64 start, stop, time; - - gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format, - &start, &stop, &time); - - GST_LOG_OBJECT (element, - "NEWSEGMENT update %d, rate %lf, applied rate %lf, " - "format %d, " "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %" - G_GINT64_FORMAT, update, rate, arate, format, start, stop, time); - - gst_segment_set_newsegment_full (&element->segment, update, - rate, arate, format, start, stop, time); - - gst_object_unref (element); - } - - return gst_pad_event_default (pad, event); -} diff --git a/src/plugins/gstreamer/gstvideoconnector.h b/src/plugins/gstreamer/gstvideoconnector.h deleted file mode 100644 index aa3d775..0000000 --- a/src/plugins/gstreamer/gstvideoconnector.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTVIDEOCONNECTOR_H -#define QGSTVIDEOCONNECTOR_H - -#include <gst/gst.h> - -G_BEGIN_DECLS - -#define GST_TYPE_VIDEO_CONNECTOR \ - (gst_video_connector_get_type()) -#define GST_VIDEO_CONNECTOR(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VIDEO_CONNECTOR, GstVideoConnector)) -#define GST_VIDEO_CONNECTOR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_VIDEO_CONNECTOR, GstVideoConnectorClass)) -#define GST_IS_VIDEO_CONNECTOR(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_VIDEO_CONNECTOR)) -#define GST_IS_VIDEO_CONNECTOR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_VIDEO_CONNECTOR)) - -typedef struct _GstVideoConnector GstVideoConnector; -typedef struct _GstVideoConnectorClass GstVideoConnectorClass; - -struct _GstVideoConnector { - GstElement element; - - GstPad *srcpad; - GstPad *sinkpad; - - gboolean relinked; - gboolean failedSignalEmited; - GstSegment segment; - GstBuffer *latest_buffer; -}; - -struct _GstVideoConnectorClass { - GstElementClass parent_class; - - /* action signal to resend new segment */ - void (*resend_new_segment) (GstElement * element, gboolean emitFailedSignal); -}; - -GType gst_video_connector_get_type (void); - -G_END_DECLS - -#endif - diff --git a/src/plugins/gstreamer/mediacapture/mediacapture.pri b/src/plugins/gstreamer/mediacapture/mediacapture.pri deleted file mode 100644 index b7f7794..0000000 --- a/src/plugins/gstreamer/mediacapture/mediacapture.pri +++ /dev/null @@ -1,27 +0,0 @@ -INCLUDEPATH += $$PWD - -DEFINES += QMEDIA_GSTREAMER_CAPTURE - -HEADERS += $$PWD/qgstreamercaptureservice.h \ - $$PWD/qgstreamercapturesession.h \ - $$PWD/qgstreameraudioencode.h \ - $$PWD/qgstreamervideoencode.h \ - $$PWD/qgstreamerrecordercontrol.h \ - $$PWD/qgstreamermediacontainercontrol.h \ - $$PWD/qgstreamercameracontrol.h \ - $$PWD/qgstreamerv4l2input.h \ - $$PWD/qgstreamercapturemetadatacontrol.h \ - $$PWD/qgstreamerimagecapturecontrol.h \ - $$PWD/qgstreamerimageencode.h - -SOURCES += $$PWD/qgstreamercaptureservice.cpp \ - $$PWD/qgstreamercapturesession.cpp \ - $$PWD/qgstreameraudioencode.cpp \ - $$PWD/qgstreamervideoencode.cpp \ - $$PWD/qgstreamerrecordercontrol.cpp \ - $$PWD/qgstreamermediacontainercontrol.cpp \ - $$PWD/qgstreamercameracontrol.cpp \ - $$PWD/qgstreamerv4l2input.cpp \ - $$PWD/qgstreamercapturemetadatacontrol.cpp \ - $$PWD/qgstreamerimagecapturecontrol.cpp \ - $$PWD/qgstreamerimageencode.cpp diff --git a/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.cpp b/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.cpp deleted file mode 100644 index 2f7c6a8..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.cpp +++ /dev/null @@ -1,290 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreameraudioencode.h" -#include "qgstreamercapturesession.h" -#include "qgstreamermediacontainercontrol.h" - -#include <QtCore/qdebug.h> - -#include <math.h> - -QGstreamerAudioEncode::QGstreamerAudioEncode(QObject *parent) - :QAudioEncoderControl(parent) -{ - QList<QByteArray> codecCandidates; - -#if defined(Q_WS_MAEMO_6) - codecCandidates << "audio/AAC" << "audio/mpeg" << "audio/vorbis" << "audio/speex" << "audio/GSM" - << "audio/PCM" << "audio/AMR" << "audio/AMR-WB" << "audio/FLAC"; -#else - codecCandidates << "audio/mpeg" << "audio/vorbis" << "audio/speex" << "audio/GSM" - << "audio/PCM" << "audio/AMR" << "audio/AMR-WB" << "audio/FLAC"; -#endif - -#if defined(Q_WS_MAEMO_6) - m_elementNames["audio/AMR"] = "nokiaamrnbenc"; - m_elementNames["audio/AMR-WB"] = "nokiaamrwbenc"; - m_elementNames["audio/AAC"] = "nokiaaacenc"; -#else - m_elementNames["audio/mpeg"] = "lamemp3enc"; - m_elementNames["audio/AMR"] = "amrnbenc"; - m_elementNames["audio/AMR-WB"] = "amrwbenc"; -#endif - - m_elementNames["audio/vorbis"] = "vorbisenc"; - m_elementNames["audio/speex"] = "speexenc"; - m_elementNames["audio/PCM"] = "audioresample"; - m_elementNames["audio/FLAC"] = "flacenc"; - m_elementNames["audio/GSM"] = "gsmenc"; - - 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(); - - 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, - QGstreamerMediaContainerControl::supportedStreamTypes(factory, GST_PAD_SRC)); - - gst_object_unref(GST_OBJECT(factory)); - } - } - - //if (!m_codecs.isEmpty()) - // m_audioSettings.setCodec(m_codecs[0]); -} - -QGstreamerAudioEncode::~QGstreamerAudioEncode() -{ -} - -QStringList QGstreamerAudioEncode::supportedAudioCodecs() const -{ - return m_codecs; -} - -QString QGstreamerAudioEncode::codecDescription(const QString &codecName) const -{ - return m_codecDescriptions.value(codecName); -} - -QStringList QGstreamerAudioEncode::supportedEncodingOptions(const QString &codec) const -{ - return m_codecOptions.value(codec); -} - -QVariant QGstreamerAudioEncode::encodingOption( - const QString &codec, const QString &name) const -{ - return m_options[codec].value(name); -} - -void QGstreamerAudioEncode::setEncodingOption( - const QString &codec, const QString &name, const QVariant &value) -{ - m_options[codec][name] = value; -} - -QList<int> QGstreamerAudioEncode::supportedSampleRates(const QAudioEncoderSettings &, bool *) const -{ - //TODO check element caps to find actual values - - return QList<int>(); -} - -QAudioEncoderSettings QGstreamerAudioEncode::audioSettings() const -{ - return m_audioSettings; -} - -void QGstreamerAudioEncode::setAudioSettings(const QAudioEncoderSettings &settings) -{ - m_audioSettings = settings; -} - - -GstElement *QGstreamerAudioEncode::createEncoder() -{ - QString codec = m_audioSettings.codec(); - GstElement *encoderElement = gst_element_factory_make(m_elementNames.value(codec).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); - - //qDebug() << "set caps filter:" << gst_caps_to_string(caps); - - g_object_set(G_OBJECT(capsFilter), "caps", caps, NULL); - } - - if (encoderElement) { - if (m_audioSettings.encodingMode() == QtMultimedia::ConstantQualityEncoding) { - QtMultimedia::EncodingQuality qualityValue = m_audioSettings.quality(); - - if (codec == QLatin1String("audio/vorbis")) { - double qualityTable[] = { - 0.1, //VeryLow - 0.3, //Low - 0.5, //Normal - 0.7, //High - 1.0 //VeryHigh - }; - g_object_set(G_OBJECT(encoderElement), "quality", qualityTable[qualityValue], NULL); - } else if (codec == QLatin1String("audio/mpeg")) { - g_object_set(G_OBJECT(encoderElement), "target", 0, NULL); //constant quality mode - qreal quality[] = { - 1, //VeryLow - 3, //Low - 5, //Normal - 7, //High - 9 //VeryHigh - }; - g_object_set(G_OBJECT(encoderElement), "quality", 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) { - if (codec == QLatin1String("audio/mpeg")) { - g_object_set(G_OBJECT(encoderElement), "target", 1, NULL); //constant bitrate mode - } - 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> QGstreamerAudioEncode::supportedStreamTypes(const QString &codecName) const -{ - return m_streamTypes.value(codecName); -} diff --git a/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.h b/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.h deleted file mode 100644 index 117aa6d..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.h +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERAUDIOENCODE_H -#define QGSTREAMERAUDIOENCODE_H - -#include <qaudioencodercontrol.h> -class QGstreamerCaptureSession; - -#include <QtCore/qstringlist.h> -#include <QtCore/qmap.h> -#include <QtCore/qset.h> - -#include <gst/gst.h> - -#include <qaudioformat.h> - -QT_USE_NAMESPACE - -class QGstreamerAudioEncode : public QAudioEncoderControl -{ - Q_OBJECT -public: - QGstreamerAudioEncode(QObject *parent); - virtual ~QGstreamerAudioEncode(); - - 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; - -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; -}; - -#endif diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercameracontrol.cpp b/src/plugins/gstreamer/mediacapture/qgstreamercameracontrol.cpp deleted file mode 100644 index 3f4592c..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamercameracontrol.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamercameracontrol.h" -#include "qgstreamerimageencode.h" - -#include <QtCore/qdebug.h> -#include <QtCore/qfile.h> - - -QGstreamerCameraControl::QGstreamerCameraControl(QGstreamerCaptureSession *session) - :QCameraControl(session), - m_captureMode(QCamera::CaptureStillImage), - m_session(session), - m_state(QCamera::UnloadedState), - m_status(QCamera::UnloadedStatus), - m_reloadPending(false) - -{ - connect(m_session, SIGNAL(stateChanged(QGstreamerCaptureSession::State)), - this, SLOT(updateStatus())); - - connect(m_session->imageEncodeControl(), SIGNAL(settingsChanged()), - SLOT(reloadLater())); - connect(m_session, SIGNAL(viewfinderChanged()), - SLOT(reloadLater())); - connect(m_session, SIGNAL(readyChanged(bool)), - SLOT(reloadLater())); -} - -QGstreamerCameraControl::~QGstreamerCameraControl() -{ -} - -void QGstreamerCameraControl::setCaptureMode(QCamera::CaptureMode mode) -{ - if (m_captureMode == mode) - return; - - switch (mode) { - case QCamera::CaptureStillImage: - m_session->setCaptureMode(QGstreamerCaptureSession::Image); - break; - case QCamera::CaptureVideo: - m_session->setCaptureMode(QGstreamerCaptureSession::AudioAndVideo); - break; - } - - emit captureModeChanged(mode); - updateStatus(); - reloadLater(); -} - -void QGstreamerCameraControl::setState(QCamera::State state) -{ - if (m_state == state) - return; - - m_state = state; - switch (state) { - case QCamera::UnloadedState: - case QCamera::LoadedState: - m_session->setState(QGstreamerCaptureSession::StoppedState); - break; - case QCamera::ActiveState: - //postpone changing to Active if the session is nor ready yet - if (m_session->isReady()) { - m_session->setState(QGstreamerCaptureSession::PreviewState); - } else { -#ifdef CAMEABIN_DEBUG - qDebug() << "Camera session is not ready yet, postpone activating"; -#endif - } - break; - default: - emit error(QCamera::NotSupportedFeatureError, tr("State not supported.")); - } - - updateStatus(); - emit stateChanged(m_state); -} - -QCamera::State QGstreamerCameraControl::state() const -{ - return m_state; -} - -void QGstreamerCameraControl::updateStatus() -{ - QCamera::Status oldStatus = m_status; - - switch (m_state) { - case QCamera::UnloadedState: - m_status = QCamera::UnloadedStatus; - break; - case QCamera::LoadedState: - m_status = QCamera::LoadedStatus; - break; - case QCamera::ActiveState: - if (m_session->state() == QGstreamerCaptureSession::StoppedState) - m_status = QCamera::StartingStatus; - else - m_status = QCamera::ActiveStatus; - break; - } - - if (oldStatus != m_status) { - //qDebug() << "Status changed:" << m_status; - emit statusChanged(m_status); - } -} - -void QGstreamerCameraControl::reloadLater() -{ - //qDebug() << "reload pipeline requested"; - if (!m_reloadPending && m_state == QCamera::ActiveState) { - m_reloadPending = true; - m_session->setState(QGstreamerCaptureSession::StoppedState); - QMetaObject::invokeMethod(this, "reloadPipeline", Qt::QueuedConnection); - } -} - -void QGstreamerCameraControl::reloadPipeline() -{ - //qDebug() << "reload pipeline"; - if (m_reloadPending) { - m_reloadPending = false; - if (m_state == QCamera::ActiveState && m_session->isReady()) { - m_session->setState(QGstreamerCaptureSession::PreviewState); - } - } -} - -bool QGstreamerCameraControl::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; - } -} diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercameracontrol.h b/src/plugins/gstreamer/mediacapture/qgstreamercameracontrol.h deleted file mode 100644 index 6e8fb0e..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamercameracontrol.h +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QGSTREAMERCAMERACONTROL_H -#define QGSTREAMERCAMERACONTROL_H - -#include <QHash> -#include <qcameracontrol.h> -#include "qgstreamercapturesession.h" - -QT_USE_NAMESPACE -QT_USE_NAMESPACE - -class QGstreamerCameraControl : public QCameraControl -{ - Q_OBJECT -public: - QGstreamerCameraControl( QGstreamerCaptureSession *session ); - virtual ~QGstreamerCameraControl(); - - 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 { return m_captureMode; } - void setCaptureMode(QCamera::CaptureMode mode); - - bool isCaptureModeSupported(QCamera::CaptureMode mode) const - { - return mode == QCamera::CaptureStillImage || mode == QCamera::CaptureVideo; - } - - QCamera::LockTypes supportedLocks() const - { - return QCamera::NoLock; - } - - bool canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const; - -public slots: - void reloadLater(); - -private slots: - void updateStatus(); - void reloadPipeline(); - - -private: - QCamera::CaptureMode m_captureMode; - QGstreamerCaptureSession *m_session; - QCamera::State m_state; - QCamera::Status m_status; - bool m_reloadPending; -}; - -#endif // QGSTREAMERCAMERACONTROL_H diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.cpp b/src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.cpp deleted file mode 100644 index b874afc..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamercapturemetadatacontrol.h" - -#include <gst/gst.h> -#include <gst/gstversion.h> - -struct QGstreamerMetaDataKeyLookup -{ - QtMultimedia::MetaData key; - const char *token; -}; - -static const QGstreamerMetaDataKeyLookup qt_gstreamerMetaDataKeys[] = -{ - { QtMultimedia::Title, GST_TAG_TITLE }, - //{ QtMultimedia::SubTitle, 0 }, - //{ QtMultimedia::Author, 0 }, - { QtMultimedia::Comment, GST_TAG_COMMENT }, - { QtMultimedia::Description, GST_TAG_DESCRIPTION }, - //{ QtMultimedia::Category, 0 }, - { QtMultimedia::Genre, GST_TAG_GENRE }, - //{ QtMultimedia::Year, 0 }, - //{ QtMultimedia::UserRating, 0 }, - - { QtMultimedia::Language, GST_TAG_LANGUAGE_CODE }, - - { QtMultimedia::Publisher, GST_TAG_ORGANIZATION }, - { QtMultimedia::Copyright, GST_TAG_COPYRIGHT }, - //{ QtMultimedia::ParentalRating, 0 }, - //{ QtMultimedia::RatingOrganisation, 0 }, - - // Media - //{ QtMultimedia::Size, 0 }, - //{ QtMultimedia::MediaType, 0 }, - { QtMultimedia::Duration, GST_TAG_DURATION }, - - // Audio - { QtMultimedia::AudioBitRate, GST_TAG_BITRATE }, - { QtMultimedia::AudioCodec, GST_TAG_AUDIO_CODEC }, - //{ QtMultimedia::ChannelCount, 0 }, - //{ QtMultimedia::SampleRate, 0 }, - - // Music - { QtMultimedia::AlbumTitle, GST_TAG_ALBUM }, - { QtMultimedia::AlbumArtist, GST_TAG_ARTIST}, - { QtMultimedia::ContributingArtist, GST_TAG_PERFORMER }, -#if (GST_VERSION_MAJOR >= 0) && (GST_VERSION_MINOR >= 10) && (GST_VERSION_MICRO >= 19) - { QtMultimedia::Composer, GST_TAG_COMPOSER }, -#endif - //{ QtMultimedia::Conductor, 0 }, - //{ QtMultimedia::Lyrics, 0 }, - //{ QtMultimedia::Mood, 0 }, - { QtMultimedia::TrackNumber, GST_TAG_TRACK_NUMBER }, - - //{ QtMultimedia::CoverArtUrlSmall, 0 }, - //{ QtMultimedia::CoverArtUrlLarge, 0 }, - - // Image/Video - //{ QtMultimedia::Resolution, 0 }, - //{ QtMultimedia::PixelAspectRatio, 0 }, - - // Video - //{ QtMultimedia::VideoFrameRate, 0 }, - //{ QtMultimedia::VideoBitRate, 0 }, - { QtMultimedia::VideoCodec, GST_TAG_VIDEO_CODEC }, - - //{ QtMultimedia::PosterUrl, 0 }, - - // Movie - //{ QtMultimedia::ChapterNumber, 0 }, - //{ QtMultimedia::Director, 0 }, - { QtMultimedia::LeadPerformer, GST_TAG_PERFORMER }, - //{ QtMultimedia::Writer, 0 }, - - // Photos - //{ QtMultimedia::CameraManufacturer, 0 }, - //{ QtMultimedia::CameraModel, 0 }, - //{ QtMultimedia::Event, 0 }, - //{ QtMultimedia::Subject, 0 } -}; - -QGstreamerCaptureMetaDataControl::QGstreamerCaptureMetaDataControl(QObject *parent) - :QMetaDataWriterControl(parent) -{ -} - -QVariant QGstreamerCaptureMetaDataControl::metaData(QtMultimedia::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 QGstreamerCaptureMetaDataControl::setMetaData(QtMultimedia::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<QtMultimedia::MetaData> QGstreamerCaptureMetaDataControl::availableMetaData() const -{ - static QMap<QByteArray, QtMultimedia::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<QtMultimedia::MetaData> res; - foreach (const QByteArray &key, m_values.keys()) { - QtMultimedia::MetaData tag = keysMap.value(key, QtMultimedia::MetaData(-1)); - if (tag != -1) - res.append(tag); - } - - return res; -} - -QVariant QGstreamerCaptureMetaDataControl::extendedMetaData(QString const &name) const -{ - return m_values.value(name.toLatin1()); -} - -void QGstreamerCaptureMetaDataControl::setExtendedMetaData(QString const &name, QVariant const &value) -{ - m_values.insert(name.toLatin1(), value); - emit QMetaDataWriterControl::metaDataChanged(); - emit metaDataChanged(m_values); -} - -QStringList QGstreamerCaptureMetaDataControl::availableExtendedMetaData() const -{ - QStringList res; - foreach (const QByteArray &key, m_values.keys()) - res.append(QString(key)); - - return res; -} diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.h b/src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.h deleted file mode 100644 index 031f630..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERCAPTUREMETADATACONTROL_H -#define QGSTREAMERCAPTUREMETADATACONTROL_H - -#include <qmetadatawritercontrol.h> - -QT_USE_NAMESPACE - -class QGstreamerCaptureMetaDataControl : public QMetaDataWriterControl -{ - Q_OBJECT -public: - QGstreamerCaptureMetaDataControl(QObject *parent); - virtual ~QGstreamerCaptureMetaDataControl() {}; - - - bool isMetaDataAvailable() const { return true; } - bool isWritable() const { return true; } - - QVariant metaData(QtMultimedia::MetaData key) const; - void setMetaData(QtMultimedia::MetaData key, const QVariant &value); - QList<QtMultimedia::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 // QGSTREAMERCAPTUREMETADATACONTROL_H diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.cpp b/src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.cpp deleted file mode 100644 index ee64b2c..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamercaptureservice.h" -#include "qgstreamercapturesession.h" -#include "qgstreamerrecordercontrol.h" -#include "qgstreamermediacontainercontrol.h" -#include "qgstreameraudioencode.h" -#include "qgstreamervideoencode.h" -#include "qgstreamerimageencode.h" -#include "qgstreamercameracontrol.h" -#include <private/qgstreamerbushelper_p.h> -#include "qgstreamerv4l2input.h" -#include "qgstreamercapturemetadatacontrol.h" - -#include "qgstreameraudioinputendpointselector.h" -#include "qgstreamervideoinputdevicecontrol.h" -#include "qgstreamerimagecapturecontrol.h" - -#include "qgstreamervideooverlay.h" -#include "qgstreamervideorenderer.h" - -#include "qgstreamervideowidget.h" - -#include <qmediaserviceprovider.h> - - -QGstreamerCaptureService::QGstreamerCaptureService(const QString &service, QObject *parent): - QMediaService(parent) -{ - m_captureSession = 0; - m_cameraControl = 0; - m_metaDataControl = 0; - - m_videoInput = 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_AUDIOSOURCE) { - m_captureSession = new QGstreamerCaptureSession(QGstreamerCaptureSession::Audio, this); - } - - if (service == Q_MEDIASERVICE_CAMERA) { - m_captureSession = new QGstreamerCaptureSession(QGstreamerCaptureSession::AudioAndVideo, this); - m_cameraControl = new QGstreamerCameraControl(m_captureSession); - m_videoInput = new QGstreamerV4L2Input(this); - m_captureSession->setVideoInput(m_videoInput); - m_videoInputDevice = new QGstreamerVideoInputDeviceControl(this); - - connect(m_videoInputDevice, SIGNAL(selectedDeviceChanged(QString)), - m_videoInput, SLOT(setDevice(QString))); - - if (m_videoInputDevice->deviceCount()) - m_videoInput->setDevice(m_videoInputDevice->deviceName(m_videoInputDevice->selectedDevice())); - - m_videoRenderer = new QGstreamerVideoRenderer(this); - -#if defined(Q_WS_X11) && !defined(QT_NO_XVIDEO) - m_videoWindow = new QGstreamerVideoOverlay(this); - m_videoWidgetControl = new QGstreamerVideoWidgetControl(this); -#endif - m_imageCaptureControl = new QGstreamerImageCaptureControl(m_captureSession); - } - - 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 QGstreamerCaptureMetaDataControl(this); - connect(m_metaDataControl, SIGNAL(metaDataChanged(QMap<QByteArray,QVariant>)), - m_captureSession, SLOT(setMetaData(QMap<QByteArray,QVariant>))); -} - -QGstreamerCaptureService::~QGstreamerCaptureService() -{ -} - -QMediaControl *QGstreamerCaptureService::requestControl(const char *name) -{ - if (!m_captureSession) - return 0; - - 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 (!m_videoOutput) { - if (qstrcmp(name, QVideoRendererControl_iid) == 0) { - m_videoOutput = m_videoRenderer; - } else if (qstrcmp(name, QVideoWindowControl_iid) == 0) { - m_videoOutput = m_videoWindow; - } else if (qstrcmp(name, QVideoWidgetControl_iid) == 0) { - m_videoOutput = m_videoWidgetControl; - } - - if (m_videoOutput) { - m_captureSession->setVideoPreview(m_videoOutput); - return m_videoOutput; - } - } - - return 0; -} - -void QGstreamerCaptureService::releaseControl(QMediaControl *control) -{ - if (control && control == m_videoOutput) { - m_videoOutput = 0; - m_captureSession->setVideoPreview(0); - } -} diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.h b/src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.h deleted file mode 100644 index 41ba4a9..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamercaptureservice.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERCAPTURESERVICE_H -#define QGSTREAMERCAPTURESERVICE_H - -#include <qmediaservice.h> -#include <qmediacontrol.h> - -#include <gst/gst.h> -QT_BEGIN_NAMESPACE -class QAudioEndpointSelector; -class QVideoDeviceControl; -QT_END_NAMESPACE - -class QGstreamerCaptureSession; -class QGstreamerCameraControl; -class QGstreamerMessage; -class QGstreamerBusHelper; -class QGstreamerVideoRenderer; -class QGstreamerVideoOverlay; -class QGstreamerVideoWidgetControl; -class QGstreamerElementFactory; -class QGstreamerCaptureMetaDataControl; -class QGstreamerImageCaptureControl; -class QGstreamerV4L2Input; - -class QGstreamerCaptureService : public QMediaService -{ - Q_OBJECT - -public: - QGstreamerCaptureService(const QString &service, QObject *parent = 0); - virtual ~QGstreamerCaptureService(); - - QMediaControl *requestControl(const char *name); - void releaseControl(QMediaControl *); - -private: - void setAudioPreview(GstElement*); - - QGstreamerCaptureSession *m_captureSession; - QGstreamerCameraControl *m_cameraControl; - QGstreamerV4L2Input *m_videoInput; - QGstreamerCaptureMetaDataControl *m_metaDataControl; - - QAudioEndpointSelector *m_audioInputEndpointSelector; - QVideoDeviceControl *m_videoInputDevice; - - QMediaControl *m_videoOutput; - - QGstreamerVideoRenderer *m_videoRenderer; - QMediaControl *m_videoWindow; - QMediaControl *m_videoWidgetControl; - QGstreamerImageCaptureControl *m_imageCaptureControl; -}; - -#endif // QGSTREAMERCAPTURESERVICE_H diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.cpp b/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.cpp deleted file mode 100644 index 8d87bb3..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.cpp +++ /dev/null @@ -1,1024 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamercapturesession.h" -#include "qgstreamerrecordercontrol.h" -#include "qgstreamermediacontainercontrol.h" -#include "qgstreamervideorendererinterface.h" -#include "qgstreameraudioencode.h" -#include "qgstreamervideoencode.h" -#include "qgstreamerimageencode.h" -#include <qmediarecorder.h> -#include <private/qgstreamerbushelper_p.h> - -#include <gst/gsttagsetter.h> -#include <gst/gstversion.h> - -#include <QtCore/qdebug.h> -#include <QtCore/qurl.h> -#include <QtCore/qset.h> -#include <QCoreApplication> -#include <QtCore/qmetaobject.h> -#include <QtCore/qfile.h> - -#include <QtGui/qimage.h> - -#define gstRef(element) { gst_object_ref(GST_OBJECT(element)); gst_object_sink(GST_OBJECT(element)); } -#define gstUnref(element) { if (element) { gst_object_unref(GST_OBJECT(element)); element = 0; } } - -QGstreamerCaptureSession::QGstreamerCaptureSession(QGstreamerCaptureSession::CaptureMode captureMode, QObject *parent) - :QObject(parent), - m_state(StoppedState), - m_pendingState(StoppedState), - m_waitingForEos(false), - m_pipelineMode(EmptyPipeline), - m_captureMode(captureMode), - m_audioInputFactory(0), - m_audioPreviewFactory(0), - m_videoInputFactory(0), - m_viewfinder(0), - m_viewfinderInterface(0), - m_audioSrc(0), - m_audioTee(0), - m_audioPreviewQueue(0), - m_audioPreview(0), - m_audioVolume(0), - m_muted(false), - m_videoSrc(0), - m_videoTee(0), - m_videoPreviewQueue(0), - m_videoPreview(0), - m_imageCaptureBin(0), - m_encodeBin(0), - m_passImage(false), - m_passPrerollImage(false) -{ - m_pipeline = gst_pipeline_new("media-capture-pipeline"); - gstRef(m_pipeline); - - m_bus = gst_element_get_bus(m_pipeline); - m_busHelper = new QGstreamerBusHelper(m_bus, this); - m_busHelper->installMessageFilter(this); - - m_audioEncodeControl = new QGstreamerAudioEncode(this); - m_videoEncodeControl = new QGstreamerVideoEncode(this); - m_imageEncodeControl = new QGstreamerImageEncode(this); - m_recorderControl = new QGstreamerRecorderControl(this); - m_mediaContainerControl = new QGstreamerMediaContainerControl(this); - - setState(StoppedState); -} - -QGstreamerCaptureSession::~QGstreamerCaptureSession() -{ - setState(StoppedState); - gst_element_set_state(m_pipeline, GST_STATE_NULL); - gst_object_unref(GST_OBJECT(m_pipeline)); -} - -void QGstreamerCaptureSession::setCaptureMode(CaptureMode mode) -{ - m_captureMode = mode; -} - -GstElement *QGstreamerCaptureSession::buildEncodeBin() -{ - GstElement *encodeBin = gst_bin_new("encode-bin"); - - GstElement *muxer = gst_element_factory_make( m_mediaContainerControl->formatElementName().constData(), "muxer"); - if (!muxer) { - qWarning() << "Could not create a media muxer element:" << m_mediaContainerControl->formatElementName(); - gst_object_unref(encodeBin); - return 0; - } - - GstElement *fileSink = gst_element_factory_make("filesink", "filesink"); - g_object_set(G_OBJECT(fileSink), "location", m_sink.toString().toLocal8Bit().constData(), NULL); - gst_bin_add_many(GST_BIN(encodeBin), muxer, fileSink, NULL); - - if (!gst_element_link(muxer, fileSink)) { - gst_object_unref(encodeBin); - return 0; - } - - if (m_captureMode & Audio) { - GstElement *audioConvert = gst_element_factory_make("audioconvert", "audioconvert"); - GstElement *audioQueue = gst_element_factory_make("queue", "audio-encode-queue"); - m_audioVolume = gst_element_factory_make("volume", "volume"); - gst_bin_add_many(GST_BIN(encodeBin), audioConvert, audioQueue, m_audioVolume, NULL); - - GstElement *audioEncoder = m_audioEncodeControl->createEncoder(); - if (!audioEncoder) { - gst_object_unref(encodeBin); - qWarning() << "Could not create an audio encoder element:" << m_audioEncodeControl->audioSettings().codec(); - return 0; - } - - gst_bin_add(GST_BIN(encodeBin), audioEncoder); - - if (!gst_element_link_many(audioConvert, audioQueue, m_audioVolume, audioEncoder, muxer, NULL)) { - gst_object_unref(encodeBin); - return 0; - } - - g_object_set(G_OBJECT(m_audioVolume), "volume", (m_muted ? 0.0 : 1.0), NULL); - - // add ghostpads - GstPad *pad = gst_element_get_static_pad(audioConvert, "sink"); - gst_element_add_pad(GST_ELEMENT(encodeBin), gst_ghost_pad_new("audiosink", pad)); - gst_object_unref(GST_OBJECT(pad)); - } - - if (m_captureMode & Video) { - GstElement *videoQueue = gst_element_factory_make("queue", "video-encode-queue"); - GstElement *colorspace = gst_element_factory_make("ffmpegcolorspace", "ffmpegcolorspace-encoder"); - GstElement *videoscale = gst_element_factory_make("videoscale","videoscale-encoder"); - gst_bin_add_many(GST_BIN(encodeBin), videoQueue, colorspace, videoscale, NULL); - - GstElement *videoEncoder = m_videoEncodeControl->createEncoder(); - if (!videoEncoder) { - gst_object_unref(encodeBin); - qWarning() << "Could not create a video encoder element:" << m_videoEncodeControl->videoSettings().codec(); - return 0; - } - - gst_bin_add(GST_BIN(encodeBin), videoEncoder); - - if (!gst_element_link_many(videoQueue, colorspace, videoscale, videoEncoder, muxer, NULL)) { - gst_object_unref(encodeBin); - return 0; - } - - // add ghostpads - GstPad *pad = gst_element_get_static_pad(videoQueue, "sink"); - gst_element_add_pad(GST_ELEMENT(encodeBin), gst_ghost_pad_new("videosink", pad)); - gst_object_unref(GST_OBJECT(pad)); - } - - return encodeBin; -} - -GstElement *QGstreamerCaptureSession::buildAudioSrc() -{ - GstElement *audioSrc = 0; - if (m_audioInputFactory) - audioSrc = m_audioInputFactory->buildElement(); - else { - audioSrc = gst_element_factory_make("pulsesrc", "audio_src"); - QString elementName = "alsasrc"; - QString device; - - if (m_captureDevice.startsWith("alsa:")) { - device = m_captureDevice.mid(QString("alsa:").length()); - } else if (m_captureDevice.startsWith("oss:")) { - elementName = "osssrc"; - device = m_captureDevice.mid(QString("oss:").length()); - } else if (m_captureDevice.startsWith("pulseaudio:")) { - elementName = "pulsesrc"; - } else { - elementName = "autoaudiosrc"; - } - - audioSrc = gst_element_factory_make(elementName.toAscii().constData(), "audio_src"); - if (audioSrc && !device.isEmpty()) - g_object_set(G_OBJECT(audioSrc), "device", device.toLocal8Bit().constData(), NULL); - } - - if (!audioSrc) { - emit error(int(QMediaRecorder::ResourceError), tr("Could not create an audio source element")); - audioSrc = gst_element_factory_make("fakesrc", NULL); - } - - return audioSrc; -} - -GstElement *QGstreamerCaptureSession::buildAudioPreview() -{ - GstElement *previewElement = 0; - - if (m_audioPreviewFactory) { - previewElement = m_audioPreviewFactory->buildElement(); - } else { - - -#if 1 - previewElement = gst_element_factory_make("fakesink", "audio-preview"); -#else - GstElement *bin = gst_bin_new("audio-preview-bin"); - GstElement *visual = gst_element_factory_make("libvisual_lv_scope", "audio-preview"); - GstElement *sink = gst_element_factory_make("ximagesink", NULL); - gst_bin_add_many(GST_BIN(bin), visual, sink, NULL); - gst_element_link_many(visual,sink, NULL); - - - // add ghostpads - GstPad *pad = gst_element_get_static_pad(visual, "sink"); - Q_ASSERT(pad); - gst_element_add_pad(GST_ELEMENT(bin), gst_ghost_pad_new("audiosink", pad)); - gst_object_unref(GST_OBJECT(pad)); - - previewElement = bin; -#endif - } - - return previewElement; -} - -GstElement *QGstreamerCaptureSession::buildVideoSrc() -{ - GstElement *videoSrc = 0; - if (m_videoInputFactory) { - videoSrc = m_videoInputFactory->buildElement(); - } else { - videoSrc = gst_element_factory_make("videotestsrc", "video_test_src"); - //videoSrc = gst_element_factory_make("v4l2src", "video_test_src"); - } - - return videoSrc; -} - -GstElement *QGstreamerCaptureSession::buildVideoPreview() -{ - GstElement *previewElement = 0; - - if (m_viewfinderInterface) { - GstElement *bin = gst_bin_new("video-preview-bin"); - GstElement *colorspace = gst_element_factory_make("ffmpegcolorspace", "ffmpegcolorspace-preview"); - GstElement *capsFilter = gst_element_factory_make("capsfilter", "capsfilter-video-preview"); - GstElement *preview = m_viewfinderInterface->videoSink(); - - gst_bin_add_many(GST_BIN(bin), colorspace, capsFilter, preview, NULL); - gst_element_link(colorspace,capsFilter); - gst_element_link(capsFilter,preview); - - QSize resolution; - qreal frameRate = 0; - - if (m_captureMode & Video) { - QVideoEncoderSettings videoSettings = m_videoEncodeControl->videoSettings(); - resolution = videoSettings.resolution(); - frameRate = videoSettings.frameRate(); - } else if (m_captureMode & Image) { - resolution = m_imageEncodeControl->imageSettings().resolution(); - } - - if (!resolution.isEmpty() || frameRate > 0.001) { - GstCaps *caps = gst_caps_new_empty(); - QStringList structureTypes; - structureTypes << "video/x-raw-yuv" << "video/x-raw-rgb"; - - foreach(const QString &structureType, structureTypes) { - GstStructure *structure = gst_structure_new(structureType.toAscii().constData(), NULL); - - if (!resolution.isEmpty()) { - gst_structure_set(structure, "width", G_TYPE_INT, resolution.width(), NULL); - gst_structure_set(structure, "height", G_TYPE_INT, resolution.height(), NULL); - } - - if (frameRate > 0.001) { - QPair<int,int> rate = m_videoEncodeControl->rateAsRational(); - - //qDebug() << "frame rate:" << num << denum; - - gst_structure_set(structure, "framerate", GST_TYPE_FRACTION, rate.first, rate.second, NULL); - } - - gst_caps_append_structure(caps,structure); - } - - //qDebug() << "set video preview caps filter:" << gst_caps_to_string(caps); - - g_object_set(G_OBJECT(capsFilter), "caps", caps, NULL); - - } - - // add ghostpads - GstPad *pad = gst_element_get_static_pad(colorspace, "sink"); - Q_ASSERT(pad); - gst_element_add_pad(GST_ELEMENT(bin), gst_ghost_pad_new("videosink", pad)); - gst_object_unref(GST_OBJECT(pad)); - - previewElement = bin; - } else { -#if 1 - previewElement = gst_element_factory_make("fakesink", "video-preview"); -#else - GstElement *bin = gst_bin_new("video-preview-bin"); - GstElement *colorspace = gst_element_factory_make("ffmpegcolorspace", "ffmpegcolorspace-preview"); - GstElement *preview = gst_element_factory_make("ximagesink", "video-preview"); - gst_bin_add_many(GST_BIN(bin), colorspace, preview, NULL); - gst_element_link(colorspace,preview); - - // add ghostpads - GstPad *pad = gst_element_get_static_pad(colorspace, "sink"); - Q_ASSERT(pad); - gst_element_add_pad(GST_ELEMENT(bin), gst_ghost_pad_new("videosink", pad)); - gst_object_unref(GST_OBJECT(pad)); - - previewElement = bin; -#endif - } - - return previewElement; -} - - -static gboolean passImageFilter(GstElement *element, - GstBuffer *buffer, - void *appdata) -{ - Q_UNUSED(element); - Q_UNUSED(buffer); - - QGstreamerCaptureSession *session = (QGstreamerCaptureSession *)appdata; - if (session->m_passImage || session->m_passPrerollImage) { - session->m_passImage = false; - - if (session->m_passPrerollImage) { - session->m_passPrerollImage = false; - return TRUE; - } - session->m_passPrerollImage = false; - - QImage img; - - GstCaps *caps = gst_buffer_get_caps(buffer); - if (caps) { - GstStructure *structure = gst_caps_get_structure (caps, 0); - gint width = 0; - gint height = 0; - - if (structure && - gst_structure_get_int(structure, "width", &width) && - gst_structure_get_int(structure, "height", &height) && - width > 0 && height > 0) { - if (qstrcmp(gst_structure_get_name(structure), "video/x-raw-yuv") == 0) { - guint32 fourcc = 0; - gst_structure_get_fourcc(structure, "format", &fourcc); - - if (fourcc == GST_MAKE_FOURCC('I','4','2','0')) { - img = QImage(width/2, height/2, QImage::Format_RGB32); - - const uchar *data = (const uchar *)buffer->data; - - for (int y=0; y<height; y+=2) { - const uchar *yLine = data + y*width; - const uchar *uLine = data + width*height + y*width/4; - const uchar *vLine = data + width*height*5/4 + y*width/4; - - for (int x=0; x<width; x+=2) { - const qreal Y = 1.164*(yLine[x]-16); - const int U = uLine[x/2]-128; - const int V = vLine[x/2]-128; - - int b = qBound(0, int(Y + 2.018*U), 255); - int g = qBound(0, int(Y - 0.813*V - 0.391*U), 255); - int r = qBound(0, int(Y + 1.596*V), 255); - - img.setPixel(x/2,y/2,qRgb(r,g,b)); - } - } - } - - } else if (qstrcmp(gst_structure_get_name(structure), "video/x-raw-rgb") == 0) { - QImage::Format format = QImage::Format_Invalid; - int bpp = 0; - gst_structure_get_int(structure, "bpp", &bpp); - - if (bpp == 24) - format = QImage::Format_RGB888; - else if (bpp == 32) - format = QImage::Format_RGB32; - - if (format != QImage::Format_Invalid) { - img = QImage((const uchar *)buffer->data, - width, - height, - format); - img.bits(); //detach - } - } - } - gst_caps_unref(caps); - } - - static int exposedSignalIndex = session->metaObject()->indexOfSignal("imageExposed(int)"); - session->metaObject()->method(exposedSignalIndex).invoke(session, - Qt::QueuedConnection, - Q_ARG(int,session->m_imageRequestId)); - - static int capturedSignalIndex = session->metaObject()->indexOfSignal("imageCaptured(int,QImage)"); - session->metaObject()->method(capturedSignalIndex).invoke(session, - Qt::QueuedConnection, - Q_ARG(int,session->m_imageRequestId), - Q_ARG(QImage,img)); - - return TRUE; - } else { - return FALSE; - } -} - -static gboolean saveImageFilter(GstElement *element, - GstBuffer *buffer, - GstPad *pad, - void *appdata) -{ - Q_UNUSED(element); - Q_UNUSED(pad); - QGstreamerCaptureSession *session = (QGstreamerCaptureSession *)appdata; - - QString fileName = session->m_imageFileName; - - if (!fileName.isEmpty()) { - QFile f(fileName); - if (f.open(QFile::WriteOnly)) { - f.write((const char *)buffer->data, buffer->size); - f.close(); - - static int signalIndex = session->metaObject()->indexOfSignal("imageSaved(int,QString)"); - session->metaObject()->method(signalIndex).invoke(session, - Qt::QueuedConnection, - Q_ARG(int,session->m_imageRequestId), - Q_ARG(QString,fileName)); - } - } - - return TRUE; -} - -GstElement *QGstreamerCaptureSession::buildImageCapture() -{ - GstElement *bin = gst_bin_new("image-capture-bin"); - GstElement *queue = gst_element_factory_make("queue", "queue-image-capture"); - GstElement *colorspace = gst_element_factory_make("ffmpegcolorspace", "ffmpegcolorspace-image-capture"); - GstElement *encoder = gst_element_factory_make("jpegenc", "image-encoder"); - GstElement *sink = gst_element_factory_make("fakesink","sink-image-capture"); - - GstPad *pad = gst_element_get_static_pad(queue, "src"); - Q_ASSERT(pad); - gst_pad_add_buffer_probe(pad, G_CALLBACK(passImageFilter), this); - - g_object_set(G_OBJECT(sink), "signal-handoffs", TRUE, NULL); - g_signal_connect(G_OBJECT(sink), "handoff", - G_CALLBACK(saveImageFilter), this); - - gst_bin_add_many(GST_BIN(bin), queue, colorspace, encoder, sink, NULL); - gst_element_link_many(queue, colorspace, encoder, sink, NULL); - - // add ghostpads - pad = gst_element_get_static_pad(queue, "sink"); - Q_ASSERT(pad); - gst_element_add_pad(GST_ELEMENT(bin), gst_ghost_pad_new("imagesink", pad)); - gst_object_unref(GST_OBJECT(pad)); - - m_passImage = false; - m_passPrerollImage = true; - m_imageFileName = QString(); - - return bin; -} - -void QGstreamerCaptureSession::captureImage(int requestId, const QString &fileName) -{ - m_imageRequestId = requestId; - m_imageFileName = fileName; - m_passImage = true; -} - - -#define REMOVE_ELEMENT(element) { if (element) {gst_bin_remove(GST_BIN(m_pipeline), element); element = 0;} } - -bool QGstreamerCaptureSession::rebuildGraph(QGstreamerCaptureSession::PipelineMode newMode) -{ - REMOVE_ELEMENT(m_audioSrc); - REMOVE_ELEMENT(m_audioPreview); - REMOVE_ELEMENT(m_audioPreviewQueue); - REMOVE_ELEMENT(m_audioTee); - REMOVE_ELEMENT(m_videoSrc); - REMOVE_ELEMENT(m_videoPreview); - REMOVE_ELEMENT(m_videoPreviewQueue); - REMOVE_ELEMENT(m_videoTee); - REMOVE_ELEMENT(m_encodeBin); - REMOVE_ELEMENT(m_imageCaptureBin); - m_audioVolume = 0; - - bool ok = true; - - switch (newMode) { - case EmptyPipeline: - break; - case PreviewPipeline: - if (m_captureMode & Audio) { - m_audioSrc = buildAudioSrc(); - m_audioPreview = buildAudioPreview(); - - ok &= m_audioSrc && m_audioPreview; - - if (ok) { - gst_bin_add_many(GST_BIN(m_pipeline), m_audioSrc, m_audioPreview, NULL); - ok &= gst_element_link(m_audioSrc, m_audioPreview); - } - } - if (m_captureMode & Video || m_captureMode & Image) { - m_videoSrc = buildVideoSrc(); - m_videoTee = gst_element_factory_make("tee", "video-preview-tee"); - m_videoPreviewQueue = gst_element_factory_make("queue", "video-preview-queue"); - m_videoPreview = buildVideoPreview(); - m_imageCaptureBin = buildImageCapture(); - - ok &= m_videoSrc && m_videoTee && m_videoPreviewQueue && m_videoPreview && m_imageCaptureBin; - - if (ok) { - gst_bin_add_many(GST_BIN(m_pipeline), m_videoSrc, m_videoTee, - m_videoPreviewQueue, m_videoPreview, - m_imageCaptureBin, NULL); - - ok &= gst_element_link(m_videoSrc, m_videoTee); - ok &= gst_element_link(m_videoTee, m_videoPreviewQueue); - ok &= gst_element_link(m_videoPreviewQueue, m_videoPreview); - ok &= gst_element_link(m_videoTee, m_imageCaptureBin); - } - } - break; - case RecordingPipeline: - m_encodeBin = buildEncodeBin(); - gst_bin_add(GST_BIN(m_pipeline), m_encodeBin); - - if (m_captureMode & Audio) { - m_audioSrc = buildAudioSrc(); - ok &= m_audioSrc != 0; - - gst_bin_add(GST_BIN(m_pipeline), m_audioSrc); - ok &= gst_element_link(m_audioSrc, m_encodeBin); - } - - if (m_captureMode & Video) { - m_videoSrc = buildVideoSrc(); - ok &= m_videoSrc != 0; - - gst_bin_add(GST_BIN(m_pipeline), m_videoSrc); - ok &= gst_element_link(m_videoSrc, m_encodeBin); - } - - if (!m_metaData.isEmpty()) - setMetaData(m_metaData); - - break; - case PreviewAndRecordingPipeline: - m_encodeBin = buildEncodeBin(); - if (m_encodeBin) - gst_bin_add(GST_BIN(m_pipeline), m_encodeBin); - - ok &= m_encodeBin != 0; - - if (ok && m_captureMode & Audio) { - m_audioSrc = buildAudioSrc(); - m_audioPreview = buildAudioPreview(); - m_audioTee = gst_element_factory_make("tee", NULL); - m_audioPreviewQueue = gst_element_factory_make("queue", NULL); - - ok &= m_audioSrc && m_audioPreview && m_audioTee && m_audioPreviewQueue; - - if (ok) { - gst_bin_add_many(GST_BIN(m_pipeline), m_audioSrc, m_audioTee, - m_audioPreviewQueue, m_audioPreview, NULL); - ok &= gst_element_link(m_audioSrc, m_audioTee); - ok &= gst_element_link(m_audioTee, m_audioPreviewQueue); - ok &= gst_element_link(m_audioPreviewQueue, m_audioPreview); - ok &= gst_element_link(m_audioTee, m_encodeBin); - } - } - - if (ok && (m_captureMode & Video || m_captureMode & Image)) { - m_videoSrc = buildVideoSrc(); - m_videoPreview = buildVideoPreview(); - m_videoTee = gst_element_factory_make("tee", NULL); - m_videoPreviewQueue = gst_element_factory_make("queue", NULL); - - ok &= m_videoSrc && m_videoPreview && m_videoTee && m_videoPreviewQueue; - - if (ok) { - gst_bin_add_many(GST_BIN(m_pipeline), m_videoSrc, m_videoTee, - m_videoPreviewQueue, m_videoPreview, NULL); - ok &= gst_element_link(m_videoSrc, m_videoTee); - ok &= gst_element_link(m_videoTee, m_videoPreviewQueue); - ok &= gst_element_link(m_videoPreviewQueue, m_videoPreview); - } - - if (ok && (m_captureMode & Video)) - ok &= gst_element_link(m_videoTee, m_encodeBin); - } - - if (!m_metaData.isEmpty()) - setMetaData(m_metaData); - - - break; - } - - if (!ok) { - emit error(int(QMediaRecorder::FormatError),tr("Failed to build media capture pipeline.")); - } - - dumpGraph( QString("rebuild_graph_%1_%2").arg(m_pipelineMode).arg(newMode) ); - if (m_encodeBin) { - QString fileName = QString("rebuild_graph_encode_%1_%2").arg(m_pipelineMode).arg(newMode); -#if !(GST_DISABLE_GST_DEBUG) && (GST_VERSION_MAJOR >= 0) && (GST_VERSION_MINOR >= 10) && (GST_VERSION_MICRO >= 19) - _gst_debug_bin_to_dot_file(GST_BIN(m_encodeBin), GST_DEBUG_GRAPH_SHOW_ALL, fileName.toAscii()); -#endif - } - - if (ok) { - m_pipelineMode = newMode; - } else { - m_pipelineMode = EmptyPipeline; - - REMOVE_ELEMENT(m_audioSrc); - REMOVE_ELEMENT(m_audioPreview); - REMOVE_ELEMENT(m_audioPreviewQueue); - REMOVE_ELEMENT(m_audioTee); - REMOVE_ELEMENT(m_videoSrc); - REMOVE_ELEMENT(m_videoPreview); - REMOVE_ELEMENT(m_videoPreviewQueue); - REMOVE_ELEMENT(m_videoTee); - REMOVE_ELEMENT(m_encodeBin); - } - - return ok; -} - -void QGstreamerCaptureSession::dumpGraph(const QString &fileName) -{ -#if !(GST_DISABLE_GST_DEBUG) && (GST_VERSION_MAJOR >= 0) && (GST_VERSION_MINOR >= 10) && (GST_VERSION_MICRO >= 19) - _gst_debug_bin_to_dot_file(GST_BIN(m_pipeline), - GstDebugGraphDetails(/*GST_DEBUG_GRAPH_SHOW_ALL |*/ GST_DEBUG_GRAPH_SHOW_MEDIA_TYPE | GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS | GST_DEBUG_GRAPH_SHOW_STATES), - fileName.toAscii()); -#endif -} - -QUrl QGstreamerCaptureSession::outputLocation() const -{ - return m_sink; -} - -bool QGstreamerCaptureSession::setOutputLocation(const QUrl& sink) -{ - m_sink = sink; - return true; -} - -void QGstreamerCaptureSession::setAudioInput(QGstreamerElementFactory *audioInput) -{ - m_audioInputFactory = audioInput; -} - -void QGstreamerCaptureSession::setAudioPreview(QGstreamerElementFactory *audioPreview) -{ - m_audioPreviewFactory = audioPreview; -} - -void QGstreamerCaptureSession::setVideoInput(QGstreamerVideoInput *videoInput) -{ - m_videoInputFactory = videoInput; -} - -void QGstreamerCaptureSession::setVideoPreview(QObject *viewfinder) -{ - m_viewfinderInterface = qobject_cast<QGstreamerVideoRendererInterface*>(viewfinder); - if (!m_viewfinderInterface) - viewfinder = 0; - - if (m_viewfinder != viewfinder) { - bool oldReady = isReady(); - - if (m_viewfinder) { - disconnect(m_viewfinder, SIGNAL(sinkChanged()), - this, SIGNAL(viewfinderChanged())); - disconnect(m_viewfinder, SIGNAL(readyChanged(bool)), - this, SIGNAL(readyChanged(bool))); - - m_busHelper->removeMessageFilter(m_viewfinder); - } - - m_viewfinder = viewfinder; - //m_viewfinderHasChanged = true; - - if (m_viewfinder) { - connect(m_viewfinder, SIGNAL(sinkChanged()), - this, SIGNAL(viewfinderChanged())); - connect(m_viewfinder, SIGNAL(readyChanged(bool)), - this, SIGNAL(readyChanged(bool))); - - m_busHelper->installMessageFilter(m_viewfinder); - } - - emit viewfinderChanged(); - if (oldReady != isReady()) - emit readyChanged(isReady()); - } -} - -bool QGstreamerCaptureSession::isReady() const -{ - return m_viewfinderInterface != 0 && m_viewfinderInterface->isReady(); -} - -QGstreamerCaptureSession::State QGstreamerCaptureSession::state() const -{ - return m_state; -} - -void QGstreamerCaptureSession::waitForStopped() -{ - GstState state = GST_STATE_PLAYING; - gst_element_get_state(m_pipeline, &state, 0, 0); - - while (state != GST_STATE_NULL) { - qApp->processEvents(); - gst_element_get_state(m_pipeline, &state, 0, 0); - } -} - -void QGstreamerCaptureSession::setState(QGstreamerCaptureSession::State newState) -{ - if (newState == m_pendingState && !m_waitingForEos) - return; - - m_pendingState = newState; - - PipelineMode newMode = EmptyPipeline; - - switch (newState) { - case PausedState: - case RecordingState: - newMode = PreviewAndRecordingPipeline; - break; - case PreviewState: - newMode = PreviewPipeline; - break; - case StoppedState: - newMode = EmptyPipeline; - break; - } - - if (newMode != m_pipelineMode) { - if (m_pipelineMode == PreviewAndRecordingPipeline) { - if (!m_waitingForEos) { - m_waitingForEos = true; - //qDebug() << "Waiting for EOS"; - //with live sources it's necessary to send EOS even to pipeline - //before going to STOPPED state - gst_element_send_event(m_pipeline, gst_event_new_eos()); - // Unless gstreamer is in GST_STATE_PLAYING our EOS message will not be received. - gst_element_set_state(m_pipeline, GST_STATE_PLAYING); - - return; - } else { - m_waitingForEos = false; - //qDebug() << "EOS received"; - } - } - - //select suitable default codecs/containers, if necessary - m_recorderControl->applySettings(); - - gst_element_set_state(m_pipeline, GST_STATE_NULL); - - //It would be better to do this async. but - //gstreamer doesn't notify about pipeline went to NULL state - waitForStopped(); - if (!rebuildGraph(newMode)) { - m_pendingState = StoppedState; - m_state = StoppedState; - emit stateChanged(StoppedState); - - return; - } - } - - switch (newState) { - case PausedState: - gst_element_set_state(m_pipeline, GST_STATE_PAUSED); - break; - case RecordingState: - case PreviewState: - gst_element_set_state(m_pipeline, GST_STATE_PLAYING); - break; - case StoppedState: - gst_element_set_state(m_pipeline, GST_STATE_NULL); - } - - //we have to do it here, since gstreamer will not emit bus messages any more - if (newState == StoppedState) { - m_state = StoppedState; - emit stateChanged(StoppedState); - } -} - - -qint64 QGstreamerCaptureSession::duration() const -{ - GstFormat format = GST_FORMAT_TIME; - gint64 duration = 0; - - if ( m_encodeBin && gst_element_query_position(m_encodeBin, &format, &duration)) - return duration / 1000000; - else - return 0; -} - -void QGstreamerCaptureSession::setCaptureDevice(const QString &deviceName) -{ - m_captureDevice = deviceName; -} - -void QGstreamerCaptureSession::setMetaData(const QMap<QByteArray, QVariant> &data) -{ - //qDebug() << "QGstreamerCaptureSession::setMetaData" << data; - m_metaData = data; - - if (m_encodeBin) { - GstIterator *elements = gst_bin_iterate_all_by_interface(GST_BIN(m_encodeBin), GST_TYPE_TAG_SETTER); - GstElement *element = 0; - while (gst_iterator_next(elements, (void**)&element) == GST_ITERATOR_OK) { - //qDebug() << "found element with tag setter interface:" << gst_element_get_name(element); - QMapIterator<QByteArray, QVariant> it(data); - while (it.hasNext()) { - it.next(); - const QString tagName = it.key(); - const QVariant tagValue = it.value(); - - - switch(tagValue.type()) { - case QVariant::String: - gst_tag_setter_add_tags(GST_TAG_SETTER(element), - GST_TAG_MERGE_REPLACE_ALL, - tagName.toUtf8().constData(), - tagValue.toString().toUtf8().constData(), - NULL); - break; - case QVariant::Int: - case QVariant::LongLong: - gst_tag_setter_add_tags(GST_TAG_SETTER(element), - GST_TAG_MERGE_REPLACE_ALL, - tagName.toUtf8().constData(), - tagValue.toInt(), - NULL); - break; - case QVariant::Double: - gst_tag_setter_add_tags(GST_TAG_SETTER(element), - GST_TAG_MERGE_REPLACE_ALL, - tagName.toUtf8().constData(), - tagValue.toDouble(), - NULL); - break; - default: - break; - } - - } - - } - } -} - -bool QGstreamerCaptureSession::processBusMessage(const QGstreamerMessage &message) -{ - GstMessage* gm = message.rawMessage(); - - if (gm) { - if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ERROR) { - GError *err; - gchar *debug; - gst_message_parse_error (gm, &err, &debug); - emit error(int(QMediaRecorder::ResourceError),QString::fromUtf8(err->message)); - g_error_free (err); - g_free (debug); - } - - if (GST_MESSAGE_SRC(gm) == GST_OBJECT_CAST(m_pipeline)) { - switch (GST_MESSAGE_TYPE(gm)) { - case GST_MESSAGE_DURATION: - break; - - case GST_MESSAGE_EOS: - if (m_waitingForEos) - setState(m_pendingState); - break; - - case GST_MESSAGE_STATE_CHANGED: - { - - GstState oldState; - GstState newState; - GstState pending; - - gst_message_parse_state_changed(gm, &oldState, &newState, &pending); - - QStringList states; - states << "GST_STATE_VOID_PENDING" << "GST_STATE_NULL" << "GST_STATE_READY" << "GST_STATE_PAUSED" << "GST_STATE_PLAYING"; - - /* - qDebug() << QString("state changed: old: %1 new: %2 pending: %3") \ - .arg(states[oldState]) \ - .arg(states[newState]) \ - .arg(states[pending]); - - #define ENUM_NAME(c,e,v) (c::staticMetaObject.enumerator(c::staticMetaObject.indexOfEnumerator(e)).valueToKey((v))) - - qDebug() << "Current session state:" << ENUM_NAME(QGstreamerCaptureSession,"State",m_state); - qDebug() << "Pending session state:" << ENUM_NAME(QGstreamerCaptureSession,"State",m_pendingState); - */ - - switch (newState) { - case GST_STATE_VOID_PENDING: - case GST_STATE_NULL: - case GST_STATE_READY: - if (m_state != StoppedState && m_pendingState == StoppedState) { - emit stateChanged(m_state = StoppedState); - dumpGraph("stopped"); - } - break; - case GST_STATE_PAUSED: - if (m_state != PausedState && m_pendingState == PausedState) - emit stateChanged(m_state = PausedState); - dumpGraph("paused"); - - if (m_pipelineMode == RecordingPipeline && !m_metaData.isEmpty()) - setMetaData(m_metaData); - break; - case GST_STATE_PLAYING: - { - if ((m_pendingState == PreviewState || m_pendingState == RecordingState) && - m_state != m_pendingState) - { - m_state = m_pendingState; - emit stateChanged(m_state); - } - - if (m_pipelineMode == PreviewPipeline) - dumpGraph("preview"); - else - dumpGraph("recording"); - } - break; - } - } - break; - default: - break; - } - //qDebug() << "New session state:" << ENUM_NAME(QGstreamerCaptureSession,"State",m_state); - } - } - return false; -} - -void QGstreamerCaptureSession::setMuted(bool muted) -{ - if (m_muted != muted) { - m_muted = muted; - if (m_audioVolume) - g_object_set(G_OBJECT(m_audioVolume), "volume", (m_muted ? 0.0 : 1.0), NULL); - emit mutedChanged(muted); - } -} diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.h b/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.h deleted file mode 100644 index aa5a09c..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.h +++ /dev/null @@ -1,211 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERCAPTURESESSION_H -#define QGSTREAMERCAPTURESESSION_H - -#include <qmediarecordercontrol.h> -#include <qmediarecorder.h> - -#include <QtCore/qurl.h> - -#include <gst/gst.h> - -#include <private/qgstreamerbushelper_p.h> - -QT_USE_NAMESPACE - -class QGstreamerMessage; -class QGstreamerBusHelper; -class QGstreamerAudioEncode; -class QGstreamerVideoEncode; -class QGstreamerImageEncode; -class QGstreamerRecorderControl; -class QGstreamerMediaContainerControl; -class QGstreamerVideoRendererInterface; - -class QGstreamerElementFactory -{ -public: - virtual GstElement *buildElement() = 0; - virtual void prepareWinId() {} -}; - -class QGstreamerVideoInput : public QGstreamerElementFactory -{ -public: - virtual QList<qreal> supportedFrameRates(const QSize &frameSize = QSize()) const = 0; - virtual QList<QSize> supportedResolutions(qreal frameRate = -1) const = 0; -}; - -class QGstreamerCaptureSession : public QObject, public QGstreamerBusMessageFilter -{ - Q_OBJECT - Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged) - Q_ENUMS(State) - Q_ENUMS(CaptureMode) - Q_INTERFACES(QGstreamerBusMessageFilter) -public: - enum CaptureMode { Audio = 1, Video = 2, Image=4, AudioAndVideo = Audio | Video }; - enum State { StoppedState, PreviewState, PausedState, RecordingState }; - - QGstreamerCaptureSession(CaptureMode captureMode, QObject *parent); - ~QGstreamerCaptureSession(); - - QGstreamerBusHelper *bus() { return m_busHelper; } - - CaptureMode captureMode() const { return m_captureMode; } - void setCaptureMode(CaptureMode); - - QUrl outputLocation() const; - bool setOutputLocation(const QUrl& sink); - - QGstreamerAudioEncode *audioEncodeControl() const { return m_audioEncodeControl; } - QGstreamerVideoEncode *videoEncodeControl() const { return m_videoEncodeControl; } - QGstreamerImageEncode *imageEncodeControl() const { return m_imageEncodeControl; } - - QGstreamerRecorderControl *recorderControl() const { return m_recorderControl; } - QGstreamerMediaContainerControl *mediaContainerControl() const { return m_mediaContainerControl; } - - QGstreamerElementFactory *audioInput() const { return m_audioInputFactory; } - void setAudioInput(QGstreamerElementFactory *audioInput); - - QGstreamerElementFactory *audioPreview() const { return m_audioPreviewFactory; } - void setAudioPreview(QGstreamerElementFactory *audioPreview); - - QGstreamerVideoInput *videoInput() const { return m_videoInputFactory; } - void setVideoInput(QGstreamerVideoInput *videoInput); - - QObject *videoPreview() const { return m_viewfinder; } - void setVideoPreview(QObject *viewfinder); - - void captureImage(int requestId, const QString &fileName); - - State state() const; - qint64 duration() const; - bool isMuted() const { return m_muted; } - - bool isReady() const; - - bool processBusMessage(const QGstreamerMessage &message); - -signals: - void stateChanged(QGstreamerCaptureSession::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 imageSaved(int requestId, const QString &path); - void mutedChanged(bool); - void readyChanged(bool); - void viewfinderChanged(); - -public slots: - void setState(QGstreamerCaptureSession::State); - void setCaptureDevice(const QString &deviceName); - - void dumpGraph(const QString &fileName); - - void setMetaData(const QMap<QByteArray, QVariant>&); - void setMuted(bool); - -private: - enum PipelineMode { EmptyPipeline, PreviewPipeline, RecordingPipeline, PreviewAndRecordingPipeline }; - - GstElement *buildEncodeBin(); - GstElement *buildAudioSrc(); - GstElement *buildAudioPreview(); - GstElement *buildVideoSrc(); - GstElement *buildVideoPreview(); - GstElement *buildImageCapture(); - - void waitForStopped(); - bool rebuildGraph(QGstreamerCaptureSession::PipelineMode newMode); - - QUrl m_sink; - QString m_captureDevice; - State m_state; - State m_pendingState; - bool m_waitingForEos; - PipelineMode m_pipelineMode; - QGstreamerCaptureSession::CaptureMode m_captureMode; - QMap<QByteArray, QVariant> m_metaData; - - QGstreamerElementFactory *m_audioInputFactory; - QGstreamerElementFactory *m_audioPreviewFactory; - QGstreamerVideoInput *m_videoInputFactory; - QObject *m_viewfinder; - QGstreamerVideoRendererInterface *m_viewfinderInterface; - - QGstreamerAudioEncode *m_audioEncodeControl; - QGstreamerVideoEncode *m_videoEncodeControl; - QGstreamerImageEncode *m_imageEncodeControl; - QGstreamerRecorderControl *m_recorderControl; - QGstreamerMediaContainerControl *m_mediaContainerControl; - - QGstreamerBusHelper *m_busHelper; - GstBus* m_bus; - GstElement *m_pipeline; - - GstElement *m_audioSrc; - GstElement *m_audioTee; - GstElement *m_audioPreviewQueue; - GstElement *m_audioPreview; - GstElement *m_audioVolume; - bool m_muted; - - GstElement *m_videoSrc; - GstElement *m_videoTee; - GstElement *m_videoPreviewQueue; - GstElement *m_videoPreview; - - GstElement *m_imageCaptureBin; - - GstElement *m_encodeBin; - -public: - bool m_passImage; - bool m_passPrerollImage; - QString m_imageFileName; - int m_imageRequestId; -}; - -#endif // QGSTREAMERCAPTURESESSION_H diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerimagecapturecontrol.cpp b/src/plugins/gstreamer/mediacapture/qgstreamerimagecapturecontrol.cpp deleted file mode 100644 index efa7089..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamerimagecapturecontrol.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamerimagecapturecontrol.h" -#include <QtCore/QDebug> -#include <QtCore/QDir> - -QGstreamerImageCaptureControl::QGstreamerImageCaptureControl(QGstreamerCaptureSession *session) - :QCameraImageCaptureControl(session), m_session(session), m_ready(false), m_lastId(0) -{ - connect(m_session, SIGNAL(stateChanged(QGstreamerCaptureSession::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(imageSaved(int,QString)), this, SIGNAL(imageSaved(int,QString))); -} - -QGstreamerImageCaptureControl::~QGstreamerImageCaptureControl() -{ -} - -bool QGstreamerImageCaptureControl::isReadyForCapture() const -{ - return m_ready; -} - -int QGstreamerImageCaptureControl::capture(const QString &fileName) -{ - QString path = fileName; - if (path.isEmpty()) { - int lastImage = 0; - QDir outputDir = QDir::currentPath(); - foreach(QString fileName, outputDir.entryList(QStringList() << "img_*.jpg")) { - int imgNumber = fileName.mid(4, fileName.size()-8).toInt(); - lastImage = qMax(lastImage, imgNumber); - } - - path = QString("img_%1.jpg").arg(lastImage+1, - 4, //fieldWidth - 10, - QLatin1Char('0')); - } - m_lastId++; - - m_session->captureImage(m_lastId, path); - - return m_lastId; -} - -void QGstreamerImageCaptureControl::cancelCapture() -{ - -} - -void QGstreamerImageCaptureControl::updateState() -{ - bool ready = m_session->state() == QGstreamerCaptureSession::PreviewState; - if (m_ready != ready) { - emit readyForCaptureChanged(m_ready = ready); - } -} diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerimagecapturecontrol.h b/src/plugins/gstreamer/mediacapture/qgstreamerimagecapturecontrol.h deleted file mode 100644 index 186aa39..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamerimagecapturecontrol.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QGSTREAMERIMAGECAPTURECONTROL_H -#define QGSTREAMERIMAGECAPTURECONTROL_H - -#include <qcameraimagecapturecontrol.h> -#include "qgstreamercapturesession.h" -QT_USE_NAMESPACE - -class QGstreamerImageCaptureControl : public QCameraImageCaptureControl -{ - Q_OBJECT -public: - QGstreamerImageCaptureControl(QGstreamerCaptureSession *session); - virtual ~QGstreamerImageCaptureControl(); - - 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(); - -private: - QGstreamerCaptureSession *m_session; - bool m_ready; - int m_lastId; -}; - -#endif // QGSTREAMERCAPTURECORNTROL_H diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerimageencode.cpp b/src/plugins/gstreamer/mediacapture/qgstreamerimageencode.cpp deleted file mode 100644 index 1fbc450..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamerimageencode.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamerimageencode.h" -#include "qgstreamercapturesession.h" - -#include <QtCore/qdebug.h> - -#include <math.h> - -QGstreamerImageEncode::QGstreamerImageEncode(QGstreamerCaptureSession *session) - :QImageEncoderControl(session), m_session(session) -{ -} - -QGstreamerImageEncode::~QGstreamerImageEncode() -{ -} - -QList<QSize> QGstreamerImageEncode::supportedResolutions(const QImageEncoderSettings &, bool *continuous) const -{ - if (continuous) - *continuous = m_session->videoInput() != 0; - - return m_session->videoInput() ? m_session->videoInput()->supportedResolutions() : QList<QSize>(); -} - -QStringList QGstreamerImageEncode::supportedImageCodecs() const -{ - return QStringList() << "jpeg"; -} - -QString QGstreamerImageEncode::imageCodecDescription(const QString &codecName) const -{ - if (codecName == "jpeg") - return tr("JPEG image encoder"); - - return QString(); -} - -QImageEncoderSettings QGstreamerImageEncode::imageSettings() const -{ - return m_settings; -} - -void QGstreamerImageEncode::setImageSettings(const QImageEncoderSettings &settings) -{ - if (m_settings != settings) { - m_settings = settings; - emit settingsChanged(); - } -} diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerimageencode.h b/src/plugins/gstreamer/mediacapture/qgstreamerimageencode.h deleted file mode 100644 index a3c6294..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamerimageencode.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERIMAGEENCODE_H -#define QGSTREAMERIMAGEENCODE_H - -class QGstreamerCaptureSession; - -#include <qimageencodercontrol.h> - -#include <QtCore/qstringlist.h> -#include <QtCore/qmap.h> - -#include <gst/gst.h> -QT_USE_NAMESPACE - -class QGstreamerImageEncode : public QImageEncoderControl -{ - Q_OBJECT -public: - QGstreamerImageEncode(QGstreamerCaptureSession *session); - virtual ~QGstreamerImageEncode(); - - QList<QSize> supportedResolutions(const QImageEncoderSettings &settings = QImageEncoderSettings(), - bool *continuous = 0) const; - - QStringList supportedImageCodecs() const; - QString imageCodecDescription(const QString &codecName) const; - - QImageEncoderSettings imageSettings() const; - void setImageSettings(const QImageEncoderSettings &settings); - -Q_SIGNALS: - void settingsChanged(); - -private: - QImageEncoderSettings m_settings; - - QGstreamerCaptureSession *m_session; -}; - -#endif diff --git a/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.cpp b/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.cpp deleted file mode 100644 index b0d48f2..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamermediacontainercontrol.h" - - -#include <QtCore/qdebug.h> - -QGstreamerMediaContainerControl::QGstreamerMediaContainerControl(QObject *parent) - :QMediaContainerControl(parent) -{ - QList<QByteArray> formatCandidates; - formatCandidates << "matroska" << "ogg" << "mp4" << "wav" << "quicktime" << "avi" << "3gpp"; - formatCandidates << "flv" << "amr" << "asf" << "dv" << "gif"; - formatCandidates << "mpeg" << "vob" << "mpegts" << "3g2" << "3gp"; - formatCandidates << "raw"; - - m_elementNames["matroska"] = "matroskamux"; - m_elementNames["ogg"] = "oggmux"; - m_elementNames["mp4"] = "ffmux_mp4"; - m_elementNames["quicktime"] = "ffmux_mov"; - m_elementNames["avi"] = "avimux"; - m_elementNames["3gpp"] = "gppmux"; - m_elementNames["flv"] = "flvmux"; - m_elementNames["wav"] = "wavenc"; - m_elementNames["amr"] = "ffmux_amr"; - m_elementNames["asf"] = "ffmux_asf"; - m_elementNames["dv"] = "ffmux_dv"; - m_elementNames["gif"] = "ffmux_gif"; - m_elementNames["mpeg"] = "ffmux_mpeg"; - m_elementNames["vob"] = "ffmux_vob"; - m_elementNames["mpegts"] = "ffmux_mpegts"; - m_elementNames["3g2"] = "ffmux_3g2"; - m_elementNames["3gp"] = "ffmux_3gp"; - m_elementNames["raw"] = "identity"; - - m_containerExtensions["matroska"] = "mkv"; - m_containerExtensions["quicktime"] = "mov"; - m_containerExtensions["mpegts"] = "m2t"; - m_containerExtensions["mpeg"] = "mpg"; - - QSet<QString> allTypes; - - foreach( const QByteArray& formatName, formatCandidates ) { - QByteArray elementName = m_elementNames[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)); - } - } - - //if (!m_supportedContainers.isEmpty()) - // setContainerMimeType(m_supportedContainers[0]); -} - -QSet<QString> QGstreamerMediaContainerControl::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> QGstreamerMediaContainerControl::supportedStreamTypes(const QString &container) const -{ - return m_streamTypes.value(container); -} - -QString QGstreamerMediaContainerControl::containerExtension() const -{ - return m_containerExtensions.value(m_format, m_format); -} diff --git a/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.h b/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.h deleted file mode 100644 index 345226b..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QGSTREAMERMEDIACONTAINERCONTROL_H -#define QGSTREAMERMEDIACONTAINERCONTROL_H - -#include <qmediacontainercontrol.h> -#include <QtCore/qstringlist.h> -#include <QtCore/qset.h> - -#include <gst/gst.h> - -QT_USE_NAMESPACE - -class QGstreamerMediaContainerControl : public QMediaContainerControl -{ -Q_OBJECT -public: - QGstreamerMediaContainerControl(QObject *parent); - virtual ~QGstreamerMediaContainerControl() {}; - - virtual QStringList supportedContainers() const { return m_supportedContainers; } - virtual QString containerMimeType() const { return m_format; } - virtual void setContainerMimeType(const QString &formatMimeType) { m_format = formatMimeType; } - - 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); - - QString containerExtension() const; - -private: - QString m_format; - QStringList m_supportedContainers; - QMap<QString,QByteArray> m_elementNames; - QMap<QString, QString> m_containerDescriptions; - QMap<QString, QString> m_containerExtensions; - QMap<QString, QSet<QString> > m_streamTypes; -}; - -#endif // QGSTREAMERMEDIACONTAINERCONTROL_H diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.cpp b/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.cpp deleted file mode 100644 index 250a6b2..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.cpp +++ /dev/null @@ -1,289 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamerrecordercontrol.h" -#include "qgstreameraudioencode.h" -#include "qgstreamervideoencode.h" -#include "qgstreamermediacontainercontrol.h" -#include <QtCore/QDebug> - -QGstreamerRecorderControl::QGstreamerRecorderControl(QGstreamerCaptureSession *session) - :QMediaRecorderControl(session), m_session(session), m_state(QMediaRecorder::StoppedState) -{ - connect(m_session, SIGNAL(stateChanged(QGstreamerCaptureSession::State)), SLOT(updateState())); - connect(m_session, SIGNAL(error(int,QString)), SIGNAL(error(int,QString))); - connect(m_session, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged(qint64))); - connect(m_session, SIGNAL(mutedChanged(bool)), SIGNAL(mutedChanged(bool))); - m_hasPreviewState = m_session->captureMode() != QGstreamerCaptureSession::Audio; -} - -QGstreamerRecorderControl::~QGstreamerRecorderControl() -{ -} - -QUrl QGstreamerRecorderControl::outputLocation() const -{ - return m_session->outputLocation(); -} - -bool QGstreamerRecorderControl::setOutputLocation(const QUrl &sink) -{ - m_outputLocation = sink; - m_session->setOutputLocation(sink); - return true; -} - - -QMediaRecorder::State QGstreamerRecorderControl::state() const -{ - switch ( m_session->state() ) { - case QGstreamerCaptureSession::RecordingState: - return QMediaRecorder::RecordingState; - case QGstreamerCaptureSession::PausedState: - return QMediaRecorder::PausedState; - case QGstreamerCaptureSession::PreviewState: - case QGstreamerCaptureSession::StoppedState: - return QMediaRecorder::StoppedState; - } - - return QMediaRecorder::StoppedState; - -} - -void QGstreamerRecorderControl::updateState() -{ - QMediaRecorder::State newState = state(); - if (m_state != newState) { - m_state = newState; - emit stateChanged(m_state); - } -} - -qint64 QGstreamerRecorderControl::duration() const -{ - return m_session->duration(); -} - -void QGstreamerRecorderControl::record() -{ - if (m_outputLocation.isEmpty()) { - QString container = m_session->mediaContainerControl()->containerExtension(); - if (container.isEmpty()) - container = "raw"; - - m_session->setOutputLocation(QUrl(generateFileName(defaultDir(), container))); - } - - m_session->dumpGraph("before-record"); - if (!m_hasPreviewState || m_session->state() != QGstreamerCaptureSession::StoppedState) { - m_session->setState(QGstreamerCaptureSession::RecordingState); - } else - emit error(QMediaRecorder::ResourceError, tr("Service has not been started")); - - m_session->dumpGraph("after-record"); -} - -void QGstreamerRecorderControl::pause() -{ - m_session->dumpGraph("before-pause"); - if (!m_hasPreviewState || m_session->state() != QGstreamerCaptureSession::StoppedState) { - m_session->setState(QGstreamerCaptureSession::PausedState); - } else - emit error(QMediaRecorder::ResourceError, tr("Service has not been started")); -} - -void QGstreamerRecorderControl::stop() -{ - if (!m_hasPreviewState) { - m_session->setState(QGstreamerCaptureSession::StoppedState); - } else { - if (m_session->state() != QGstreamerCaptureSession::StoppedState) - m_session->setState(QGstreamerCaptureSession::PreviewState); - } -} - -void QGstreamerRecorderControl::applySettings() -{ - //Check the codecs are compatible with container, - //and choose the compatible codecs/container if omitted - QGstreamerAudioEncode *audioEncodeControl = m_session->audioEncodeControl(); - QGstreamerVideoEncode *videoEncodeControl = m_session->videoEncodeControl(); - QGstreamerMediaContainerControl *mediaContainerControl = m_session->mediaContainerControl(); - - bool needAudio = m_session->captureMode() & QGstreamerCaptureSession::Audio; - bool needVideo = m_session->captureMode() & QGstreamerCaptureSession::Video; - - QStringList containerCandidates; - if (mediaContainerControl->containerMimeType().isEmpty()) - containerCandidates = mediaContainerControl->supportedContainers(); - else - containerCandidates << mediaContainerControl->containerMimeType(); - - - QStringList audioCandidates; - if (needAudio) { - QAudioEncoderSettings audioSettings = audioEncodeControl->audioSettings(); - if (audioSettings.codec().isEmpty()) - audioCandidates = audioEncodeControl->supportedAudioCodecs(); - else - audioCandidates << audioSettings.codec(); - } - - QStringList videoCandidates; - if (needVideo) { - 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(); - - if (needAudio) { - 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; - } - - if (needVideo) { - bool 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()) { - emit error(QMediaRecorder::FormatError, tr("Not compatible codecs and container format.")); - } else { - mediaContainerControl->setContainerMimeType(container); - - if (needAudio) { - QAudioEncoderSettings audioSettings = audioEncodeControl->audioSettings(); - audioSettings.setCodec(audioCodec); - audioEncodeControl->setAudioSettings(audioSettings); - } - - if (needVideo) { - QVideoEncoderSettings videoSettings = videoEncodeControl->videoSettings(); - videoSettings.setCodec(videoCodec); - videoEncodeControl->setVideoSettings(videoSettings); - } - } -} - - -bool QGstreamerRecorderControl::isMuted() const -{ - return m_session->isMuted(); -} - -void QGstreamerRecorderControl::setMuted(bool muted) -{ - m_session->setMuted(muted); -} - -QDir QGstreamerRecorderControl::defaultDir() const -{ - QStringList dirCandidates; - -#if defined(Q_WS_MAEMO_6) - dirCandidates << QLatin1String("/home/user/MyDocs"); -#endif - - dirCandidates << QDir::home().filePath("Documents"); - dirCandidates << QDir::home().filePath("My Documents"); - dirCandidates << QDir::homePath(); - dirCandidates << QDir::currentPath(); - dirCandidates << QDir::tempPath(); - - foreach (const QString &path, dirCandidates) { - QDir dir(path); - if (dir.exists() && QFileInfo(path).isWritable()) - return dir; - } - - return QDir(); -} - -QString QGstreamerRecorderControl::generateFileName(const QDir &dir, const QString &ext) const -{ - - int lastClip = 0; - foreach(QString fileName, dir.entryList(QStringList() << QString("clip_*.%1").arg(ext))) { - int imgNumber = fileName.mid(5, fileName.size()-6-ext.length()).toInt(); - lastClip = qMax(lastClip, imgNumber); - } - - QString name = QString("clip_%1.%2").arg(lastClip+1, - 4, //fieldWidth - 10, - QLatin1Char('0')).arg(ext); - - return dir.absoluteFilePath(name); -} diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.h b/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.h deleted file mode 100644 index 66f4ee6..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QGSTREAMERRECORDERCONTROL_H -#define QGSTREAMERRECORDERCONTROL_H - -#include <QtCore/QDir> - -#include <qmediarecordercontrol.h> -#include "qgstreamercapturesession.h" - -QT_USE_NAMESPACE - -class QGstreamerRecorderControl : public QMediaRecorderControl -{ - Q_OBJECT - -public: - QGstreamerRecorderControl(QGstreamerCaptureSession *session); - virtual ~QGstreamerRecorderControl(); - - QUrl outputLocation() const; - bool setOutputLocation(const QUrl &sink); - - QMediaRecorder::State state() const; - - qint64 duration() const; - - bool isMuted() const; - - void applySettings(); - -public slots: - void record(); - void pause(); - void stop(); - void setMuted(bool); - -private slots: - void updateState(); - -private: - QDir defaultDir() const; - QString generateFileName(const QDir &dir, const QString &ext) const; - - QUrl m_outputLocation; - QGstreamerCaptureSession *m_session; - QMediaRecorder::State m_state; - bool m_hasPreviewState; -}; - -#endif // QGSTREAMERCAPTURECORNTROL_H diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerv4l2input.cpp b/src/plugins/gstreamer/mediacapture/qgstreamerv4l2input.cpp deleted file mode 100644 index 0d9d083..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamerv4l2input.cpp +++ /dev/null @@ -1,293 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamerv4l2input.h" - -#include <QtCore/qdebug.h> -#include <QtCore/qfile.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> - -QT_BEGIN_NAMESPACE -static inline uint qHash(const QSize& key) { return uint(key.width()*256+key.height()); } - -static bool operator<(const QSize &s1, const QSize s2) -{ - return s1.width()*s1.height() < s2.width()*s2.height(); -} -QT_END_NAMESPACE - -QGstreamerV4L2Input::QGstreamerV4L2Input(QObject *parent) - :QObject(parent) -{ -} - -QGstreamerV4L2Input::~QGstreamerV4L2Input() -{ -} - -GstElement *QGstreamerV4L2Input::buildElement() -{ - GstElement *camera = gst_element_factory_make("v4l2src", "camera_source"); - if (camera && !m_device.isEmpty() ) - g_object_set(G_OBJECT(camera), "device", m_device.constData(), NULL); - - return camera; -} - -void QGstreamerV4L2Input::setDevice(const QByteArray &newDevice) -{ - if (m_device != newDevice) { - m_device = newDevice; - updateSupportedResolutions(newDevice); - } -} - -void QGstreamerV4L2Input::setDevice(const QString &device) -{ - setDevice(QFile::encodeName(device)); -} - -void QGstreamerV4L2Input::updateSupportedResolutions(const QByteArray &device) -{ - m_frameRates.clear(); - m_resolutions.clear(); - m_ratesByResolution.clear(); - - QSet<QSize> allResolutions; - QSet<int> allFrameRates; - - QFile f(device); - - if (!f.open(QFile::ReadOnly)) - return; - - int fd = f.handle(); - - //get the list of formats: - QList<quint32> supportedFormats; - - { - v4l2_fmtdesc fmt; - memset(&fmt, 0, sizeof(v4l2_fmtdesc)); - - fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - int sanity = 0; - - for (fmt.index = 0;; fmt.index++) { - if (sanity++ > 8) - break; - if( ::ioctl(fd, VIDIOC_ENUM_FMT, &fmt) == -1) { - if(errno == EINVAL) - break; - } - supportedFormats.append(fmt.pixelformat); - } - } - - QList<QSize> commonSizes; - commonSizes << QSize(128, 96) - <<QSize(160,120) - <<QSize(176, 144) - <<QSize(320, 240) - <<QSize(352, 288) - <<QSize(640, 480) - <<QSize(1024, 768) - <<QSize(1280, 1024) - <<QSize(1600, 1200) - <<QSize(1920, 1200) - <<QSize(2048, 1536) - <<QSize(2560, 1600) - <<QSize(2580, 1936); - - QList<int> commonRates; - commonRates << 05*1000 << 75*1000 << 10*1000 << 15*1000 << 20*1000 - << 24*1000 << 25*1000 << 30*1000 << 50*1000 << 60*1000; - - - //get the list of resolutions: - - foreach (quint32 format, supportedFormats) { - struct v4l2_frmsizeenum formatSize; - memset(&formatSize, 0, sizeof(formatSize)); - formatSize.pixel_format = format; - - QList<QSize> sizeList; - - if (0) { - char formatStr[5]; - memcpy(formatStr, &format, 4); - formatStr[4] = 0; - //qDebug() << "trying format" << formatStr; - } - - for (int i=0;;i++) { - formatSize.index = i; - if (ioctl (fd, VIDIOC_ENUM_FRAMESIZES, &formatSize) < 0) - break; - - if (formatSize.type == V4L2_FRMSIZE_TYPE_DISCRETE) { - sizeList.append(QSize(formatSize.discrete.width, formatSize.discrete.height)); - } else { - - foreach (const QSize& candidate, commonSizes) { - if (candidate.width() <= (int)formatSize.stepwise.max_width && - candidate.height() >= (int)formatSize.stepwise.min_width && - candidate.width() % formatSize.stepwise.step_width == 0 && - candidate.height() <= (int)formatSize.stepwise.max_height && - candidate.height() >= (int)formatSize.stepwise.min_height && - candidate.height() % formatSize.stepwise.step_height == 0) { - sizeList.append(candidate); - } - } - - if (!sizeList.contains(QSize(formatSize.stepwise.min_width, formatSize.stepwise.min_height))) - sizeList.prepend(QSize(formatSize.stepwise.min_width, formatSize.stepwise.min_height)); - - if (!sizeList.contains(QSize(formatSize.stepwise.max_width, formatSize.stepwise.max_height))) - sizeList.append(QSize(formatSize.stepwise.max_width, formatSize.stepwise.max_height)); - - break; //stepwise values are returned only for index 0 - } - - } - - //and frameRates for each resolution. - - foreach (const QSize &s, sizeList) { - allResolutions.insert(s); - - struct v4l2_frmivalenum formatInterval; - memset(&formatInterval, 0, sizeof(formatInterval)); - formatInterval.pixel_format = format; - formatInterval.width = s.width(); - formatInterval.height = s.height(); - - QList<int> frameRates; //in 1/1000 of fps - - for (int i=0; ; i++) { - formatInterval.index = i; - - if (ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &formatInterval) < 0) - break; - - if (formatInterval.type == V4L2_FRMIVAL_TYPE_DISCRETE) { - //converts seconds to fps*1000 - if (formatInterval.discrete.numerator) - frameRates.append(qRound(formatInterval.discrete.denominator*1000.0 / formatInterval.discrete.numerator)); - } else { - if (formatInterval.stepwise.min.numerator == 0 || - formatInterval.stepwise.max.numerator == 0) { - qWarning() << "received invalid frame interval"; - break; - } - - - int minRate = qRound(formatInterval.stepwise.min.denominator*1000.0 / - formatInterval.stepwise.min.numerator); - - int maxRate = qRound(formatInterval.stepwise.max.denominator*1000.0 / - formatInterval.stepwise.max.numerator); - - - foreach (int candidate, commonRates) { - if (candidate >= minRate && candidate <= maxRate) - frameRates.append(candidate); - } - - if (!frameRates.contains(minRate)) - frameRates.prepend(minRate); - - if (!frameRates.contains(maxRate)) - frameRates.append(maxRate); - - break; //stepwise values are returned only for index 0 - } - } - allFrameRates.unite(frameRates.toSet()); - m_ratesByResolution[s].unite(frameRates.toSet()); - } - } - - f.close(); - - foreach(int rate, allFrameRates) { - m_frameRates.append(rate/1000.0); - } - - qSort(m_frameRates); - - m_resolutions = allResolutions.toList(); - qSort(m_resolutions); - - //qDebug() << "frame rates:" << m_frameRates; - //qDebug() << "resolutions:" << m_resolutions; -} - - -QList<qreal> QGstreamerV4L2Input::supportedFrameRates(const QSize &frameSize) const -{ - if (frameSize.isEmpty()) - return m_frameRates; - else { - QList<qreal> res; - foreach(int rate, m_ratesByResolution[frameSize]) { - res.append(rate/1000.0); - } - return res; - } -} - -QList<QSize> QGstreamerV4L2Input::supportedResolutions(qreal frameRate) const -{ - Q_UNUSED(frameRate); - return m_resolutions; -} diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerv4l2input.h b/src/plugins/gstreamer/mediacapture/qgstreamerv4l2input.h deleted file mode 100644 index 278f642..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamerv4l2input.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QGSTREAMERV4L2INPUT_H -#define QGSTREAMERV4L2INPUT_H - -#include <QtCore/qhash.h> -#include <QtCore/qbytearray.h> -#include <QtCore/qlist.h> -#include <QtCore/qsize.h> -#include "qgstreamercapturesession.h" - -QT_USE_NAMESPACE - -class QGstreamerV4L2Input : public QObject, public QGstreamerVideoInput -{ - Q_OBJECT -public: - QGstreamerV4L2Input(QObject *parent = 0); - virtual ~QGstreamerV4L2Input(); - - GstElement *buildElement(); - - QList<qreal> supportedFrameRates(const QSize &frameSize = QSize()) const; - QList<QSize> supportedResolutions(qreal frameRate = -1) const; - - QByteArray device() const; - -public slots: - void setDevice(const QByteArray &device); - void setDevice(const QString &device); - -private: - void updateSupportedResolutions(const QByteArray &device); - - QList<qreal> m_frameRates; - QList<QSize> m_resolutions; - - QHash<QSize, QSet<int> > m_ratesByResolution; - - QByteArray m_device; -}; - -#endif // QGSTREAMERV4L2INPUT_H diff --git a/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.cpp b/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.cpp deleted file mode 100644 index a2f139e..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.cpp +++ /dev/null @@ -1,331 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamervideoencode.h" -#include "qgstreamercapturesession.h" -#include "qgstreamermediacontainercontrol.h" - -#include <QtCore/qdebug.h> - -#include <math.h> - -QGstreamerVideoEncode::QGstreamerVideoEncode(QGstreamerCaptureSession *session) - :QVideoEncoderControl(session), m_session(session) -{ - QList<QByteArray> codecCandidates; - codecCandidates << "video/h264" << "video/xvid" << "video/mpeg4" << "video/mpeg1" << "video/mpeg2" << "video/theora"; - - 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_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(); - - 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, - QGstreamerMediaContainerControl::supportedStreamTypes(factory, GST_PAD_SRC)); - - gst_object_unref(GST_OBJECT(factory)); - } - } - - //if (!m_codecs.isEmpty()) - // m_videoSettings.setCodec(m_codecs[0]); -} - -QGstreamerVideoEncode::~QGstreamerVideoEncode() -{ -} - -QList<QSize> QGstreamerVideoEncode::supportedResolutions(const QVideoEncoderSettings &, bool *continuous) const -{ - if (continuous) - *continuous = m_session->videoInput() != 0; - - return m_session->videoInput() ? m_session->videoInput()->supportedResolutions() : QList<QSize>(); -} - -QList< qreal > QGstreamerVideoEncode::supportedFrameRates(const QVideoEncoderSettings &, bool *continuous) const -{ - if (continuous) - *continuous = false; - - return m_session->videoInput() ? m_session->videoInput()->supportedFrameRates() : QList<qreal>(); -} - -QStringList QGstreamerVideoEncode::supportedVideoCodecs() const -{ - return m_codecs; -} - -QString QGstreamerVideoEncode::videoCodecDescription(const QString &codecName) const -{ - return m_codecDescriptions.value(codecName); -} - -QStringList QGstreamerVideoEncode::supportedEncodingOptions(const QString &codec) const -{ - return m_codecOptions.value(codec); -} - -QVariant QGstreamerVideoEncode::encodingOption(const QString &codec, const QString &name) const -{ - return m_options[codec].value(name); -} - -void QGstreamerVideoEncode::setEncodingOption( - const QString &codec, const QString &name, const QVariant &value) -{ - m_options[codec][name] = value; -} - -QVideoEncoderSettings QGstreamerVideoEncode::videoSettings() const -{ - return m_videoSettings; -} - -void QGstreamerVideoEncode::setVideoSettings(const QVideoEncoderSettings &settings) -{ - m_videoSettings = settings; -} - -GstElement *QGstreamerVideoEncode::createEncoder() -{ - QString codec = m_videoSettings.codec(); - //qDebug() << "create encoder for video codec" << codec; - GstElement *encoderElement = gst_element_factory_make( m_elementNames.value(codec).constData(), "video-encoder"); - if (!encoderElement) - return 0; - - GstBin *encoderBin = GST_BIN(gst_bin_new("video-encoder-bin")); - - GstElement *capsFilter = gst_element_factory_make("capsfilter", "capsfilter-video"); - gst_bin_add(encoderBin, capsFilter); - - GstElement *colorspace = gst_element_factory_make("ffmpegcolorspace", NULL); - gst_bin_add(encoderBin, colorspace); - gst_bin_add(encoderBin, encoderElement); - - gst_element_link_many(capsFilter, colorspace, encoderElement, NULL); - - // 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 (encoderElement) { - if (m_videoSettings.encodingMode() == QtMultimedia::ConstantQualityEncoding) { - QtMultimedia::EncodingQuality qualityValue = m_videoSettings.quality(); - - if (codec == QLatin1String("video/h264")) { - //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 (codec == QLatin1String("video/xvid")) { - //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 (codec == QLatin1String("video/mpeg4") || - codec == QLatin1String("video/mpeg1") || - codec == QLatin1String("video/mpeg2") ) { - //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 (codec == QLatin1String("video/theora")) { - 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 { - 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; - } - - } - } - - if (!m_videoSettings.resolution().isEmpty() || m_videoSettings.frameRate() > 0.001) { - GstCaps *caps = gst_caps_new_empty(); - QStringList structureTypes; - structureTypes << "video/x-raw-yuv" << "video/x-raw-rgb"; - - foreach(const QString &structureType, structureTypes) { - GstStructure *structure = gst_structure_new(structureType.toAscii().constData(), NULL); - - if (!m_videoSettings.resolution().isEmpty()) { - gst_structure_set(structure, "width", G_TYPE_INT, m_videoSettings.resolution().width(), NULL); - gst_structure_set(structure, "height", G_TYPE_INT, m_videoSettings.resolution().height(), NULL); - } - - if (m_videoSettings.frameRate() > 0.001) { - QPair<int,int> rate = rateAsRational(); - - //qDebug() << "frame rate:" << num << denum; - - gst_structure_set(structure, "framerate", GST_TYPE_FRACTION, rate.first, rate.second, NULL); - } - - gst_caps_append_structure(caps,structure); - } - - //qDebug() << "set video caps filter:" << gst_caps_to_string(caps); - - g_object_set(G_OBJECT(capsFilter), "caps", caps, NULL); - } - - return GST_ELEMENT(encoderBin); -} - -QPair<int,int> QGstreamerVideoEncode::rateAsRational() const -{ - qreal frameRate = m_videoSettings.frameRate(); - - if (frameRate > 0.001) { - //convert to rational number - QList<int> denumCandidates; - denumCandidates << 1 << 2 << 3 << 5 << 10 << 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> QGstreamerVideoEncode::supportedStreamTypes(const QString &codecName) const -{ - return m_streamTypes.value(codecName); -} diff --git a/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.h b/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.h deleted file mode 100644 index f2b7a41..0000000 --- a/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.h +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERVIDEOENCODE_H -#define QGSTREAMERVIDEOENCODE_H - -#include <qvideoencodercontrol.h> -class QGstreamerCaptureSession; - -#include <QtCore/qstringlist.h> -#include <QtCore/qmap.h> -#include <QtCore/qset.h> - -#include <gst/gst.h> - -QT_USE_NAMESPACE - -class QGstreamerVideoEncode : public QVideoEncoderControl -{ - Q_OBJECT -public: - QGstreamerVideoEncode(QGstreamerCaptureSession *session); - virtual ~QGstreamerVideoEncode(); - - 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() 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; - -private: - QGstreamerCaptureSession *m_session; - - QStringList m_codecs; - QMap<QString,QString> m_codecDescriptions; - QMap<QString,QByteArray> m_elementNames; - QMap<QString,QStringList> m_codecOptions; - - QVideoEncoderSettings m_videoSettings; - QMap<QString, QMap<QString, QVariant> > m_options; - QMap<QString, QSet<QString> > m_streamTypes; -}; - -#endif diff --git a/src/plugins/gstreamer/mediaplayer/mediaplayer.pri b/src/plugins/gstreamer/mediaplayer/mediaplayer.pri deleted file mode 100644 index 310ed6f..0000000 --- a/src/plugins/gstreamer/mediaplayer/mediaplayer.pri +++ /dev/null @@ -1,30 +0,0 @@ -INCLUDEPATH += $$PWD - -DEFINES += QMEDIA_GSTREAMER_PLAYER - -contains(config_test_gstreamer_appsrc, yes) { - HEADERS += $$PWD/qgstappsrc.h - SOURCES += $$PWD/qgstappsrc.cpp - - DEFINES += HAVE_GST_APPSRC - - LIBS += -lgstapp-0.10 -} - -HEADERS += \ - $$PWD/qgstreamerplayercontrol.h \ - $$PWD/qgstreamerplayerservice.h \ - $$PWD/qgstreamerplayersession.h \ - $$PWD/qgstreamerstreamscontrol.h \ - $$PWD/qgstreamermetadataprovider.h \ - $$PWD/playerresourcepolicy.h - -SOURCES += \ - $$PWD/qgstreamerplayercontrol.cpp \ - $$PWD/qgstreamerplayerservice.cpp \ - $$PWD/qgstreamerplayersession.cpp \ - $$PWD/qgstreamerstreamscontrol.cpp \ - $$PWD/qgstreamermetadataprovider.cpp \ - $$PWD/playerresourcepolicy.cpp - - diff --git a/src/plugins/gstreamer/mediaplayer/playerresourcepolicy.cpp b/src/plugins/gstreamer/mediaplayer/playerresourcepolicy.cpp deleted file mode 100644 index 8b49cfc..0000000 --- a/src/plugins/gstreamer/mediaplayer/playerresourcepolicy.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "playerresourcepolicy.h" - -//#define DEBUG_RESOURCE_POLICY -#include <QtCore/qdebug.h> - -#ifdef HAVE_RESOURCE_POLICY -#include <policy/resource.h> -#include <policy/resources.h> -#include <policy/resource-set.h> -#endif - -PlayerResourcePolicy::PlayerResourcePolicy(QObject *parent) : - QObject(parent), - m_videoEnabled(true), - m_resourceSet(0), - m_status(PlayerResourcePolicy::Initial) -{ -#ifdef HAVE_RESOURCE_POLICY - m_resourceSet = new ResourcePolicy::ResourceSet("player", this); - m_resourceSet->setAlwaysReply(); - - ResourcePolicy::AudioResource *audioResource = new ResourcePolicy::AudioResource("player"); - audioResource->setProcessID(QCoreApplication::applicationPid()); - audioResource->setStreamTag("media.name", "*"); - m_resourceSet->addResourceObject(audioResource); - - m_resourceSet->addResource(ResourcePolicy::VideoPlaybackType); - m_resourceSet->update(); - - connect(m_resourceSet, SIGNAL(resourcesGranted(const QList<ResourcePolicy::ResourceType>)), - this, SLOT(handleResourcesGranted())); - connect(m_resourceSet, SIGNAL(resourcesDenied()), - this, SLOT(handleResourcesDenied())); - connect(m_resourceSet, SIGNAL(lostResources()), - this, SLOT(handleResourcesLost())); - connect(m_resourceSet, SIGNAL(resourcesReleasedByManager()), - this, SLOT(handleResourcesLost())); -#endif -} - -PlayerResourcePolicy::~PlayerResourcePolicy() -{ -} - -bool PlayerResourcePolicy::isVideoEnabled() const -{ - return m_videoEnabled; -} - -void PlayerResourcePolicy::setVideoEnabled(bool enabled) -{ - if (m_videoEnabled != enabled) { - m_videoEnabled = enabled; - -#ifdef HAVE_RESOURCE_POLICY - if (enabled) - m_resourceSet->addResource(ResourcePolicy::VideoPlaybackType); - else - m_resourceSet->deleteResource(ResourcePolicy::VideoPlaybackType); - - m_resourceSet->update(); -#endif - } -} - -void PlayerResourcePolicy::acquire() -{ -#ifdef HAVE_RESOURCE_POLICY - -#ifdef DEBUG_RESOURCE_POLICY - qDebug() << Q_FUNC_INFO << "Acquire resource"; -#endif - m_status = RequestedResource; - m_resourceSet->acquire(); -#else - m_status = GrantedResource; -#endif -} - -void PlayerResourcePolicy::release() -{ -#ifdef HAVE_RESOURCE_POLICY - -#ifdef DEBUG_RESOURCE_POLICY - qDebug() << Q_FUNC_INFO << "Release resource"; -#endif - - m_resourceSet->release(); -#endif - m_status = Initial; - -} - -bool PlayerResourcePolicy::isGranted() const -{ - return m_status == GrantedResource; -} - -bool PlayerResourcePolicy::isRequested() const -{ - return m_status == RequestedResource; -} - -void PlayerResourcePolicy::handleResourcesGranted() -{ - m_status = GrantedResource; -#ifdef DEBUG_RESOURCE_POLICY - qDebug() << Q_FUNC_INFO << "Resource granted"; -#endif - emit resourcesGranted(); -} - -void PlayerResourcePolicy::handleResourcesDenied() -{ - m_status = Initial; -#ifdef DEBUG_RESOURCE_POLICY - qDebug() << Q_FUNC_INFO << "Resource denied"; -#endif - emit resourcesDenied(); -} - -void PlayerResourcePolicy::handleResourcesLost() -{ -#ifdef DEBUG_RESOURCE_POLICY - qDebug() << Q_FUNC_INFO << "Resource lost"; -#endif - if (m_status != Initial) { - m_status = Initial; - emit resourcesLost(); - } - -#ifdef HAVE_RESOURCE_POLICY - m_resourceSet->release(); -#endif -} diff --git a/src/plugins/gstreamer/mediaplayer/playerresourcepolicy.h b/src/plugins/gstreamer/mediaplayer/playerresourcepolicy.h deleted file mode 100644 index d51fd2d..0000000 --- a/src/plugins/gstreamer/mediaplayer/playerresourcepolicy.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PLAYERRESOURCEPOLICY_H -#define PLAYERRESOURCEPOLICY_H - -#include <QtCore/qobject.h> - -namespace ResourcePolicy { -class ResourceSet; -}; - -class PlayerResourcePolicy : public QObject -{ - Q_OBJECT -public: - PlayerResourcePolicy(QObject *parent = 0); - ~PlayerResourcePolicy(); - - bool isVideoEnabled() const; - bool isGranted() const; - bool isRequested() const; - -Q_SIGNALS: - void resourcesDenied(); - void resourcesGranted(); - void resourcesLost(); - -public Q_SLOTS: - void acquire(); - void release(); - - void setVideoEnabled(bool enabled); - -private Q_SLOTS: - void handleResourcesGranted(); - void handleResourcesDenied(); - void handleResourcesLost(); - -private: - enum ResourceStatus { - Initial = 0, - RequestedResource, - GrantedResource - }; - - bool m_videoEnabled; - ResourcePolicy::ResourceSet *m_resourceSet; - ResourceStatus m_status; -}; - -#endif diff --git a/src/plugins/gstreamer/mediaplayer/qgstappsrc.cpp b/src/plugins/gstreamer/mediaplayer/qgstappsrc.cpp deleted file mode 100644 index dc1f21e..0000000 --- a/src/plugins/gstreamer/mediaplayer/qgstappsrc.cpp +++ /dev/null @@ -1,227 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QDebug> - -#include "qgstappsrc.h" -#include <QtNetwork> - -QGstAppSrc::QGstAppSrc(QObject *parent) - :QObject(parent) - ,m_stream(0) - ,m_appSrc(0) - ,m_sequential(false) - ,m_maxBytes(0) - ,m_setup(false) - ,m_dataRequestSize(-1) - ,m_dataRequested(false) - ,m_enoughData(false) - ,m_forceData(false) -{ -} - -QGstAppSrc::~QGstAppSrc() -{ - if (m_appSrc) - gst_object_unref(G_OBJECT(m_appSrc)); -} - -bool QGstAppSrc::setup(GstElement* appsrc) -{ - if (m_setup || m_stream == 0 || appsrc == 0) - return false; - - m_appSrc = GST_APP_SRC(appsrc); - m_callbacks.need_data = &QGstAppSrc::on_need_data; - m_callbacks.enough_data = &QGstAppSrc::on_enough_data; - m_callbacks.seek_data = &QGstAppSrc::on_seek_data; - gst_app_src_set_callbacks(m_appSrc, (GstAppSrcCallbacks*)&m_callbacks, this, (GDestroyNotify)&QGstAppSrc::destroy_notify); - - g_object_get(G_OBJECT(m_appSrc), "max-bytes", &m_maxBytes, NULL); - - if (m_sequential) - m_streamType = GST_APP_STREAM_TYPE_STREAM; - else - m_streamType = GST_APP_STREAM_TYPE_RANDOM_ACCESS; - gst_app_src_set_stream_type(m_appSrc, m_streamType); - gst_app_src_set_size(m_appSrc, (m_sequential) ? -1 : m_stream->size()); - - return m_setup = true; -} - -void QGstAppSrc::setStream(QIODevice *stream) -{ - if (stream == 0) - return; - if (m_stream) { - disconnect(m_stream, SIGNAL(readyRead()), this, SLOT(onDataReady())); - disconnect(m_stream, SIGNAL(destroyed()), this, SLOT(streamDestroyed())); - } - if (m_appSrc) - gst_object_unref(G_OBJECT(m_appSrc)); - - m_dataRequestSize = -1; - m_dataRequested = false; - m_enoughData = false; - m_forceData = false; - m_maxBytes = 0; - - m_appSrc = 0; - m_stream = stream; - connect(m_stream, SIGNAL(destroyed()), SLOT(streamDestroyed())); - connect(m_stream, SIGNAL(readyRead()), this, SLOT(onDataReady())); - m_sequential = m_stream->isSequential(); - m_setup = false; -} - -QIODevice *QGstAppSrc::stream() const -{ - return m_stream; -} - -GstAppSrc *QGstAppSrc::element() -{ - return m_appSrc; -} - -void QGstAppSrc::onDataReady() -{ - if (!m_enoughData) { - m_dataRequested = true; - pushDataToAppSrc(); - } -} - -void QGstAppSrc::streamDestroyed() -{ - if (sender() == m_stream) { - m_stream = 0; - sendEOS(); - } -} - -void QGstAppSrc::pushDataToAppSrc() -{ - if (!isStreamValid() || !m_setup) - return; - - if (m_dataRequested && !m_enoughData) { - qint64 size; - if (m_dataRequestSize == (unsigned int)-1) - size = qMin(m_stream->bytesAvailable(), queueSize()); - else - size = qMin(m_stream->bytesAvailable(), (qint64)m_dataRequestSize); - void *data = g_malloc(size); - GstBuffer* buffer = gst_app_buffer_new(data, size, g_free, data); - buffer->offset = m_stream->pos(); - qint64 bytesRead = m_stream->read((char*)GST_BUFFER_DATA(buffer), size); - buffer->offset_end = buffer->offset + bytesRead - 1; - - if (bytesRead > 0) { - m_dataRequested = false; - m_enoughData = false; - GstFlowReturn ret = gst_app_src_push_buffer (GST_APP_SRC (element()), buffer); - if (ret == GST_FLOW_ERROR) { - qWarning()<<"appsrc: push buffer error"; - } else if (ret == GST_FLOW_WRONG_STATE) { - qWarning()<<"appsrc: push buffer wrong state"; - } else if (ret == GST_FLOW_RESEND) { - qWarning()<<"appsrc: push buffer resend"; - } - } - } else if (m_stream->atEnd()) { - sendEOS(); - } -} - -bool QGstAppSrc::doSeek(qint64 value) -{ - if (isStreamValid()) - return stream()->seek(value); - return false; -} - - -gboolean QGstAppSrc::on_seek_data(GstAppSrc *element, guint64 arg0, gpointer userdata) -{ - Q_UNUSED(element); - QGstAppSrc *self = reinterpret_cast<QGstAppSrc*>(userdata); - if (self && self->isStreamValid()) { - if (!self->stream()->isSequential()) - QMetaObject::invokeMethod(self, "doSeek", Qt::AutoConnection, Q_ARG(qint64, arg0)); - } - else - return false; - - return true; -} - -void QGstAppSrc::on_enough_data(GstAppSrc *element, gpointer userdata) -{ - Q_UNUSED(element); - QGstAppSrc *self = reinterpret_cast<QGstAppSrc*>(userdata); - if (self) - self->enoughData() = true; -} - -void QGstAppSrc::on_need_data(GstAppSrc *element, guint arg0, gpointer userdata) -{ - Q_UNUSED(element); - QGstAppSrc *self = reinterpret_cast<QGstAppSrc*>(userdata); - if (self) { - self->dataRequested() = true; - self->enoughData() = false; - self->dataRequestSize()= arg0; - QMetaObject::invokeMethod(self, "pushDataToAppSrc", Qt::AutoConnection); - } -} - -void QGstAppSrc::destroy_notify(gpointer data) -{ - Q_UNUSED(data); -} - -void QGstAppSrc::sendEOS() -{ - gst_app_src_end_of_stream(GST_APP_SRC(m_appSrc)); - if (isStreamValid() && !stream()->isSequential()) - stream()->reset(); -} diff --git a/src/plugins/gstreamer/mediaplayer/qgstappsrc.h b/src/plugins/gstreamer/mediaplayer/qgstappsrc.h deleted file mode 100644 index a636dde..0000000 --- a/src/plugins/gstreamer/mediaplayer/qgstappsrc.h +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTAPPSRC_H -#define QGSTAPPSRC_H - -#include <QtCore/qobject.h> -#include <QtCore/qiodevice.h> - -#include <gst/gst.h> -#include <gst/app/gstappsrc.h> -#include <gst/app/gstappbuffer.h> - -class QGstAppSrc : public QObject -{ - Q_OBJECT -public: - QGstAppSrc(QObject *parent = 0); - ~QGstAppSrc(); - - bool setup(GstElement *); - bool isReady() const { return m_setup; } - - void setStream(QIODevice *); - QIODevice *stream() const; - - GstAppSrc *element(); - - qint64 queueSize() const { return m_maxBytes; } - - bool& enoughData() { return m_enoughData; } - bool& dataRequested() { return m_dataRequested; } - unsigned int& dataRequestSize() { return m_dataRequestSize; } - - bool isStreamValid() const - { - return m_stream != 0 && - m_stream->isOpen(); - } - -private slots: - void pushDataToAppSrc(); - bool doSeek(qint64); - void onDataReady(); - - void streamDestroyed(); -private: - static gboolean on_seek_data(GstAppSrc *element, guint64 arg0, gpointer userdata); - static void on_enough_data(GstAppSrc *element, gpointer userdata); - static void on_need_data(GstAppSrc *element, uint arg0, gpointer userdata); - static void destroy_notify(gpointer data); - - void sendEOS(); - - QIODevice *m_stream; - GstAppSrc *m_appSrc; - bool m_sequential; - GstAppStreamType m_streamType; - GstAppSrcCallbacks m_callbacks; - qint64 m_maxBytes; - bool m_setup; - unsigned int m_dataRequestSize; - bool m_dataRequested; - bool m_enoughData; - bool m_forceData; -}; - -#endif diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamermetadataprovider.cpp b/src/plugins/gstreamer/mediaplayer/qgstreamermetadataprovider.cpp deleted file mode 100644 index 6670672..0000000 --- a/src/plugins/gstreamer/mediaplayer/qgstreamermetadataprovider.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamermetadataprovider.h" -#include "qgstreamerplayersession.h" -#include <QDebug> - -#include <gst/gstversion.h> - -struct QGstreamerMetaDataKeyLookup -{ - QtMultimedia::MetaData key; - const char *token; -}; - -static const QGstreamerMetaDataKeyLookup qt_gstreamerMetaDataKeys[] = -{ - { QtMultimedia::Title, GST_TAG_TITLE }, - //{ QtMultimedia::SubTitle, 0 }, - //{ QtMultimedia::Author, 0 }, - { QtMultimedia::Comment, GST_TAG_COMMENT }, - { QtMultimedia::Description, GST_TAG_DESCRIPTION }, - //{ QtMultimedia::Category, 0 }, - { QtMultimedia::Genre, GST_TAG_GENRE }, - { QtMultimedia::Year, "year" }, - //{ QtMultimedia::UserRating, 0 }, - - { QtMultimedia::Language, GST_TAG_LANGUAGE_CODE }, - - { QtMultimedia::Publisher, GST_TAG_ORGANIZATION }, - { QtMultimedia::Copyright, GST_TAG_COPYRIGHT }, - //{ QtMultimedia::ParentalRating, 0 }, - //{ QtMultimedia::RatingOrganisation, 0 }, - - // Media - //{ QtMultimedia::Size, 0 }, - //{ QtMultimedia::MediaType, 0 }, - { QtMultimedia::Duration, GST_TAG_DURATION }, - - // Audio - { QtMultimedia::AudioBitRate, GST_TAG_BITRATE }, - { QtMultimedia::AudioCodec, GST_TAG_AUDIO_CODEC }, - //{ QtMultimedia::ChannelCount, 0 }, - //{ QtMultimedia::SampleRate, 0 }, - - // Music - { QtMultimedia::AlbumTitle, GST_TAG_ALBUM }, - { QtMultimedia::AlbumArtist, GST_TAG_ARTIST}, - { QtMultimedia::ContributingArtist, GST_TAG_PERFORMER }, -#if (GST_VERSION_MAJOR >= 0) && (GST_VERSION_MINOR >= 10) && (GST_VERSION_MICRO >= 19) - { QtMultimedia::Composer, GST_TAG_COMPOSER }, -#endif - //{ QtMultimedia::Conductor, 0 }, - //{ QtMultimedia::Lyrics, 0 }, - //{ QtMultimedia::Mood, 0 }, - { QtMultimedia::TrackNumber, GST_TAG_TRACK_NUMBER }, - - //{ QtMultimedia::CoverArtUrlSmall, 0 }, - //{ QtMultimedia::CoverArtUrlLarge, 0 }, - - // Image/Video - { QtMultimedia::Resolution, "resolution" }, - { QtMultimedia::PixelAspectRatio, "pixel-aspect-ratio" }, - - // Video - //{ QtMultimedia::VideoFrameRate, 0 }, - //{ QtMultimedia::VideoBitRate, 0 }, - { QtMultimedia::VideoCodec, GST_TAG_VIDEO_CODEC }, - - //{ QtMultimedia::PosterUrl, 0 }, - - // Movie - //{ QtMultimedia::ChapterNumber, 0 }, - //{ QtMultimedia::Director, 0 }, - { QtMultimedia::LeadPerformer, GST_TAG_PERFORMER }, - //{ QtMultimedia::Writer, 0 }, - - // Photos - //{ QtMultimedia::CameraManufacturer, 0 }, - //{ QtMultimedia::CameraModel, 0 }, - //{ QtMultimedia::Event, 0 }, - //{ QtMultimedia::Subject, 0 } -}; - -QGstreamerMetaDataProvider::QGstreamerMetaDataProvider(QGstreamerPlayerSession *session, QObject *parent) - :QMetaDataReaderControl(parent), m_session(session) -{ - connect(m_session, SIGNAL(tagsChanged()), SLOT(updateTags())); -} - -QGstreamerMetaDataProvider::~QGstreamerMetaDataProvider() -{ -} - -bool QGstreamerMetaDataProvider::isMetaDataAvailable() const -{ - return !m_session->tags().isEmpty(); -} - -bool QGstreamerMetaDataProvider::isWritable() const -{ - return false; -} - -QVariant QGstreamerMetaDataProvider::metaData(QtMultimedia::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) { - return m_session->tags().value(QByteArray(qt_gstreamerMetaDataKeys[i].token)); - } - } - return QVariant(); -} - -QList<QtMultimedia::MetaData> QGstreamerMetaDataProvider::availableMetaData() const -{ - static QMap<QByteArray, QtMultimedia::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<QtMultimedia::MetaData> res; - foreach (const QByteArray &key, m_session->tags().keys()) { - QtMultimedia::MetaData tag = keysMap.value(key, QtMultimedia::MetaData(-1)); - if (tag != -1) - res.append(tag); - } - - return res; -} - -QVariant QGstreamerMetaDataProvider::extendedMetaData(const QString &key) const -{ - return m_session->tags().value(key.toLatin1()); -} - -QStringList QGstreamerMetaDataProvider::availableExtendedMetaData() const -{ - QStringList res; - foreach (const QByteArray &key, m_session->tags().keys()) - res.append(QString(key)); - - return res; -} - -void QGstreamerMetaDataProvider::updateTags() -{ - emit metaDataChanged(); -} diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamermetadataprovider.h b/src/plugins/gstreamer/mediaplayer/qgstreamermetadataprovider.h deleted file mode 100644 index efba79c..0000000 --- a/src/plugins/gstreamer/mediaplayer/qgstreamermetadataprovider.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERMETADATAPROVIDER_H -#define QGSTREAMERMETADATAPROVIDER_H - -#include <qmetadatareadercontrol.h> - -QT_USE_NAMESPACE - -class QGstreamerPlayerSession; - -class QGstreamerMetaDataProvider : public QMetaDataReaderControl -{ - Q_OBJECT -public: - QGstreamerMetaDataProvider( QGstreamerPlayerSession *session, QObject *parent ); - virtual ~QGstreamerMetaDataProvider(); - - bool isMetaDataAvailable() const; - bool isWritable() const; - - QVariant metaData(QtMultimedia::MetaData key) const; - QList<QtMultimedia::MetaData> availableMetaData() const; - - QVariant extendedMetaData(const QString &key) const ; - QStringList availableExtendedMetaData() const; - -private slots: - void updateTags(); - -private: - QGstreamerPlayerSession *m_session; -}; - -#endif // QGSTREAMERMETADATAPROVIDER_H diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayercontrol.cpp b/src/plugins/gstreamer/mediaplayer/qgstreamerplayercontrol.cpp deleted file mode 100644 index 6198163..0000000 --- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayercontrol.cpp +++ /dev/null @@ -1,775 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamerplayercontrol.h" -#include "qgstreamerplayersession.h" -#include "playerresourcepolicy.h" - -#include <qmediaplaylistnavigator.h> - - -#include <QtCore/qdir.h> -#include <QtCore/qsocketnotifier.h> -#include <QtCore/qurl.h> -#include <QtCore/qdebug.h> - -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> - -//#define DEBUG_PLAYBIN - -QGstreamerPlayerControl::QGstreamerPlayerControl(QGstreamerPlayerSession *session, QObject *parent) - : QMediaPlayerControl(parent) - , m_ownStream(false) - , m_session(session) - , m_state(QMediaPlayer::StoppedState) - , m_mediaStatus(QMediaPlayer::NoMedia) - , m_bufferProgress(-1) - , m_seekToStartPending(false) - , m_pendingSeekPosition(-1) - , m_stream(0) - , m_fifoNotifier(0) - , m_fifoCanWrite(false) - , m_bufferSize(0) - , m_bufferOffset(0) -{ - m_fifoFd[0] = -1; - m_fifoFd[1] = -1; - - m_resources = new PlayerResourcePolicy(this); - - connect(m_session, SIGNAL(positionChanged(qint64)), - this, SLOT(updatePosition(qint64))); - connect(m_session, SIGNAL(durationChanged(qint64)), - this, SIGNAL(durationChanged(qint64))); - connect(m_session, SIGNAL(mutedStateChanged(bool)), - this, SIGNAL(mutedChanged(bool))); - connect(m_session, SIGNAL(volumeChanged(int)), - this, SIGNAL(volumeChanged(int))); - connect(m_session, SIGNAL(stateChanged(QMediaPlayer::State)), - this, SLOT(updateSessionState(QMediaPlayer::State))); - connect(m_session,SIGNAL(bufferingProgressChanged(int)), - this, SLOT(setBufferProgress(int))); - connect(m_session, SIGNAL(playbackFinished()), - this, SLOT(processEOS())); - connect(m_session, SIGNAL(audioAvailableChanged(bool)), - this, SIGNAL(audioAvailableChanged(bool))); - connect(m_session, SIGNAL(videoAvailableChanged(bool)), - this, SIGNAL(videoAvailableChanged(bool))); - connect(m_session, SIGNAL(seekableChanged(bool)), - this, SIGNAL(seekableChanged(bool))); - connect(m_session, SIGNAL(error(int,QString)), - this, SIGNAL(error(int,QString))); - connect(m_session, SIGNAL(invalidMedia()), - this, SLOT(handleInvalidMedia())); - connect(m_session, SIGNAL(playbackRateChanged(qreal)), - this, SIGNAL(playbackRateChanged(qreal))); - connect(m_session, SIGNAL(seekableChanged(bool)), - this, SLOT(applyPendingSeek(bool))); - - connect(m_resources, SIGNAL(resourcesGranted()), SLOT(handleResourcesGranted())); - connect(m_resources, SIGNAL(resourcesDenied()), SLOT(handleResourcesLost())); - connect(m_resources, SIGNAL(resourcesLost()), SLOT(handleResourcesLost())); -} - -QGstreamerPlayerControl::~QGstreamerPlayerControl() -{ - if (m_fifoFd[0] >= 0) { - ::close(m_fifoFd[0]); - ::close(m_fifoFd[1]); - m_fifoFd[0] = -1; - m_fifoFd[1] = -1; - } -} - -qint64 QGstreamerPlayerControl::position() const -{ - return m_seekToStartPending ? 0 : m_session->position(); -} - -qint64 QGstreamerPlayerControl::duration() const -{ - return m_session->duration(); -} - -QMediaPlayer::State QGstreamerPlayerControl::state() const -{ - return m_state; -} - -QMediaPlayer::MediaStatus QGstreamerPlayerControl::mediaStatus() const -{ - return m_mediaStatus; -} - -int QGstreamerPlayerControl::bufferStatus() const -{ - if (m_bufferProgress == -1) { - return m_session->state() == QMediaPlayer::StoppedState ? 0 : 100; - } else - return m_bufferProgress; -} - -int QGstreamerPlayerControl::volume() const -{ - return m_session->volume(); -} - -bool QGstreamerPlayerControl::isMuted() const -{ - return m_session->isMuted(); -} - -bool QGstreamerPlayerControl::isSeekable() const -{ - return m_session->isSeekable(); -} - -QMediaTimeRange QGstreamerPlayerControl::availablePlaybackRanges() const -{ - return m_session->availablePlaybackRanges(); -} - -qreal QGstreamerPlayerControl::playbackRate() const -{ - return m_session->playbackRate(); -} - -void QGstreamerPlayerControl::setPlaybackRate(qreal rate) -{ - m_session->setPlaybackRate(rate); -} - -void QGstreamerPlayerControl::setPosition(qint64 pos) -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO << pos/1000.0; -#endif - - pushState(); - - if (m_mediaStatus == QMediaPlayer::EndOfMedia) { - m_mediaStatus = QMediaPlayer::LoadedMedia; - m_seekToStartPending = true; - } - - if (m_session->isSeekable() && m_session->seek(pos)) { - m_seekToStartPending = false; - } else { - m_pendingSeekPosition = pos; - //don't display the first video frame since it's not what user requested. - m_session->showPrerollFrames(false); - } - - popAndNotifyState(); -} - -void QGstreamerPlayerControl::play() -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO; -#endif - - playOrPause(QMediaPlayer::PlayingState); -} - -void QGstreamerPlayerControl::pause() -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO; -#endif - - playOrPause(QMediaPlayer::PausedState); -} - -void QGstreamerPlayerControl::playOrPause(QMediaPlayer::State newState) -{ - if (m_mediaStatus == QMediaPlayer::NoMedia) - return; - - pushState(); -#ifdef Q_WS_MAEMO_6 - //this is a work around for the gstreamer bug, - //should be remove once it get fixed - if (newState == QMediaPlayer::PlayingState && m_mediaStatus == QMediaPlayer::InvalidMedia) { - setMedia(m_currentResource, m_stream); - } -#endif - - if (m_mediaStatus == QMediaPlayer::EndOfMedia) { - m_mediaStatus = QMediaPlayer::BufferedMedia; - m_seekToStartPending = true; - } - - if (!m_resources->isGranted() && !m_resources->isRequested()) - m_resources->acquire(); - - if (m_resources->isGranted()) { - if (m_seekToStartPending) { - m_session->pause(); - if (!m_session->seek(0)) { - m_bufferProgress = -1; - m_session->stop(); - m_mediaStatus = QMediaPlayer::LoadingMedia; - } - m_seekToStartPending = false; - } - - bool ok = false; - - //To prevent displaying the first video frame when playback is resumed - //the pipeline is paused instead of playing, seeked to requested position, - //and after seeking is finished (position updated) playback is restarted - //with show-preroll-frame enabled. - if (newState == QMediaPlayer::PlayingState && m_pendingSeekPosition == -1) - ok = m_session->play(); - else - ok = m_session->pause(); - - if (!ok) - newState = QMediaPlayer::StoppedState; - } - - if (m_mediaStatus == QMediaPlayer::InvalidMedia) - m_mediaStatus = QMediaPlayer::LoadingMedia; - - m_state = newState; - - if (m_mediaStatus == QMediaPlayer::EndOfMedia || m_mediaStatus == QMediaPlayer::LoadedMedia) { - if (m_bufferProgress == -1 || m_bufferProgress == 100) - m_mediaStatus = QMediaPlayer::BufferedMedia; - else - m_mediaStatus = QMediaPlayer::BufferingMedia; - } - - popAndNotifyState(); - - emit positionChanged(position()); -} - -void QGstreamerPlayerControl::stop() -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO; -#endif - - pushState(); - - if (m_state != QMediaPlayer::StoppedState) { - m_state = QMediaPlayer::StoppedState; - if (m_resources->isGranted()) - m_session->pause(); - - if (m_mediaStatus != QMediaPlayer::EndOfMedia) { - m_seekToStartPending = true; - emit positionChanged(position()); - } - } - - popAndNotifyState(); -} - -void QGstreamerPlayerControl::setVolume(int volume) -{ - m_session->setVolume(volume); -} - -void QGstreamerPlayerControl::setMuted(bool muted) -{ - m_session->setMuted(muted); -} - -QMediaContent QGstreamerPlayerControl::media() const -{ - return m_currentResource; -} - -const QIODevice *QGstreamerPlayerControl::mediaStream() const -{ - return m_stream; -} - -void QGstreamerPlayerControl::setMedia(const QMediaContent &content, QIODevice *stream) -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO; -#endif - - pushState(); - - m_state = QMediaPlayer::StoppedState; - QMediaContent oldMedia = m_currentResource; - m_pendingSeekPosition = -1; - m_session->showPrerollFrames(true); - - if (!content.isNull() || stream) { - if (!m_resources->isRequested() && !m_resources->isGranted()) - m_resources->acquire(); - - if (!m_resources->isGranted()) { - m_currentResource = content; - m_stream = stream; - - m_state = QMediaPlayer::StoppedState; - m_mediaStatus = QMediaPlayer::LoadingMedia; - if (m_currentResource != oldMedia) - emit mediaChanged(m_currentResource); - popAndNotifyState(); - return; - } - } else { - m_resources->release(); - } - - m_session->stop(); - - bool userStreamValid = false; - - if (m_bufferProgress != -1) { - m_bufferProgress = -1; - emit bufferStatusChanged(0); - } - - if (m_stream) { -#if !defined(HAVE_GST_APPSRC) - closeFifo(); - - disconnect(m_stream, SIGNAL(readyRead()), this, SLOT(writeFifo())); -#endif - - if (m_ownStream) - delete m_stream; - m_stream = 0; - m_ownStream = false; - } - - // If the canonical URL refers to a Qt resource, open with QFile and use - // the stream playback capability to play. - if (stream == 0 && content.canonicalUrl().scheme() == QLatin1String("qrc")) { - stream = new QFile(QLatin1Char(':') + content.canonicalUrl().path(), this); - if (!stream->open(QIODevice::ReadOnly)) { - delete stream; - m_mediaStatus = QMediaPlayer::InvalidMedia; - m_currentResource = content; - emit mediaChanged(m_currentResource); - emit error(QMediaPlayer::FormatError, tr("Attempting to play invalid Qt resource")); - if (m_state != QMediaPlayer::PlayingState) - m_resources->release(); - popAndNotifyState(); - return; - } - m_ownStream = true; - } - - m_currentResource = content; - m_stream = stream; - m_seekToStartPending = false; - - QNetworkRequest request; - - if (m_stream) { -#if !defined(HAVE_GST_APPSRC) - if (m_stream->isReadable() && openFifo()) { - request = QNetworkRequest(QUrl(QString(QLatin1String("fd://%1")).arg(m_fifoFd[0]))); - } -#else - userStreamValid = stream->isOpen() && m_stream->isReadable(); - request = content.canonicalRequest(); -#endif - } else if (!content.isNull()) { - request = content.canonicalRequest(); - } - -#if !defined(HAVE_GST_APPSRC) - m_session->loadFromUri(request); -#else - if (m_stream) { - if (userStreamValid){ - m_session->loadFromStream(request, m_stream); - } else { - m_mediaStatus = QMediaPlayer::InvalidMedia; - emit error(QMediaPlayer::FormatError, tr("Attempting to play invalid user stream")); - if (m_state != QMediaPlayer::PlayingState) - m_resources->release(); - popAndNotifyState(); - return; - } - } else - m_session->loadFromUri(request); -#endif - -#if !defined(HAVE_GST_APPSRC) - if (m_fifoFd[1] >= 0) { - m_fifoCanWrite = true; - - writeFifo(); - } -#endif - -#if defined(HAVE_GST_APPSRC) - if (!request.url().isEmpty() || userStreamValid) { -#else - if (!request.url().isEmpty()) { -#endif - m_mediaStatus = QMediaPlayer::LoadingMedia; - m_session->pause(); - } else { - m_mediaStatus = QMediaPlayer::NoMedia; - setBufferProgress(0); - } - - if (m_currentResource != oldMedia) - emit mediaChanged(m_currentResource); - - emit positionChanged(position()); - - if (content.isNull() && !stream) - m_resources->release(); - - popAndNotifyState(); -} - -void QGstreamerPlayerControl::setVideoOutput(QObject *output) -{ - m_session->setVideoRenderer(output); -} - -bool QGstreamerPlayerControl::isAudioAvailable() const -{ - return m_session->isAudioAvailable(); -} - -bool QGstreamerPlayerControl::isVideoAvailable() const -{ - return m_session->isVideoAvailable(); -} - -void QGstreamerPlayerControl::updateSessionState(QMediaPlayer::State state) -{ - pushState(); - - if (state == QMediaPlayer::StoppedState) - m_state = QMediaPlayer::StoppedState; - - updateMediaStatus(); - - popAndNotifyState(); -} - -void QGstreamerPlayerControl::updateMediaStatus() -{ - pushState(); - QMediaPlayer::MediaStatus oldStatus = m_mediaStatus; - - switch (m_session->state()) { - case QMediaPlayer::StoppedState: - if (m_currentResource.isNull()) - m_mediaStatus = QMediaPlayer::NoMedia; - else if (oldStatus != QMediaPlayer::InvalidMedia) - m_mediaStatus = QMediaPlayer::LoadingMedia; - break; - - case QMediaPlayer::PlayingState: - case QMediaPlayer::PausedState: - if (m_state == QMediaPlayer::StoppedState) { - m_mediaStatus = QMediaPlayer::LoadedMedia; - } else { - if (m_bufferProgress == -1 || m_bufferProgress == 100) - m_mediaStatus = QMediaPlayer::BufferedMedia; - else - m_mediaStatus = QMediaPlayer::StalledMedia; - } - break; - } - - if (m_state == QMediaPlayer::PlayingState && !m_resources->isGranted()) - m_mediaStatus = QMediaPlayer::StalledMedia; - - //EndOfMedia status should be kept, until reset by pause, play or setMedia - if (oldStatus == QMediaPlayer::EndOfMedia) - m_mediaStatus = QMediaPlayer::EndOfMedia; - - popAndNotifyState(); -} - -void QGstreamerPlayerControl::processEOS() -{ - pushState(); - m_mediaStatus = QMediaPlayer::EndOfMedia; - emit positionChanged(position()); - stop(); - popAndNotifyState(); -} - -void QGstreamerPlayerControl::setBufferProgress(int progress) -{ - if (m_bufferProgress == progress || m_mediaStatus == QMediaPlayer::NoMedia) - return; - -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO << progress; -#endif - m_bufferProgress = progress; - - if (m_resources->isGranted()) { - if (m_state == QMediaPlayer::PlayingState && - m_bufferProgress == 100 && - m_session->state() != QMediaPlayer::PlayingState) - m_session->play(); - - if (!m_session->isLiveSource() && m_bufferProgress < 100 && - (m_session->state() == QMediaPlayer::PlayingState || - m_session->pendingState() == QMediaPlayer::PlayingState)) - m_session->pause(); - } - - updateMediaStatus(); - - emit bufferStatusChanged(m_bufferProgress); -} - -void QGstreamerPlayerControl::writeFifo() -{ - if (m_fifoCanWrite) { - qint64 bytesToRead = qMin<qint64>( - m_stream->bytesAvailable(), PIPE_BUF - m_bufferSize); - - if (bytesToRead > 0) { - int bytesRead = m_stream->read(&m_buffer[m_bufferOffset + m_bufferSize], bytesToRead); - - if (bytesRead > 0) - m_bufferSize += bytesRead; - } - - if (m_bufferSize > 0) { - int bytesWritten = ::write(m_fifoFd[1], &m_buffer[m_bufferOffset], size_t(m_bufferSize)); - - if (bytesWritten > 0) { - m_bufferOffset += bytesWritten; - m_bufferSize -= bytesWritten; - - if (m_bufferSize == 0) - m_bufferOffset = 0; - } else if (errno == EAGAIN) { - m_fifoCanWrite = false; - } else { - closeFifo(); - } - } - } - - m_fifoNotifier->setEnabled(m_stream->bytesAvailable() > 0); -} - -void QGstreamerPlayerControl::fifoReadyWrite(int socket) -{ - if (socket == m_fifoFd[1]) { - m_fifoCanWrite = true; - - writeFifo(); - } -} - -bool QGstreamerPlayerControl::openFifo() -{ - Q_ASSERT(m_fifoFd[0] < 0); - Q_ASSERT(m_fifoFd[1] < 0); - - if (::pipe(m_fifoFd) == 0) { - int flags = ::fcntl(m_fifoFd[1], F_GETFD); - - if (::fcntl(m_fifoFd[1], F_SETFD, flags | O_NONBLOCK) >= 0) { - m_fifoNotifier = new QSocketNotifier(m_fifoFd[1], QSocketNotifier::Write); - - connect(m_fifoNotifier, SIGNAL(activated(int)), this, SLOT(fifoReadyWrite(int))); - - return true; - } else { - qWarning("Failed to make pipe non blocking %d", errno); - - ::close(m_fifoFd[0]); - ::close(m_fifoFd[1]); - - m_fifoFd[0] = -1; - m_fifoFd[1] = -1; - - return false; - } - } else { - qWarning("Failed to create pipe %d", errno); - - return false; - } -} - -void QGstreamerPlayerControl::closeFifo() -{ - if (m_fifoFd[0] >= 0) { - delete m_fifoNotifier; - m_fifoNotifier = 0; - - ::close(m_fifoFd[0]); - ::close(m_fifoFd[1]); - m_fifoFd[0] = -1; - m_fifoFd[1] = -1; - - m_fifoCanWrite = false; - - m_bufferSize = 0; - m_bufferOffset = 0; - } -} - -void QGstreamerPlayerControl::applyPendingSeek(bool isSeekable) -{ - if (isSeekable && m_pendingSeekPosition != -1) - setPosition(m_pendingSeekPosition); -} - -void QGstreamerPlayerControl::handleInvalidMedia() -{ - pushState(); - m_mediaStatus = QMediaPlayer::InvalidMedia; - m_state = QMediaPlayer::StoppedState; - popAndNotifyState(); -} - -void QGstreamerPlayerControl::handleResourcesGranted() -{ - pushState(); - - QMediaPlayer::State state = m_state; - - //preserve m_pendingSeekPosition, it's reset on setMedia - qint64 pos = m_pendingSeekPosition; - setMedia(m_currentResource, m_stream); - - if (pos != -1) - setPosition(pos); - - if (state != QMediaPlayer::StoppedState) - playOrPause(state); - else - updateMediaStatus(); - - popAndNotifyState(); -} - -void QGstreamerPlayerControl::handleResourcesLost() -{ - //on resource lost the pipeline should be stopped - //player status is changed to paused - - pushState(); - QMediaPlayer::State oldState = m_state; - - qint64 pos = m_session->position(); - m_session->stop(); - m_pendingSeekPosition = pos; - //don't blink the first video frame after playback is restored - m_session->showPrerollFrames(false); - - if (oldState != QMediaPlayer::StoppedState ) - m_state = QMediaPlayer::PausedState; - - popAndNotifyState(); -} - -bool QGstreamerPlayerControl::isMediaDownloadEnabled() const -{ - return m_session->property("mediaDownloadEnabled").toBool(); -} - -void QGstreamerPlayerControl::setMediaDownloadEnabled(bool enabled) -{ - m_session->setProperty("mediaDownloadEnabled", enabled); -} - -void QGstreamerPlayerControl::pushState() -{ - m_stateStack.push(m_state); - m_mediaStatusStack.push(m_mediaStatus); -} - -void QGstreamerPlayerControl::popAndNotifyState() -{ - Q_ASSERT(!m_stateStack.isEmpty()); - - QMediaPlayer::State oldState = m_stateStack.pop(); - QMediaPlayer::MediaStatus oldMediaStatus = m_mediaStatusStack.pop(); - - if (m_stateStack.isEmpty()) { - if (m_state != oldState) { -#ifdef DEBUG_PLAYBIN - qDebug() << "State changed:" << m_state; -#endif - emit stateChanged(m_state); - } - - if (m_mediaStatus != oldMediaStatus) { -#ifdef DEBUG_PLAYBIN - qDebug() << "Media status changed:" << m_mediaStatus; -#endif - emit mediaStatusChanged(m_mediaStatus); - } - } -} - -void QGstreamerPlayerControl::updatePosition(qint64 pos) -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO << pos/1000.0 << "pending:" << m_pendingSeekPosition/1000.0; -#endif - - if (m_pendingSeekPosition != -1) { - //seek request is complete, it's safe to resume playback - //with prerolled frame displayed - m_pendingSeekPosition = -1; - m_session->showPrerollFrames(true); - if (m_state == QMediaPlayer::PlayingState) { - m_session->play(); - } - } - - emit positionChanged(pos); -} diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayercontrol.h b/src/plugins/gstreamer/mediaplayer/qgstreamerplayercontrol.h deleted file mode 100644 index ea02c97..0000000 --- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayercontrol.h +++ /dev/null @@ -1,158 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERPLAYERCONTROL_H -#define QGSTREAMERPLAYERCONTROL_H - -#include <QtCore/qobject.h> -#include <QtCore/qstack.h> - -#include <qmediaplayercontrol.h> -#include <qmediaplayer.h> - -#include <limits.h> - -QT_BEGIN_NAMESPACE -class QMediaPlaylist; -class QMediaPlaylistNavigator; -class QSocketNotifier; -QT_END_NAMESPACE - -QT_USE_NAMESPACE - -class QGstreamerPlayerSession; -class QGstreamerPlayerService; -class PlayerResourcePolicy; - -class QGstreamerPlayerControl : public QMediaPlayerControl -{ - Q_OBJECT - Q_PROPERTY(bool mediaDownloadEnabled READ isMediaDownloadEnabled WRITE setMediaDownloadEnabled) - -public: - QGstreamerPlayerControl(QGstreamerPlayerSession *session, QObject *parent = 0); - ~QGstreamerPlayerControl(); - - QMediaPlayer::State state() const; - QMediaPlayer::MediaStatus mediaStatus() const; - - qint64 position() const; - qint64 duration() const; - - int bufferStatus() const; - - int volume() const; - bool isMuted() const; - - bool isAudioAvailable() const; - bool isVideoAvailable() const; - void setVideoOutput(QObject *output); - - bool isSeekable() const; - QMediaTimeRange availablePlaybackRanges() const; - - qreal playbackRate() const; - void setPlaybackRate(qreal rate); - - QMediaContent media() const; - const QIODevice *mediaStream() const; - void setMedia(const QMediaContent&, QIODevice *); - - bool isMediaDownloadEnabled() const; - void setMediaDownloadEnabled(bool enabled); - -public Q_SLOTS: - void setPosition(qint64 pos); - - void play(); - void pause(); - void stop(); - - void setVolume(int volume); - void setMuted(bool muted); - -private Q_SLOTS: - void writeFifo(); - void fifoReadyWrite(int socket); - - void updateSessionState(QMediaPlayer::State state); - void updateMediaStatus(); - void processEOS(); - void setBufferProgress(int progress); - void applyPendingSeek(bool isSeekable); - void updatePosition(qint64 pos); - - void handleInvalidMedia(); - - void handleResourcesGranted(); - void handleResourcesLost(); - -private: - bool openFifo(); - void closeFifo(); - void playOrPause(QMediaPlayer::State state); - - void pushState(); - void popAndNotifyState(); - - bool m_ownStream; - QGstreamerPlayerSession *m_session; - QMediaPlayer::State m_state; - QMediaPlayer::MediaStatus m_mediaStatus; - QStack<QMediaPlayer::State> m_stateStack; - QStack<QMediaPlayer::MediaStatus> m_mediaStatusStack; - - int m_bufferProgress; - bool m_seekToStartPending; - qint64 m_pendingSeekPosition; - QMediaContent m_currentResource; - QIODevice *m_stream; - QSocketNotifier *m_fifoNotifier; - int m_fifoFd[2]; - bool m_fifoCanWrite; - int m_bufferSize; - int m_bufferOffset; - char m_buffer[PIPE_BUF]; - - PlayerResourcePolicy *m_resources; -}; - -#endif diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.cpp b/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.cpp deleted file mode 100644 index 7c017e2..0000000 --- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qvariant.h> -#include <QtCore/qdebug.h> -#include <QtWidgets/qwidget.h> - -#include "qgstreamerplayerservice.h" -#include "qgstreamerplayercontrol.h" -#include "qgstreamerplayersession.h" -#include "qgstreamermetadataprovider.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 "qgstreamerstreamscontrol.h" - -#include <qmediaplaylistnavigator.h> -#include <qmediaplaylist.h> - -QGstreamerPlayerService::QGstreamerPlayerService(QObject *parent): - QMediaService(parent), - m_videoOutput(0), - m_videoRenderer(0), - m_videoWindow(0), - m_videoWidget(0) -{ - m_session = new QGstreamerPlayerSession(this); - m_control = new QGstreamerPlayerControl(m_session, this); - m_metaData = new QGstreamerMetaDataProvider(m_session, this); - m_streamsControl = new QGstreamerStreamsControl(m_session,this); - -#if defined(Q_WS_MAEMO_6) && defined(__arm__) - m_videoRenderer = new QGstreamerGLTextureRenderer(this); -#else - m_videoRenderer = new QGstreamerVideoRenderer(this); -#endif - -#if defined(Q_WS_X11) && !defined(QT_NO_XVIDEO) - -#ifdef Q_WS_MAEMO_6 - m_videoWindow = new QGstreamerVideoWindow(this, "omapxvsink"); -#else - m_videoWindow = new QGstreamerVideoOverlay(this); -#endif - - m_videoWidget = new QGstreamerVideoWidgetControl(this); -#endif -} - -QGstreamerPlayerService::~QGstreamerPlayerService() -{ -} - -QMediaControl *QGstreamerPlayerService::requestControl(const char *name) -{ - if (qstrcmp(name,QMediaPlayerControl_iid) == 0) - return m_control; - - if (qstrcmp(name,QMetaDataReaderControl_iid) == 0) - return m_metaData; - - if (qstrcmp(name,QMediaStreamsControl_iid) == 0) - return m_streamsControl; - - if (!m_videoOutput) { - if (qstrcmp(name, QVideoWidgetControl_iid) == 0) - m_videoOutput = m_videoWidget; - else if (qstrcmp(name, QVideoRendererControl_iid) == 0) - m_videoOutput = m_videoRenderer; - else if (qstrcmp(name, QVideoWindowControl_iid) == 0) - m_videoOutput = m_videoWindow; - - if (m_videoOutput) { - m_control->setVideoOutput(m_videoOutput); - return m_videoOutput; - } - } - - return 0; -} - -void QGstreamerPlayerService::releaseControl(QMediaControl *control) -{ - if (control == m_videoOutput) { - m_videoOutput = 0; - m_control->setVideoOutput(0); - } -} - diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.h b/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.h deleted file mode 100644 index ffaae17..0000000 --- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERPLAYERSERVICE_H -#define QGSTREAMERPLAYERSERVICE_H - -#include <QtCore/qobject.h> -#include <QtCore/qiodevice.h> - -#include <qmediaservice.h> - -QT_BEGIN_NAMESPACE -class QMediaMetaData; -class QMediaPlayerControl; -class QMediaPlaylist; -class QMediaPlaylistNavigator; -QT_END_NAMESPACE - -class QGstreamerMetaData; -class QGstreamerPlayerControl; -class QGstreamerPlayerSession; -class QGstreamerMetaDataProvider; -class QGstreamerStreamsControl; -class QGstreamerVideoRenderer; -class QGstreamerVideoOverlay; -class QGstreamerVideoWidgetControl; - -QT_USE_NAMESPACE - -class QGstreamerPlayerService : public QMediaService -{ - Q_OBJECT -public: - QGstreamerPlayerService(QObject *parent = 0); - ~QGstreamerPlayerService(); - - QMediaControl *requestControl(const char *name); - void releaseControl(QMediaControl *control); - -private: - QGstreamerPlayerControl *m_control; - QGstreamerPlayerSession *m_session; - QGstreamerMetaDataProvider *m_metaData; - QGstreamerStreamsControl *m_streamsControl; - - QMediaControl *m_videoOutput; - QMediaControl *m_videoRenderer; - QMediaControl *m_videoWindow; - QMediaControl *m_videoWidget; -}; - -#endif diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.cpp b/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.cpp deleted file mode 100644 index db64ba6..0000000 --- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.cpp +++ /dev/null @@ -1,1618 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamerplayersession.h" -#include <private/qgstreamerbushelper_p.h> - -#include "qgstreamervideorendererinterface.h" -#include "gstvideoconnector.h" -#include <private/qgstutils_p.h> - -#include <gst/gstvalue.h> -#include <gst/base/gstbasesrc.h> - -#include <QtCore/qdatetime.h> -#include <QtCore/qdebug.h> -#include <QtCore/qsize.h> -#include <QtCore/qtimer.h> -#include <QtCore/qdebug.h> -#include <QtCore/qdir.h> -#include <QtCore/qstandardpaths.h> - -#if defined(Q_WS_MAEMO_6) || (GST_VERSION_MICRO > 20) -#define USE_PLAYBIN2 -#endif - -//#define DEBUG_PLAYBIN -//#define DEBUG_VO_BIN_DUMP - -typedef enum { - GST_PLAY_FLAG_VIDEO = 0x00000001, - GST_PLAY_FLAG_AUDIO = 0x00000002, - GST_PLAY_FLAG_TEXT = 0x00000004, - GST_PLAY_FLAG_VIS = 0x00000008, - GST_PLAY_FLAG_SOFT_VOLUME = 0x00000010, - GST_PLAY_FLAG_NATIVE_AUDIO = 0x00000020, - GST_PLAY_FLAG_NATIVE_VIDEO = 0x00000040, - GST_PLAY_FLAG_DOWNLOAD = 0x00000080, - GST_PLAY_FLAG_BUFFERING = 0x000000100 -} GstPlayFlags; - -QGstreamerPlayerSession::QGstreamerPlayerSession(QObject *parent) - :QObject(parent), - m_state(QMediaPlayer::StoppedState), - m_pendingState(QMediaPlayer::StoppedState), - m_busHelper(0), - m_playbin(0), - m_usePlaybin2(false), - m_usingColorspaceElement(false), - m_videoSink(0), - m_pendingVideoSink(0), - m_nullVideoSink(0), - m_bus(0), - m_videoOutput(0), - m_renderer(0), - m_haveQueueElement(false), -#if defined(HAVE_GST_APPSRC) - m_appSrc(0), -#endif - m_volume(100), - m_playbackRate(1.0), - m_muted(false), - m_audioAvailable(false), - m_videoAvailable(false), - m_seekable(false), - m_lastPosition(0), - m_duration(-1), - m_durationQueries(0), - m_displayPrerolledFrame(true), - m_sourceType(UnknownSrc), - m_everPlayed(false), - m_isLiveSource(false) -{ -#ifdef USE_PLAYBIN2 - m_playbin = gst_element_factory_make("playbin2", NULL); -#endif - - if (m_playbin) { - m_usePlaybin2 = true; - - //GST_PLAY_FLAG_NATIVE_VIDEO omits configuration of ffmpegcolorspace and videoscale, - //since those elements are included in the video output bin when necessary. -#ifdef Q_WS_MAEMO_6 - int flags = GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_AUDIO | - GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_NATIVE_AUDIO; -#else - int flags = 0; - g_object_get(G_OBJECT(m_playbin), "flags", &flags, NULL); - flags |= GST_PLAY_FLAG_NATIVE_VIDEO; -#endif - g_object_set(G_OBJECT(m_playbin), "flags", flags, NULL); - } else { - m_usePlaybin2 = false; - m_playbin = gst_element_factory_make("playbin", NULL); - } - - m_videoOutputBin = gst_bin_new("video-output-bin"); - gst_object_ref(GST_OBJECT(m_videoOutputBin)); - - m_videoIdentity = GST_ELEMENT(g_object_new(gst_video_connector_get_type(), 0)); - g_signal_connect(G_OBJECT(m_videoIdentity), "connection-failed", G_CALLBACK(insertColorSpaceElement), (gpointer)this); - m_colorSpace = gst_element_factory_make("ffmpegcolorspace", "ffmpegcolorspace-vo"); - gst_object_ref(GST_OBJECT(m_colorSpace)); - - m_nullVideoSink = gst_element_factory_make("fakesink", NULL); - g_object_set(G_OBJECT(m_nullVideoSink), "sync", true, NULL); - gst_object_ref(GST_OBJECT(m_nullVideoSink)); - gst_bin_add_many(GST_BIN(m_videoOutputBin), m_videoIdentity, m_nullVideoSink, NULL); - gst_element_link(m_videoIdentity, m_nullVideoSink); - - m_videoSink = m_nullVideoSink; - - // add ghostpads - GstPad *pad = gst_element_get_static_pad(m_videoIdentity,"sink"); - gst_element_add_pad(GST_ELEMENT(m_videoOutputBin), gst_ghost_pad_new("videosink", pad)); - gst_object_unref(GST_OBJECT(pad)); - - if (m_playbin != 0) { - // Sort out messages - m_bus = gst_element_get_bus(m_playbin); - m_busHelper = new QGstreamerBusHelper(m_bus, this); - m_busHelper->installMessageFilter(this); - - g_object_set(G_OBJECT(m_playbin), "video-sink", m_videoOutputBin, NULL); - - g_signal_connect(G_OBJECT(m_playbin), "notify::source", G_CALLBACK(playbinNotifySource), this); - g_signal_connect(G_OBJECT(m_playbin), "element-added", G_CALLBACK(handleElementAdded), this); - - // Initial volume - double volume = 1.0; - g_object_get(G_OBJECT(m_playbin), "volume", &volume, NULL); - m_volume = int(volume*100); - - g_signal_connect(G_OBJECT(m_playbin), "notify::volume", G_CALLBACK(handleVolumeChange), this); - if (m_usePlaybin2) - g_signal_connect(G_OBJECT(m_playbin), "notify::mute", G_CALLBACK(handleMutedChange), this); - } -} - -QGstreamerPlayerSession::~QGstreamerPlayerSession() -{ - if (m_playbin) { - stop(); - - delete m_busHelper; - gst_object_unref(GST_OBJECT(m_bus)); - gst_object_unref(GST_OBJECT(m_playbin)); - gst_object_unref(GST_OBJECT(m_colorSpace)); - gst_object_unref(GST_OBJECT(m_nullVideoSink)); - gst_object_unref(GST_OBJECT(m_videoOutputBin)); - } -} - -GstElement *QGstreamerPlayerSession::playbin() const -{ - return m_playbin; -} - -#if defined(HAVE_GST_APPSRC) -void QGstreamerPlayerSession::configureAppSrcElement(GObject* object, GObject *orig, GParamSpec *pspec, QGstreamerPlayerSession* self) -{ - Q_UNUSED(object); - Q_UNUSED(pspec); - - if (self->appsrc()->isReady()) - return; - - GstElement *appsrc; - g_object_get(orig, "source", &appsrc, NULL); - - if (!self->appsrc()->setup(appsrc)) - qWarning()<<"Could not setup appsrc element"; -} -#endif - -void QGstreamerPlayerSession::loadFromStream(const QNetworkRequest &request, QIODevice *appSrcStream) -{ -#if defined(HAVE_GST_APPSRC) -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO; -#endif - m_request = request; - m_duration = -1; - m_lastPosition = 0; - m_haveQueueElement = false; - - if (m_appSrc) - m_appSrc->deleteLater(); - m_appSrc = new QGstAppSrc(this); - m_appSrc->setStream(appSrcStream); - - if (m_playbin) { - m_tags.clear(); - emit tagsChanged(); - - g_signal_connect(G_OBJECT(m_playbin), "deep-notify::source", (GCallback) &QGstreamerPlayerSession::configureAppSrcElement, (gpointer)this); - g_object_set(G_OBJECT(m_playbin), "uri", "appsrc://", NULL); - - if (!m_streamTypes.isEmpty()) { - m_streamProperties.clear(); - m_streamTypes.clear(); - - emit streamsChanged(); - } - } -#endif -} - -void QGstreamerPlayerSession::loadFromUri(const QNetworkRequest &request) -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO << request.url(); -#endif - m_request = request; - m_duration = -1; - m_lastPosition = 0; - m_haveQueueElement = false; - - if (m_playbin) { - m_tags.clear(); - emit tagsChanged(); - - g_object_set(G_OBJECT(m_playbin), "uri", m_request.url().toEncoded().constData(), NULL); - - if (!m_streamTypes.isEmpty()) { - m_streamProperties.clear(); - m_streamTypes.clear(); - - emit streamsChanged(); - } - } -} - -qint64 QGstreamerPlayerSession::duration() const -{ - return m_duration; -} - -qint64 QGstreamerPlayerSession::position() const -{ - GstFormat format = GST_FORMAT_TIME; - gint64 position = 0; - - if ( m_playbin && gst_element_query_position(m_playbin, &format, &position)) - m_lastPosition = position / 1000000; - - return m_lastPosition; -} - -qreal QGstreamerPlayerSession::playbackRate() const -{ - return m_playbackRate; -} - -void QGstreamerPlayerSession::setPlaybackRate(qreal rate) -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO << rate; -#endif - if (!qFuzzyCompare(m_playbackRate, rate)) { - m_playbackRate = rate; - if (m_playbin) { - gst_element_seek(m_playbin, rate, GST_FORMAT_TIME, - GstSeekFlags(GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_FLUSH), - GST_SEEK_TYPE_NONE,0, - GST_SEEK_TYPE_NONE,0 ); - } - emit playbackRateChanged(m_playbackRate); - } -} - -QMediaTimeRange QGstreamerPlayerSession::availablePlaybackRanges() const -{ - QMediaTimeRange ranges; -#if (GST_VERSION_MAJOR >= 0) && (GST_VERSION_MINOR >= 10) && (GST_VERSION_MICRO >= 31) - //GST_FORMAT_TIME would be more appropriate, but unfortunately it's not supported. - //with GST_FORMAT_PERCENT media is treated as encoded with constant bitrate. - GstQuery* query = gst_query_new_buffering(GST_FORMAT_PERCENT); - - if (gst_element_query(m_playbin, query)) { - for (guint index = 0; index < gst_query_get_n_buffering_ranges(query); index++) { - gint64 rangeStart = 0; - gint64 rangeStop = 0; - - //This query should return values in GST_FORMAT_PERCENT_MAX range, - //but queue2 returns values in 0..100 range instead - if (gst_query_parse_nth_buffering_range(query, index, &rangeStart, &rangeStop)) - ranges.addInterval(rangeStart * duration() / 100, - rangeStop * duration() / 100); - } - } - - gst_query_unref(query); -#endif - - //without queue2 element in pipeline all the media is considered available - if (ranges.isEmpty() && duration() > 0 && !m_haveQueueElement) - ranges.addInterval(0, duration()); - -#ifdef DEBUG_PLAYBIN - qDebug() << ranges; -#endif - - return ranges; -} - -int QGstreamerPlayerSession::activeStream(QMediaStreamsControl::StreamType streamType) const -{ - int streamNumber = -1; - if (m_playbin) { - switch (streamType) { - case QMediaStreamsControl::AudioStream: - g_object_get(G_OBJECT(m_playbin), "current-audio", streamNumber, NULL); - break; - case QMediaStreamsControl::VideoStream: - g_object_get(G_OBJECT(m_playbin), "current-video", streamNumber, NULL); - break; - case QMediaStreamsControl::SubPictureStream: - g_object_get(G_OBJECT(m_playbin), "current-text", streamNumber, NULL); - break; - default: - break; - } - } - - if (m_usePlaybin2 && streamNumber >= 0) - streamNumber += m_playbin2StreamOffset.value(streamType,0); - - return streamNumber; -} - -void QGstreamerPlayerSession::setActiveStream(QMediaStreamsControl::StreamType streamType, int streamNumber) -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO << streamType << streamNumber; -#endif - - if (m_usePlaybin2 && streamNumber >= 0) - streamNumber -= m_playbin2StreamOffset.value(streamType,0); - - if (m_playbin) { - switch (streamType) { - case QMediaStreamsControl::AudioStream: - g_object_set(G_OBJECT(m_playbin), "current-audio", &streamNumber, NULL); - break; - case QMediaStreamsControl::VideoStream: - g_object_set(G_OBJECT(m_playbin), "current-video", &streamNumber, NULL); - break; - case QMediaStreamsControl::SubPictureStream: - g_object_set(G_OBJECT(m_playbin), "current-text", &streamNumber, NULL); - break; - default: - break; - } - } -} - - -bool QGstreamerPlayerSession::isBuffering() const -{ - return false; -} - -int QGstreamerPlayerSession::bufferingProgress() const -{ - return 0; -} - -int QGstreamerPlayerSession::volume() const -{ - return m_volume; -} - -bool QGstreamerPlayerSession::isMuted() const -{ - return m_muted; -} - -bool QGstreamerPlayerSession::isAudioAvailable() const -{ - return m_audioAvailable; -} - -static void block_pad_cb(GstPad *pad, gboolean blocked, gpointer user_data) -{ - Q_UNUSED(pad); -#ifdef DEBUG_PLAYBIN - qDebug() << "block_pad_cb, blocked:" << blocked; -#endif - - if (blocked && user_data) { - QGstreamerPlayerSession *session = reinterpret_cast<QGstreamerPlayerSession*>(user_data); - QMetaObject::invokeMethod(session, "finishVideoOutputChange", Qt::QueuedConnection); - } -} - -void QGstreamerPlayerSession::updateVideoRenderer() -{ -#ifdef DEBUG_PLAYBIN - qDebug() << "Video sink has chaged, reload video output"; -#endif - - if (m_videoOutput) - setVideoRenderer(m_videoOutput); -} - -void QGstreamerPlayerSession::setVideoRenderer(QObject *videoOutput) -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO; -#endif - if (m_videoOutput != videoOutput) { - if (m_videoOutput) { - disconnect(m_videoOutput, SIGNAL(sinkChanged()), - this, SLOT(updateVideoRenderer())); - disconnect(m_videoOutput, SIGNAL(readyChanged(bool)), - this, SLOT(updateVideoRenderer())); - - m_busHelper->removeMessageFilter(m_videoOutput); - } - - m_videoOutput = videoOutput; - - if (m_videoOutput) { - connect(m_videoOutput, SIGNAL(sinkChanged()), - this, SLOT(updateVideoRenderer())); - connect(m_videoOutput, SIGNAL(readyChanged(bool)), - this, SLOT(updateVideoRenderer())); - - m_busHelper->installMessageFilter(m_videoOutput); - } - } - - QGstreamerVideoRendererInterface* renderer = qobject_cast<QGstreamerVideoRendererInterface*>(videoOutput); - - m_renderer = renderer; - -#ifdef DEBUG_VO_BIN_DUMP - _gst_debug_bin_to_dot_file_with_ts(GST_BIN(m_playbin), - GstDebugGraphDetails(GST_DEBUG_GRAPH_SHOW_ALL /* GST_DEBUG_GRAPH_SHOW_MEDIA_TYPE | GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS | GST_DEBUG_GRAPH_SHOW_STATES*/), - "playbin_set"); -#endif - - GstElement *videoSink = 0; - if (m_renderer && m_renderer->isReady()) - videoSink = m_renderer->videoSink(); - - if (!videoSink) - videoSink = m_nullVideoSink; - -#ifdef DEBUG_PLAYBIN - qDebug() << "Set video output:" << videoOutput; - qDebug() << "Current sink:" << (m_videoSink ? GST_ELEMENT_NAME(m_videoSink) : "") << m_videoSink - << "pending:" << (m_pendingVideoSink ? GST_ELEMENT_NAME(m_pendingVideoSink) : "") << m_pendingVideoSink - << "new sink:" << (videoSink ? GST_ELEMENT_NAME(videoSink) : "") << videoSink; -#endif - - if (m_pendingVideoSink == videoSink || - (m_pendingVideoSink == 0 && m_videoSink == videoSink)) { -#ifdef DEBUG_PLAYBIN - qDebug() << "Video sink has not changed, skip video output reconfiguration"; -#endif - return; - } - -#ifdef DEBUG_PLAYBIN - qDebug() << "Reconfigure video output"; -#endif - - if (m_state == QMediaPlayer::StoppedState) { -#ifdef DEBUG_PLAYBIN - qDebug() << "The pipeline has not started yet, pending state:" << m_pendingState; -#endif - //the pipeline has not started yet - m_pendingVideoSink = 0; - gst_element_set_state(m_videoSink, GST_STATE_NULL); - gst_element_set_state(m_playbin, GST_STATE_NULL); - - if (m_usingColorspaceElement) { - gst_element_unlink(m_colorSpace, m_videoSink); - gst_bin_remove(GST_BIN(m_videoOutputBin), m_colorSpace); - } else { - gst_element_unlink(m_videoIdentity, m_videoSink); - } - - gst_bin_remove(GST_BIN(m_videoOutputBin), m_videoSink); - - m_videoSink = videoSink; - - gst_bin_add(GST_BIN(m_videoOutputBin), m_videoSink); - - m_usingColorspaceElement = false; - bool linked = gst_element_link(m_videoIdentity, m_videoSink); - if (!linked) { - m_usingColorspaceElement = true; -#ifdef DEBUG_PLAYBIN - qDebug() << "Failed to connect video output, inserting the colorspace element."; -#endif - gst_bin_add(GST_BIN(m_videoOutputBin), m_colorSpace); - linked = gst_element_link_many(m_videoIdentity, m_colorSpace, m_videoSink, NULL); - } - - if (g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "show-preroll-frame") != 0) { - gboolean value = m_displayPrerolledFrame; - g_object_set(G_OBJECT(m_videoSink), "show-preroll-frame", value, NULL); - } - - switch (m_pendingState) { - case QMediaPlayer::PausedState: - gst_element_set_state(m_playbin, GST_STATE_PAUSED); - break; - case QMediaPlayer::PlayingState: - gst_element_set_state(m_playbin, GST_STATE_PLAYING); - break; - default: - break; - } - } else { - if (m_pendingVideoSink) { -#ifdef DEBUG_PLAYBIN - qDebug() << "already waiting for pad to be blocked, just change the pending sink"; -#endif - m_pendingVideoSink = videoSink; - return; - } - - m_pendingVideoSink = videoSink; - -#ifdef DEBUG_PLAYBIN - qDebug() << "Blocking the video output pad..."; -#endif - - //block pads, async to avoid locking in paused state - GstPad *srcPad = gst_element_get_static_pad(m_videoIdentity, "src"); - gst_pad_set_blocked_async(srcPad, true, &block_pad_cb, this); - gst_object_unref(GST_OBJECT(srcPad)); - - //Unpause the sink to avoid waiting until the buffer is processed - //while the sink is paused. The pad will be blocked as soon as the current - //buffer is processed. - if (m_state == QMediaPlayer::PausedState) { -#ifdef DEBUG_PLAYBIN - qDebug() << "Starting video output to avoid blocking in paused state..."; -#endif - gst_element_set_state(m_videoSink, GST_STATE_PLAYING); - } - } -} - -void QGstreamerPlayerSession::finishVideoOutputChange() -{ - if (!m_pendingVideoSink) - return; - -#ifdef DEBUG_PLAYBIN - qDebug() << "finishVideoOutputChange" << m_pendingVideoSink; -#endif - - GstPad *srcPad = gst_element_get_static_pad(m_videoIdentity, "src"); - - if (!gst_pad_is_blocked(srcPad)) { - //pad is not blocked, it's possible to swap outputs only in the null state - qWarning() << "Pad is not blocked yet, could not switch video sink"; - GstState identityElementState = GST_STATE_NULL; - gst_element_get_state(m_videoIdentity, &identityElementState, NULL, GST_CLOCK_TIME_NONE); - if (identityElementState != GST_STATE_NULL) { - gst_object_unref(GST_OBJECT(srcPad)); - return; //can't change vo yet, received async call from the previous change - } - } - - if (m_pendingVideoSink == m_videoSink) { - //video output was change back to the current one, - //no need to torment the pipeline, just unblock the pad - if (gst_pad_is_blocked(srcPad)) - gst_pad_set_blocked_async(srcPad, false, &block_pad_cb, 0); - - m_pendingVideoSink = 0; - gst_object_unref(GST_OBJECT(srcPad)); - return; - } - - if (m_usingColorspaceElement) { - gst_element_set_state(m_colorSpace, GST_STATE_NULL); - gst_element_set_state(m_videoSink, GST_STATE_NULL); - - gst_element_unlink(m_colorSpace, m_videoSink); - gst_bin_remove(GST_BIN(m_videoOutputBin), m_colorSpace); - } else { - gst_element_set_state(m_videoSink, GST_STATE_NULL); - gst_element_unlink(m_videoIdentity, m_videoSink); - } - - gst_bin_remove(GST_BIN(m_videoOutputBin), m_videoSink); - - m_videoSink = m_pendingVideoSink; - m_pendingVideoSink = 0; - - gst_bin_add(GST_BIN(m_videoOutputBin), m_videoSink); - - m_usingColorspaceElement = false; - bool linked = gst_element_link(m_videoIdentity, m_videoSink); - if (!linked) { - m_usingColorspaceElement = true; -#ifdef DEBUG_PLAYBIN - qDebug() << "Failed to connect video output, inserting the colorspace element."; -#endif - gst_bin_add(GST_BIN(m_videoOutputBin), m_colorSpace); - linked = gst_element_link_many(m_videoIdentity, m_colorSpace, m_videoSink, NULL); - } - - if (!linked) - qWarning() << "Linking video output element failed"; - -#ifdef DEBUG_PLAYBIN - qDebug() << "notify the video connector it has to emit a new segment message..."; -#endif - //it's necessary to send a new segment event just before - //the first buffer pushed to the new sink - g_signal_emit_by_name(m_videoIdentity, - "resend-new-segment", - true //emit connection-failed signal - //to have a chance to insert colorspace element - ); - - - GstState state; - - switch (m_pendingState) { - case QMediaPlayer::StoppedState: - state = GST_STATE_NULL; - break; - case QMediaPlayer::PausedState: - state = GST_STATE_PAUSED; - break; - case QMediaPlayer::PlayingState: - state = GST_STATE_PLAYING; - break; - } - - if (m_usingColorspaceElement) - gst_element_set_state(m_colorSpace, state); - - gst_element_set_state(m_videoSink, state); - - // Set state change that was deferred due the video output - // change being pending - gst_element_set_state(m_playbin, state); - - //don't have to wait here, it will unblock eventually - if (gst_pad_is_blocked(srcPad)) - gst_pad_set_blocked_async(srcPad, false, &block_pad_cb, 0); - gst_object_unref(GST_OBJECT(srcPad)); - -#ifdef DEBUG_VO_BIN_DUMP - _gst_debug_bin_to_dot_file_with_ts(GST_BIN(m_playbin), - GstDebugGraphDetails(GST_DEBUG_GRAPH_SHOW_ALL /* GST_DEBUG_GRAPH_SHOW_MEDIA_TYPE | GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS | GST_DEBUG_GRAPH_SHOW_STATES*/), - "playbin_finish"); -#endif -} - -void QGstreamerPlayerSession::insertColorSpaceElement(GstElement *element, gpointer data) -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO; -#endif - Q_UNUSED(element); - QGstreamerPlayerSession* session = reinterpret_cast<QGstreamerPlayerSession*>(data); - - if (session->m_usingColorspaceElement) - return; - session->m_usingColorspaceElement = true; - -#ifdef DEBUG_PLAYBIN - qDebug() << "Failed to connect video output, inserting the colorspace elemnt."; - qDebug() << "notify the video connector it has to emit a new segment message..."; -#endif - //it's necessary to send a new segment event just before - //the first buffer pushed to the new sink - g_signal_emit_by_name(session->m_videoIdentity, - "resend-new-segment", - false // don't emit connection-failed signal - ); - - gst_element_unlink(session->m_videoIdentity, session->m_videoSink); - gst_bin_add(GST_BIN(session->m_videoOutputBin), session->m_colorSpace); - gst_element_link_many(session->m_videoIdentity, session->m_colorSpace, session->m_videoSink, NULL); - - GstState state; - - switch (session->m_pendingState) { - case QMediaPlayer::StoppedState: - state = GST_STATE_NULL; - break; - case QMediaPlayer::PausedState: - state = GST_STATE_PAUSED; - break; - case QMediaPlayer::PlayingState: - state = GST_STATE_PLAYING; - break; - } - - gst_element_set_state(session->m_colorSpace, state); -} - - -bool QGstreamerPlayerSession::isVideoAvailable() const -{ - return m_videoAvailable; -} - -bool QGstreamerPlayerSession::isSeekable() const -{ - return m_seekable; -} - -bool QGstreamerPlayerSession::play() -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO; -#endif - m_everPlayed = false; - if (m_playbin) { - m_pendingState = QMediaPlayer::PlayingState; - if (gst_element_set_state(m_playbin, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) { - qWarning() << "GStreamer; Unable to play -" << m_request.url().toString(); - m_pendingState = m_state = QMediaPlayer::StoppedState; - - emit stateChanged(m_state); - } else - return true; - } - - return false; -} - -bool QGstreamerPlayerSession::pause() -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO; -#endif - if (m_playbin) { - m_pendingState = QMediaPlayer::PausedState; - if (m_pendingVideoSink != 0) - return true; - - if (gst_element_set_state(m_playbin, GST_STATE_PAUSED) == GST_STATE_CHANGE_FAILURE) { - qWarning() << "GStreamer; Unable to pause -" << m_request.url().toString(); - m_pendingState = m_state = QMediaPlayer::StoppedState; - - emit stateChanged(m_state); - } else { - return true; - } - } - - return false; -} - -void QGstreamerPlayerSession::stop() -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO; -#endif - m_everPlayed = false; - if (m_playbin) { - if (m_renderer) - m_renderer->stopRenderer(); - - gst_element_set_state(m_playbin, GST_STATE_NULL); - - m_lastPosition = 0; - QMediaPlayer::State oldState = m_state; - m_pendingState = m_state = QMediaPlayer::StoppedState; - - finishVideoOutputChange(); - - //we have to do it here, since gstreamer will not emit bus messages any more - setSeekable(false); - if (oldState != m_state) - emit stateChanged(m_state); - } -} - -bool QGstreamerPlayerSession::seek(qint64 ms) -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO << ms; -#endif - //seek locks when the video output sink is changing and pad is blocked - if (m_playbin && !m_pendingVideoSink && m_state != QMediaPlayer::StoppedState) { - ms = qMax(ms,qint64(0)); - gint64 position = ms * 1000000; - bool isSeeking = gst_element_seek(m_playbin, - m_playbackRate, - GST_FORMAT_TIME, - GstSeekFlags(GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_FLUSH), - GST_SEEK_TYPE_SET, - position, - GST_SEEK_TYPE_NONE, - 0); - if (isSeeking) - m_lastPosition = ms; - - return isSeeking; - } - - return false; -} - -void QGstreamerPlayerSession::setVolume(int volume) -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO << volume; -#endif - - if (m_volume != volume) { - m_volume = volume; - - if (m_playbin) { - //playbin2 allows to set volume and muted independently, - //with playbin1 it's necessary to keep volume at 0 while muted - if (!m_muted || m_usePlaybin2) - g_object_set(G_OBJECT(m_playbin), "volume", m_volume/100.0, NULL); - } - - emit volumeChanged(m_volume); - } -} - -void QGstreamerPlayerSession::setMuted(bool muted) -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO << muted; -#endif - if (m_muted != muted) { - m_muted = muted; - - if (m_usePlaybin2) - g_object_set(G_OBJECT(m_playbin), "mute", m_muted, NULL); - else - g_object_set(G_OBJECT(m_playbin), "volume", (m_muted ? 0 : m_volume/100.0), NULL); - - emit mutedStateChanged(m_muted); - } -} - - -void QGstreamerPlayerSession::setSeekable(bool seekable) -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO << seekable; -#endif - if (seekable != m_seekable) { - m_seekable = seekable; - emit seekableChanged(m_seekable); - } -} - -bool QGstreamerPlayerSession::processBusMessage(const QGstreamerMessage &message) -{ - GstMessage* gm = message.rawMessage(); - if (gm) { - //tag message comes from elements inside playbin, not from playbin itself - if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_TAG) { - //qDebug() << "tag message"; - GstTagList *tag_list; - gst_message_parse_tag(gm, &tag_list); - m_tags.unite(QGstUtils::gstTagListToMap(tag_list)); - - //qDebug() << m_tags; - - emit tagsChanged(); - } else if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_DURATION) { - updateDuration(); - } - -#ifdef DEBUG_PLAYBIN - if (m_sourceType == MMSSrc && qstrcmp(GST_OBJECT_NAME(GST_MESSAGE_SRC(gm)), "source") == 0) { - qDebug() << "Message from MMSSrc: " << GST_MESSAGE_TYPE(gm); - } else if (m_sourceType == RTSPSrc && qstrcmp(GST_OBJECT_NAME(GST_MESSAGE_SRC(gm)), "source") == 0) { - qDebug() << "Message from RTSPSrc: " << GST_MESSAGE_TYPE(gm); - } else { - qDebug() << "Message from " << GST_OBJECT_NAME(GST_MESSAGE_SRC(gm)) << ":" << GST_MESSAGE_TYPE(gm); - } -#endif - - if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_BUFFERING) { - int progress = 0; - gst_message_parse_buffering(gm, &progress); - emit bufferingProgressChanged(progress); - } - - bool handlePlaybin2 = false; - if (GST_MESSAGE_SRC(gm) == GST_OBJECT_CAST(m_playbin)) { - switch (GST_MESSAGE_TYPE(gm)) { - case GST_MESSAGE_STATE_CHANGED: - { - GstState oldState; - GstState newState; - GstState pending; - - gst_message_parse_state_changed(gm, &oldState, &newState, &pending); - -#ifdef DEBUG_PLAYBIN - QStringList states; - states << "GST_STATE_VOID_PENDING" << "GST_STATE_NULL" << "GST_STATE_READY" << "GST_STATE_PAUSED" << "GST_STATE_PLAYING"; - - qDebug() << QString("state changed: old: %1 new: %2 pending: %3") \ - .arg(states[oldState]) \ - .arg(states[newState]) \ - .arg(states[pending]); -#endif - - switch (newState) { - case GST_STATE_VOID_PENDING: - case GST_STATE_NULL: - setSeekable(false); - finishVideoOutputChange(); - if (m_state != QMediaPlayer::StoppedState) - emit stateChanged(m_state = QMediaPlayer::StoppedState); - break; - case GST_STATE_READY: - setSeekable(false); - if (m_state != QMediaPlayer::StoppedState) - emit stateChanged(m_state = QMediaPlayer::StoppedState); - break; - case GST_STATE_PAUSED: - { - QMediaPlayer::State prevState = m_state; - m_state = QMediaPlayer::PausedState; - - //check for seekable - if (oldState == GST_STATE_READY) { - if (m_sourceType == SoupHTTPSrc || m_sourceType == MMSSrc) { - //since udpsrc is a live source, it is not applicable here - m_everPlayed = true; - } - - getStreamsInfo(); - updateVideoResolutionTag(); - - //gstreamer doesn't give a reliable indication the duration - //information is ready, GST_MESSAGE_DURATION is not sent by most elements - //the duration is queried up to 5 times with increasing delay - m_durationQueries = 5; - updateDuration(); - - /* - //gst_element_seek_simple doesn't work reliably here, have to find a better solution - - GstFormat format = GST_FORMAT_TIME; - gint64 position = 0; - bool seekable = false; - if (gst_element_query_position(m_playbin, &format, &position)) { - seekable = gst_element_seek_simple(m_playbin, format, GST_SEEK_FLAG_NONE, position); - } - - setSeekable(seekable); - */ - - setSeekable(true); - - if (!qFuzzyCompare(m_playbackRate, qreal(1.0))) { - qreal rate = m_playbackRate; - m_playbackRate = 1.0; - setPlaybackRate(rate); - } - } - - if (m_state != prevState) - emit stateChanged(m_state); - - break; - } - case GST_STATE_PLAYING: - m_everPlayed = true; - if (m_state != QMediaPlayer::PlayingState) - emit stateChanged(m_state = QMediaPlayer::PlayingState); - - break; - } - } - break; - - case GST_MESSAGE_EOS: - emit playbackFinished(); - break; - - case GST_MESSAGE_TAG: - case GST_MESSAGE_STREAM_STATUS: - case GST_MESSAGE_UNKNOWN: - break; - case GST_MESSAGE_ERROR: { - GError *err; - gchar *debug; - gst_message_parse_error(gm, &err, &debug); - if (err->domain == GST_STREAM_ERROR && err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND) - processInvalidMedia(QMediaPlayer::FormatError, tr("Cannot play stream of type: <unknown>")); - else - processInvalidMedia(QMediaPlayer::ResourceError, QString::fromUtf8(err->message)); - qWarning() << "Error:" << QString::fromUtf8(err->message); - g_error_free(err); - g_free(debug); - } - break; - case GST_MESSAGE_WARNING: - { - GError *err; - gchar *debug; - gst_message_parse_warning (gm, &err, &debug); - qWarning() << "Warning:" << QString::fromUtf8(err->message); - g_error_free (err); - g_free (debug); - } - break; - case GST_MESSAGE_INFO: -#ifdef DEBUG_PLAYBIN - { - GError *err; - gchar *debug; - gst_message_parse_info (gm, &err, &debug); - qDebug() << "Info:" << QString::fromUtf8(err->message); - g_error_free (err); - g_free (debug); - } -#endif - break; - case GST_MESSAGE_BUFFERING: - case GST_MESSAGE_STATE_DIRTY: - case GST_MESSAGE_STEP_DONE: - case GST_MESSAGE_CLOCK_PROVIDE: - case GST_MESSAGE_CLOCK_LOST: - case GST_MESSAGE_NEW_CLOCK: - case GST_MESSAGE_STRUCTURE_CHANGE: - case GST_MESSAGE_APPLICATION: - case GST_MESSAGE_ELEMENT: - break; - case GST_MESSAGE_SEGMENT_START: - { - const GstStructure *structure = gst_message_get_structure(gm); - qint64 position = g_value_get_int64(gst_structure_get_value(structure, "position")); - position /= 1000000; - m_lastPosition = position; - emit positionChanged(position); - } - break; - case GST_MESSAGE_SEGMENT_DONE: - break; - case GST_MESSAGE_LATENCY: -#if (GST_VERSION_MAJOR >= 0) && (GST_VERSION_MINOR >= 10) && (GST_VERSION_MICRO >= 13) - case GST_MESSAGE_ASYNC_START: - break; - case GST_MESSAGE_ASYNC_DONE: - { - GstFormat format = GST_FORMAT_TIME; - gint64 position = 0; - if (gst_element_query_position(m_playbin, &format, &position)) { - position /= 1000000; - m_lastPosition = position; - emit positionChanged(position); - } - break; - } -#if GST_VERSION_MICRO >= 23 - case GST_MESSAGE_REQUEST_STATE: -#endif -#endif - case GST_MESSAGE_ANY: - break; - default: - break; - } - } else if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ERROR) { - GError *err; - gchar *debug; - gst_message_parse_error(gm, &err, &debug); - // If the source has given up, so do we. - if (qstrcmp(GST_OBJECT_NAME(GST_MESSAGE_SRC(gm)), "source") == 0) { - bool everPlayed = m_everPlayed; - // Try and differentiate network related resource errors from the others - if (!m_request.url().isRelative() && m_request.url().scheme().compare(QLatin1String("file"), Qt::CaseInsensitive) != 0 ) { - if (everPlayed || - (err->domain == GST_RESOURCE_ERROR && ( - err->code == GST_RESOURCE_ERROR_BUSY || - err->code == GST_RESOURCE_ERROR_OPEN_READ || - err->code == GST_RESOURCE_ERROR_READ || - err->code == GST_RESOURCE_ERROR_SEEK || - err->code == GST_RESOURCE_ERROR_SYNC))) { - processInvalidMedia(QMediaPlayer::NetworkError, QString::fromUtf8(err->message)); - } else { - processInvalidMedia(QMediaPlayer::ResourceError, QString::fromUtf8(err->message)); - } - } - else - processInvalidMedia(QMediaPlayer::ResourceError, QString::fromUtf8(err->message)); - } else if (err->domain == GST_STREAM_ERROR - && (err->code == GST_STREAM_ERROR_DECRYPT || err->code == GST_STREAM_ERROR_DECRYPT_NOKEY)) { - processInvalidMedia(QMediaPlayer::AccessDeniedError, QString::fromUtf8(err->message)); - } else { - handlePlaybin2 = m_usePlaybin2; - } - if (!handlePlaybin2) - qWarning() << "Error:" << QString::fromUtf8(err->message); - g_error_free(err); - g_free(debug); - } else if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ELEMENT - && qstrcmp(GST_OBJECT_NAME(GST_MESSAGE_SRC(gm)), "source") == 0 - && m_sourceType == UDPSrc - && gst_structure_has_name(gst_message_get_structure(gm), "GstUDPSrcTimeout")) { - //since udpsrc will not generate an error for the timeout event, - //we need to process its element message here and treat it as an error. - processInvalidMedia(m_everPlayed ? QMediaPlayer::NetworkError : QMediaPlayer::ResourceError, - tr("UDP source timeout")); - } else { - handlePlaybin2 = m_usePlaybin2; - } - - if (handlePlaybin2) { - if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_WARNING) { - GError *err; - gchar *debug; - gst_message_parse_warning(gm, &err, &debug); - if (err->domain == GST_STREAM_ERROR && err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND) - emit error(int(QMediaPlayer::FormatError), tr("Cannot play stream of type: <unknown>")); - qWarning() << "Warning:" << QString::fromUtf8(err->message); - g_error_free(err); - g_free(debug); - } else if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ERROR) { - GError *err; - gchar *debug; - gst_message_parse_error(gm, &err, &debug); - if (qstrncmp(GST_OBJECT_NAME(GST_MESSAGE_SRC(gm)), "decodebin2", 10) == 0 - || qstrncmp(GST_OBJECT_NAME(GST_MESSAGE_SRC(gm)), "uridecodebin", 12) == 0) { - processInvalidMedia(QMediaPlayer::ResourceError, QString::fromUtf8(err->message)); - } else if (err->domain == GST_STREAM_ERROR - && (err->code == GST_STREAM_ERROR_DECRYPT || err->code == GST_STREAM_ERROR_DECRYPT_NOKEY)) { - processInvalidMedia(QMediaPlayer::AccessDeniedError, QString::fromUtf8(err->message)); - } - qWarning() << "Error:" << QString::fromUtf8(err->message); - g_error_free(err); - g_free(debug); - } - } - } - - return false; -} - -void QGstreamerPlayerSession::getStreamsInfo() -{ - //check if video is available: - bool haveAudio = false; - bool haveVideo = false; - m_streamProperties.clear(); - m_streamTypes.clear(); - - if (m_usePlaybin2) { - gint audioStreamsCount = 0; - gint videoStreamsCount = 0; - gint textStreamsCount = 0; - - g_object_get(G_OBJECT(m_playbin), "n-audio", &audioStreamsCount, NULL); - g_object_get(G_OBJECT(m_playbin), "n-video", &videoStreamsCount, NULL); - g_object_get(G_OBJECT(m_playbin), "n-text", &textStreamsCount, NULL); - - haveAudio = audioStreamsCount > 0; - haveVideo = videoStreamsCount > 0; - - m_playbin2StreamOffset[QMediaStreamsControl::AudioStream] = 0; - m_playbin2StreamOffset[QMediaStreamsControl::VideoStream] = audioStreamsCount; - m_playbin2StreamOffset[QMediaStreamsControl::SubPictureStream] = audioStreamsCount+videoStreamsCount; - - for (int i=0; i<audioStreamsCount; i++) - m_streamTypes.append(QMediaStreamsControl::AudioStream); - - for (int i=0; i<videoStreamsCount; i++) - m_streamTypes.append(QMediaStreamsControl::VideoStream); - - for (int i=0; i<textStreamsCount; i++) - m_streamTypes.append(QMediaStreamsControl::SubPictureStream); - - for (int i=0; i<m_streamTypes.count(); i++) { - QMediaStreamsControl::StreamType streamType = m_streamTypes[i]; - QMap<QtMultimedia::MetaData, QVariant> streamProperties; - - int streamIndex = i - m_playbin2StreamOffset[streamType]; - - GstTagList *tags = 0; - switch (streamType) { - case QMediaStreamsControl::AudioStream: - g_signal_emit_by_name(G_OBJECT(m_playbin), "get-audio-tags", streamIndex, &tags); - break; - case QMediaStreamsControl::VideoStream: - g_signal_emit_by_name(G_OBJECT(m_playbin), "get-video-tags", streamIndex, &tags); - break; - case QMediaStreamsControl::SubPictureStream: - g_signal_emit_by_name(G_OBJECT(m_playbin), "get-text-tags", streamIndex, &tags); - break; - default: - break; - } - - if (tags && gst_is_tag_list(tags)) { - gchar *languageCode = 0; - if (gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &languageCode)) - streamProperties[QtMultimedia::Language] = QString::fromUtf8(languageCode); - - //qDebug() << "language for setream" << i << QString::fromUtf8(languageCode); - g_free (languageCode); - } - - m_streamProperties.append(streamProperties); - } - } else { // PlayBin 1 - enum { - GST_STREAM_TYPE_UNKNOWN, - GST_STREAM_TYPE_AUDIO, - GST_STREAM_TYPE_VIDEO, - GST_STREAM_TYPE_TEXT, - GST_STREAM_TYPE_SUBPICTURE, - GST_STREAM_TYPE_ELEMENT - }; - - GList* streamInfoList; - g_object_get(G_OBJECT(m_playbin), "stream-info", &streamInfoList, NULL); - - for (; streamInfoList != 0; streamInfoList = g_list_next(streamInfoList)) { - gint type; - gchar *languageCode = 0; - - GObject* streamInfo = G_OBJECT(streamInfoList->data); - - g_object_get(streamInfo, "type", &type, NULL); - g_object_get(streamInfo, "language-code", &languageCode, NULL); - - QMediaStreamsControl::StreamType streamType = QMediaStreamsControl::UnknownStream; - - switch (type) { - case GST_STREAM_TYPE_VIDEO: - streamType = QMediaStreamsControl::VideoStream; - haveVideo = true; - break; - case GST_STREAM_TYPE_AUDIO: - streamType = QMediaStreamsControl::AudioStream; - haveAudio = true; - break; - case GST_STREAM_TYPE_SUBPICTURE: - streamType = QMediaStreamsControl::SubPictureStream; - break; - case GST_STREAM_TYPE_UNKNOWN: { - GstCaps *caps = 0; - g_object_get(streamInfo, "caps", &caps, NULL); - const GstStructure *structure = gst_caps_get_structure(caps, 0); - const gchar *media_type = gst_structure_get_name(structure); - emit error(int(QMediaPlayer::FormatError), QString::fromLatin1("Cannot play stream of type: %1").arg(QString::fromUtf8(media_type))); -#ifdef DEBUG_PLAYBIN - qDebug() << "Encountered unknown stream type"; -#endif - gst_caps_unref(caps); - } - default: - streamType = QMediaStreamsControl::UnknownStream; - break; - } - - QMap<QtMultimedia::MetaData, QVariant> streamProperties; - streamProperties[QtMultimedia::Language] = QString::fromUtf8(languageCode); - - m_streamProperties.append(streamProperties); - m_streamTypes.append(streamType); - } - } - - - if (haveAudio != m_audioAvailable) { - m_audioAvailable = haveAudio; - emit audioAvailableChanged(m_audioAvailable); - } - if (haveVideo != m_videoAvailable) { - m_videoAvailable = haveVideo; - emit videoAvailableChanged(m_videoAvailable); - } - - emit streamsChanged(); -} - -void QGstreamerPlayerSession::updateVideoResolutionTag() -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO; -#endif - QSize size; - QSize aspectRatio; - - GstPad *pad = gst_element_get_static_pad(m_videoIdentity, "src"); - GstCaps *caps = gst_pad_get_negotiated_caps(pad); - - if (caps) { - const GstStructure *structure = gst_caps_get_structure(caps, 0); - gst_structure_get_int(structure, "width", &size.rwidth()); - gst_structure_get_int(structure, "height", &size.rheight()); - - gint aspectNum = 0; - gint aspectDenum = 0; - if (!size.isEmpty() && gst_structure_get_fraction( - structure, "pixel-aspect-ratio", &aspectNum, &aspectDenum)) { - if (aspectDenum > 0) - aspectRatio = QSize(aspectNum, aspectDenum); - } - gst_caps_unref(caps); - } - - gst_object_unref(GST_OBJECT(pad)); - - QSize currentSize = m_tags.value("resolution").toSize(); - QSize currentAspectRatio = m_tags.value("pixel-aspect-ratio").toSize(); - - if (currentSize != size || currentAspectRatio != aspectRatio) { - if (aspectRatio.isEmpty()) - m_tags.remove("pixel-aspect-ratio"); - - if (size.isEmpty()) { - m_tags.remove("resolution"); - } else { - m_tags.insert("resolution", QVariant(size)); - if (!aspectRatio.isEmpty()) - m_tags.insert("pixel-aspect-ratio", QVariant(aspectRatio)); - } - - emit tagsChanged(); - } -} - -void QGstreamerPlayerSession::updateDuration() -{ - GstFormat format = GST_FORMAT_TIME; - gint64 gstDuration = 0; - int duration = -1; - - if (m_playbin && gst_element_query_duration(m_playbin, &format, &gstDuration)) - duration = gstDuration / 1000000; - - if (m_duration != duration) { - m_duration = duration; - emit durationChanged(m_duration); - } - - if (m_duration > 0) - m_durationQueries = 0; - - if (m_durationQueries > 0) { - //increase delay between duration requests - int delay = 25 << (5 - m_durationQueries); - QTimer::singleShot(delay, this, SLOT(updateDuration())); - m_durationQueries--; - } -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO << m_duration; -#endif -} - -void QGstreamerPlayerSession::playbinNotifySource(GObject *o, GParamSpec *p, gpointer d) -{ - Q_UNUSED(p); - - GstElement *source = 0; - g_object_get(o, "source", &source, NULL); - if (source == 0) - return; - -#ifdef DEBUG_PLAYBIN - qDebug() << "Playbin source added:" << G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(source)); -#endif - - // Turn off icecast metadata request, will be re-set if in QNetworkRequest - // (souphttpsrc docs say is false by default, but header appears in request - // @version 0.10.21) - if (g_object_class_find_property(G_OBJECT_GET_CLASS(source), "iradio-mode") != 0) - g_object_set(G_OBJECT(source), "iradio-mode", FALSE, NULL); - - - // Set Headers - const QByteArray userAgentString("User-Agent"); - - QGstreamerPlayerSession *self = reinterpret_cast<QGstreamerPlayerSession *>(d); - - // User-Agent - special case, souphhtpsrc will always set something, even if - // defined in extra-headers - if (g_object_class_find_property(G_OBJECT_GET_CLASS(source), "user-agent") != 0) { - g_object_set(G_OBJECT(source), "user-agent", - self->m_request.rawHeader(userAgentString).constData(), NULL); - } - - // The rest - if (g_object_class_find_property(G_OBJECT_GET_CLASS(source), "extra-headers") != 0) { - GstStructure *extras = gst_structure_empty_new("extras"); - - foreach (const QByteArray &rawHeader, self->m_request.rawHeaderList()) { - if (rawHeader == userAgentString) // Filter User-Agent - continue; - else { - GValue headerValue; - - memset(&headerValue, 0, sizeof(GValue)); - g_value_init(&headerValue, G_TYPE_STRING); - - g_value_set_string(&headerValue, - self->m_request.rawHeader(rawHeader).constData()); - - gst_structure_set_value(extras, rawHeader.constData(), &headerValue); - } - } - - if (gst_structure_n_fields(extras) > 0) - g_object_set(G_OBJECT(source), "extra-headers", extras, NULL); - - gst_structure_free(extras); - } - - //set timeout property to 30 seconds - const int timeout = 30; - if (qstrcmp(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(source)), "GstUDPSrc") == 0) { - //udpsrc timeout unit = microsecond - //The udpsrc is always a live source. - g_object_set(G_OBJECT(source), "timeout", G_GUINT64_CONSTANT(timeout*1000000), NULL); - self->m_sourceType = UDPSrc; - self->m_isLiveSource = true; - } else if (qstrcmp(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(source)), "GstSoupHTTPSrc") == 0) { - //souphttpsrc timeout unit = second - g_object_set(G_OBJECT(source), "timeout", guint(timeout), NULL); - self->m_sourceType = SoupHTTPSrc; - //since gst_base_src_is_live is not reliable, so we check the source property directly - gboolean isLive = false; - g_object_get(G_OBJECT(source), "is-live", &isLive, NULL); - self->m_isLiveSource = isLive; - } else if (qstrcmp(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(source)), "GstMMSSrc") == 0) { - self->m_sourceType = MMSSrc; - self->m_isLiveSource = gst_base_src_is_live(GST_BASE_SRC(source)); - g_object_set(G_OBJECT(source), "tcp-timeout", G_GUINT64_CONSTANT(timeout*1000000), NULL); - } else if (qstrcmp(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(source)), "GstRTSPSrc") == 0) { - //rtspsrc acts like a live source and will therefore only generate data in the PLAYING state. - self->m_sourceType = RTSPSrc; - self->m_isLiveSource = true; - } else { - self->m_sourceType = UnknownSrc; - self->m_isLiveSource = gst_base_src_is_live(GST_BASE_SRC(source)); - } - -#ifdef DEBUG_PLAYBIN - if (self->m_isLiveSource) - qDebug() << "Current source is a live source"; - else - qDebug() << "Current source is a non-live source"; -#endif - - - gst_object_unref(source); -} - -bool QGstreamerPlayerSession::isLiveSource() const -{ - return m_isLiveSource; -} - -void QGstreamerPlayerSession::handleVolumeChange(GObject *o, GParamSpec *p, gpointer d) -{ - Q_UNUSED(o); - Q_UNUSED(p); - QGstreamerPlayerSession *session = reinterpret_cast<QGstreamerPlayerSession *>(d); - QMetaObject::invokeMethod(session, "updateVolume", Qt::QueuedConnection); -} - -void QGstreamerPlayerSession::updateVolume() -{ - double volume = 1.0; - g_object_get(m_playbin, "volume", &volume, NULL); - - //special case for playbin1 volume changes in muted state - //playbin1 has no separate muted state, - //it's emulated with volume value saved and set to 0 - //this change should not be reported to user - if (!m_usePlaybin2 && m_muted) { - if (volume > 0.001) { - //volume is changed, player in not muted any more - m_muted = false; - emit mutedStateChanged(m_muted = false); - } else { - //don't emit volume changed to 0 when player is muted - return; - } - } - - if (m_volume != int(volume*100)) { - m_volume = int(volume*100); -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO << m_muted; -#endif - emit volumeChanged(m_volume); - } -} - -void QGstreamerPlayerSession::handleMutedChange(GObject *o, GParamSpec *p, gpointer d) -{ - Q_UNUSED(o); - Q_UNUSED(p); - QGstreamerPlayerSession *session = reinterpret_cast<QGstreamerPlayerSession *>(d); - QMetaObject::invokeMethod(session, "updateMuted", Qt::QueuedConnection); -} - -void QGstreamerPlayerSession::updateMuted() -{ - gboolean muted = false; - g_object_get(G_OBJECT(m_playbin), "mute", &muted, NULL); - if (m_muted != muted) { - m_muted = muted; -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO << m_muted; -#endif - emit mutedStateChanged(muted); - } -} - - -void QGstreamerPlayerSession::handleElementAdded(GstBin *bin, GstElement *element, QGstreamerPlayerSession *session) -{ - Q_UNUSED(bin); - //we have to configure queue2 element to enable media downloading - //and reporting available ranges, - //but it's added dynamically to playbin2 - - gchar *elementName = gst_element_get_name(element); - - if (g_str_has_prefix(elementName, "queue2")) { - session->m_haveQueueElement = true; - - if (session->property("mediaDownloadEnabled").toBool()) { - QDir cacheDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); - QString cacheLocation = cacheDir.absoluteFilePath("gstmedia__XXXXXX"); -#ifdef DEBUG_PLAYBIN - qDebug() << "set queue2 temp-location" << cacheLocation; -#endif - g_object_set(G_OBJECT(element), "temp-template", cacheLocation.toUtf8().constData(), NULL); - } else { - g_object_set(G_OBJECT(element), "temp-template", NULL, NULL); - } - } else if (g_str_has_prefix(elementName, "uridecodebin") || - g_str_has_prefix(elementName, "decodebin2")) { - //listen for queue2 element added to uridecodebin/decodebin2 as well. - //Don't touch other bins since they may have unrelated queues - g_signal_connect(element, "element-added", - G_CALLBACK(handleElementAdded), session); - } - - g_free(elementName); -} - -//doing proper operations when detecting an invalidMedia: change media status before signal the erorr -void QGstreamerPlayerSession::processInvalidMedia(QMediaPlayer::Error errorCode, const QString& errorString) -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO; -#endif - emit invalidMedia(); - stop(); - emit error(int(errorCode), errorString); -} - -void QGstreamerPlayerSession::showPrerollFrames(bool enabled) -{ -#ifdef DEBUG_PLAYBIN - qDebug() << Q_FUNC_INFO << enabled; -#endif - if (enabled != m_displayPrerolledFrame && m_videoSink && - g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "show-preroll-frame") != 0) { - - gboolean value = enabled; - g_object_set(G_OBJECT(m_videoSink), "show-preroll-frame", value, NULL); - m_displayPrerolledFrame = enabled; - } -} diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.h b/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.h deleted file mode 100644 index 3380e6e..0000000 --- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.h +++ /dev/null @@ -1,229 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERPLAYERSESSION_H -#define QGSTREAMERPLAYERSESSION_H - -#include <QObject> -#include <QtNetwork/qnetworkrequest.h> -#include "qgstreamerplayercontrol.h" -#include <private/qgstreamerbushelper_p.h> -#include <qmediaplayer.h> -#include <qmediastreamscontrol.h> - -#if defined(HAVE_GST_APPSRC) -#include "qgstappsrc.h" -#endif - -#include <gst/gst.h> - -class QGstreamerBusHelper; -class QGstreamerMessage; - -class QGstreamerVideoRendererInterface; - -QT_USE_NAMESPACE - -class QGstreamerPlayerSession : public QObject, - public QGstreamerBusMessageFilter -{ -Q_OBJECT -Q_INTERFACES(QGstreamerBusMessageFilter) - -public: - QGstreamerPlayerSession(QObject *parent); - virtual ~QGstreamerPlayerSession(); - - GstElement *playbin() const; - QGstreamerBusHelper *bus() const { return m_busHelper; } - - QNetworkRequest request() const; - - QMediaPlayer::State state() const { return m_state; } - QMediaPlayer::State pendingState() const { return m_pendingState; } - - qint64 duration() const; - qint64 position() const; - - bool isBuffering() const; - - int bufferingProgress() const; - - int volume() const; - bool isMuted() const; - - bool isAudioAvailable() const; - - void setVideoRenderer(QObject *renderer); - bool isVideoAvailable() const; - - bool isSeekable() const; - - qreal playbackRate() const; - void setPlaybackRate(qreal rate); - - QMediaTimeRange availablePlaybackRanges() const; - - QMap<QByteArray ,QVariant> tags() const { return m_tags; } - QMap<QtMultimedia::MetaData,QVariant> streamProperties(int streamNumber) const { return m_streamProperties[streamNumber]; } - int streamCount() const { return m_streamProperties.count(); } - QMediaStreamsControl::StreamType streamType(int streamNumber) { return m_streamTypes.value(streamNumber, QMediaStreamsControl::UnknownStream); } - - int activeStream(QMediaStreamsControl::StreamType streamType) const; - void setActiveStream(QMediaStreamsControl::StreamType streamType, int streamNumber); - - bool processBusMessage(const QGstreamerMessage &message); - -#if defined(HAVE_GST_APPSRC) - QGstAppSrc *appsrc() const { return m_appSrc; } - static void configureAppSrcElement(GObject*, GObject*, GParamSpec*,QGstreamerPlayerSession* _this); -#endif - - bool isLiveSource() const; - -public slots: - void loadFromUri(const QNetworkRequest &url); - void loadFromStream(const QNetworkRequest &url, QIODevice *stream); - bool play(); - bool pause(); - void stop(); - - bool seek(qint64 pos); - - void setVolume(int volume); - void setMuted(bool muted); - - void showPrerollFrames(bool enabled); - -signals: - void durationChanged(qint64 duration); - void positionChanged(qint64 position); - void stateChanged(QMediaPlayer::State state); - void volumeChanged(int volume); - void mutedStateChanged(bool muted); - void audioAvailableChanged(bool audioAvailable); - void videoAvailableChanged(bool videoAvailable); - void bufferingChanged(bool buffering); - void bufferingProgressChanged(int percentFilled); - void playbackFinished(); - void tagsChanged(); - void streamsChanged(); - void seekableChanged(bool); - void error(int error, const QString &errorString); - void invalidMedia(); - void playbackRateChanged(qreal); - -private slots: - void getStreamsInfo(); - void setSeekable(bool); - void finishVideoOutputChange(); - void updateVideoRenderer(); - void updateVideoResolutionTag(); - void updateVolume(); - void updateMuted(); - void updateDuration(); - -private: - static void playbinNotifySource(GObject *o, GParamSpec *p, gpointer d); - static void handleVolumeChange(GObject *o, GParamSpec *p, gpointer d); - static void handleMutedChange(GObject *o, GParamSpec *p, gpointer d); - static void insertColorSpaceElement(GstElement *element, gpointer data); - static void handleElementAdded(GstBin *bin, GstElement *element, QGstreamerPlayerSession *session); - void processInvalidMedia(QMediaPlayer::Error errorCode, const QString& errorString); - - QNetworkRequest m_request; - QMediaPlayer::State m_state; - QMediaPlayer::State m_pendingState; - QGstreamerBusHelper* m_busHelper; - GstElement* m_playbin; - bool m_usePlaybin2; - - GstElement* m_videoOutputBin; - GstElement* m_videoIdentity; - GstElement* m_colorSpace; - bool m_usingColorspaceElement; - GstElement* m_videoSink; - GstElement* m_pendingVideoSink; - GstElement* m_nullVideoSink; - - GstBus* m_bus; - QObject *m_videoOutput; - QGstreamerVideoRendererInterface *m_renderer; - - bool m_haveQueueElement; - -#if defined(HAVE_GST_APPSRC) - QGstAppSrc *m_appSrc; -#endif - - QMap<QByteArray, QVariant> m_tags; - QList< QMap<QtMultimedia::MetaData,QVariant> > m_streamProperties; - QList<QMediaStreamsControl::StreamType> m_streamTypes; - QMap<QMediaStreamsControl::StreamType, int> m_playbin2StreamOffset; - - - int m_volume; - qreal m_playbackRate; - bool m_muted; - bool m_audioAvailable; - bool m_videoAvailable; - bool m_seekable; - - mutable qint64 m_lastPosition; - qint64 m_duration; - int m_durationQueries; - - bool m_displayPrerolledFrame; - - enum SourceType - { - UnknownSrc, - SoupHTTPSrc, - UDPSrc, - MMSSrc, - RTSPSrc, - }; - SourceType m_sourceType; - bool m_everPlayed; - bool m_isLiveSource; -}; - -#endif // QGSTREAMERPLAYERSESSION_H diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerstreamscontrol.cpp b/src/plugins/gstreamer/mediaplayer/qgstreamerstreamscontrol.cpp deleted file mode 100644 index a5ba871..0000000 --- a/src/plugins/gstreamer/mediaplayer/qgstreamerstreamscontrol.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamerstreamscontrol.h" -#include "qgstreamerplayersession.h" - -QGstreamerStreamsControl::QGstreamerStreamsControl(QGstreamerPlayerSession *session, QObject *parent) - :QMediaStreamsControl(parent), m_session(session) -{ - connect(m_session, SIGNAL(streamsChanged()), SIGNAL(streamsChanged())); -} - -QGstreamerStreamsControl::~QGstreamerStreamsControl() -{ -} - -int QGstreamerStreamsControl::streamCount() -{ - return m_session->streamCount(); -} - -QMediaStreamsControl::StreamType QGstreamerStreamsControl::streamType(int streamNumber) -{ - return m_session->streamType(streamNumber); -} - -QVariant QGstreamerStreamsControl::metaData(int streamNumber, QtMultimedia::MetaData key) -{ - return m_session->streamProperties(streamNumber).value(key); -} - -bool QGstreamerStreamsControl::isActive(int streamNumber) -{ - return streamNumber != -1 && streamNumber == m_session->activeStream(streamType(streamNumber)); -} - -void QGstreamerStreamsControl::setActive(int streamNumber, bool state) -{ - QMediaStreamsControl::StreamType type = m_session->streamType(streamNumber); - if (type == QMediaStreamsControl::UnknownStream) - return; - - if (state) - m_session->setActiveStream(type, streamNumber); - else { - //only one active stream of certain type is supported - if (m_session->activeStream(type) == streamNumber) - m_session->setActiveStream(type, -1); - } -} - diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerstreamscontrol.h b/src/plugins/gstreamer/mediaplayer/qgstreamerstreamscontrol.h deleted file mode 100644 index 77f0f2d..0000000 --- a/src/plugins/gstreamer/mediaplayer/qgstreamerstreamscontrol.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERSTREAMSCONTROL_H -#define QGSTREAMERSTREAMSCONTROL_H - -#include <qmediastreamscontrol.h> - -QT_USE_NAMESPACE - -class QGstreamerPlayerSession; - -class QGstreamerStreamsControl : public QMediaStreamsControl -{ - Q_OBJECT -public: - QGstreamerStreamsControl(QGstreamerPlayerSession *session, QObject *parent); - virtual ~QGstreamerStreamsControl(); - - virtual int streamCount(); - virtual StreamType streamType(int streamNumber); - - virtual QVariant metaData(int streamNumber, QtMultimedia::MetaData key); - - virtual bool isActive(int streamNumber); - virtual void setActive(int streamNumber, bool state); - -private: - QGstreamerPlayerSession *m_session; -}; - -#endif // QGSTREAMERSTREAMSCONTROL_H - diff --git a/src/plugins/gstreamer/qgstcodecsinfo.cpp b/src/plugins/gstreamer/qgstcodecsinfo.cpp deleted file mode 100644 index 34c18a1..0000000 --- a/src/plugins/gstreamer/qgstcodecsinfo.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstcodecsinfo.h" - -#include <QtCore/qset.h> - -#ifdef QMEDIA_GSTREAMER_CAMERABIN -#include <gst/pbutils/pbutils.h> -#include <gst/pbutils/encoding-profile.h> -#endif - - -QGstCodecsInfo::QGstCodecsInfo(QGstCodecsInfo::ElementType elementType) -{ - -#if GST_CHECK_VERSION(0,10,31) - - GstElementFactoryListType gstElementType = 0; - switch (elementType) { - case AudioEncoder: - gstElementType = GST_ELEMENT_FACTORY_TYPE_AUDIO_ENCODER; - break; - case VideoEncoder: - gstElementType = GST_ELEMENT_FACTORY_TYPE_VIDEO_ENCODER; - break; - case Muxer: - gstElementType = GST_ELEMENT_FACTORY_TYPE_MUXER; - break; - } - - GstCaps *allCaps = supportedElementCaps(gstElementType); - GstCaps *caps = gst_caps_new_empty(); - - uint codecsCount = gst_caps_get_size(allCaps); - for (uint i=0; i<codecsCount; i++) { - gst_caps_append_structure(caps, gst_caps_steal_structure(allCaps, 0)); - gchar * capsString = gst_caps_to_string(caps); - - QString codec = QLatin1String(capsString); - m_codecs.append(codec); - -#ifdef QMEDIA_GSTREAMER_CAMERABIN - gchar *description = gst_pb_utils_get_codec_description(caps); - m_codecDescriptions.insert(codec, QString::fromUtf8(description)); - - if (description) - g_free(description); -#else - m_codecDescriptions.insert(codec, codec); -#endif - - if (capsString) - g_free(capsString); - - gst_caps_remove_structure(caps, 0); - } -#else - Q_UNUSED(elementType); -#endif // GST_CHECK_VERSION(0,10,31) -} - -QStringList QGstCodecsInfo::supportedCodecs() const -{ - return m_codecs; -} - -QString QGstCodecsInfo::codecDescription(const QString &codec) const -{ - return m_codecDescriptions.value(codec); -} - -#if GST_CHECK_VERSION(0,10,31) - -/*! - List all supported caps for all installed elements of type \a elementType. - - Caps are simplified to mime type and a few field necessary to distinguish - different codecs like mpegversion or layer. - */ -GstCaps* QGstCodecsInfo::supportedElementCaps(GstElementFactoryListType elementType, - GstRank minimumRank, - GstPadDirection padDirection) -{ - GList *elements = gst_element_factory_list_get_elements(elementType, minimumRank); - GstCaps *res = gst_caps_new_empty(); - - QSet<QByteArray> fakeEncoderMimeTypes; - fakeEncoderMimeTypes << "unknown/unknown" - << "audio/x-raw-int" << "audio/x-raw-float" - << "video/x-raw-yuv" << "video/x-raw-rgb"; - - QSet<QByteArray> fieldsToAdd; - fieldsToAdd << "mpegversion" << "layer" << "layout" << "raversion" - << "wmaversion" << "wmvversion" << "variant"; - - GList *element = elements; - while (element) { - GstElementFactory *factory = (GstElementFactory *)element->data; - element = element->next; - - const GList *padTemplates = gst_element_factory_get_static_pad_templates(factory); - while (padTemplates) { - GstStaticPadTemplate *padTemplate = (GstStaticPadTemplate *)padTemplates->data; - padTemplates = padTemplates->next; - - if (padTemplate->direction == padDirection) { - const GstCaps *caps = gst_static_caps_get(&padTemplate->static_caps); - for (uint i=0; i<gst_caps_get_size(caps); i++) { - const GstStructure *structure = gst_caps_get_structure(caps, i); - - //skip "fake" encoders - if (fakeEncoderMimeTypes.contains(gst_structure_get_name(structure))) - continue; - - GstStructure *newStructure = gst_structure_new(gst_structure_get_name(structure), NULL); - - //add structure fields to distinguish between formats with similar mime types, - //like audio/mpeg - for (int j=0; j<gst_structure_n_fields(structure); j++) { - const gchar* fieldName = gst_structure_nth_field_name(structure, j); - if (fieldsToAdd.contains(fieldName)) { - const GValue *value = gst_structure_get_value(structure, fieldName); - GType valueType = G_VALUE_TYPE(value); - - //don't add values of range type, - //gst_pb_utils_get_codec_description complains about not fixed caps - - if (valueType != GST_TYPE_INT_RANGE && valueType != GST_TYPE_DOUBLE_RANGE && - valueType != GST_TYPE_FRACTION_RANGE && valueType != GST_TYPE_LIST && - valueType != GST_TYPE_ARRAY) - gst_structure_set_value(newStructure, fieldName, value); - } - } - - gst_caps_merge_structure(res, newStructure); - } - } - } - } - gst_plugin_feature_list_free(elements); - - return res; -} -#endif //GST_CHECK_VERSION(0,10,31) diff --git a/src/plugins/gstreamer/qgstcodecsinfo.h b/src/plugins/gstreamer/qgstcodecsinfo.h deleted file mode 100644 index f5a706d..0000000 --- a/src/plugins/gstreamer/qgstcodecsinfo.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTCODECSINFO_H -#define QGSTCODECSINFO_H - -#include <QtCore/qmap.h> -#include <QtCore/qstringlist.h> - -#include <gst/gst.h> - -class QGstCodecsInfo -{ -public: - enum ElementType { AudioEncoder, VideoEncoder, Muxer }; - - QGstCodecsInfo(ElementType elementType); - - QStringList supportedCodecs() const; - QString codecDescription(const QString &codec) const; - -#if GST_CHECK_VERSION(0,10,31) - static GstCaps* supportedElementCaps(GstElementFactoryListType elementType, - GstRank minimumRank = GST_RANK_MARGINAL, - GstPadDirection padDirection = GST_PAD_SRC); -#endif - -private: - QStringList m_codecs; - QMap<QString,QString> m_codecDescriptions; -}; - - -#endif diff --git a/src/plugins/gstreamer/qgstreameraudioinputendpointselector.cpp b/src/plugins/gstreamer/qgstreameraudioinputendpointselector.cpp deleted file mode 100644 index 9433850..0000000 --- a/src/plugins/gstreamer/qgstreameraudioinputendpointselector.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreameraudioinputendpointselector.h" - -#include <QtWidgets/QIcon> -#include <QtCore/QDir> -#include <QtCore/QDebug> - -#include <gst/gst.h> - -#ifdef HAVE_ALSA -#include <alsa/asoundlib.h> -#endif - -QGstreamerAudioInputEndpointSelector::QGstreamerAudioInputEndpointSelector(QObject *parent) - :QAudioEndpointSelector(parent) -{ - update(); -} - -QGstreamerAudioInputEndpointSelector::~QGstreamerAudioInputEndpointSelector() -{ -} - -QList<QString> QGstreamerAudioInputEndpointSelector::availableEndpoints() const -{ - return m_names; -} - -QString QGstreamerAudioInputEndpointSelector::endpointDescription(const QString& name) const -{ - QString desc; - - for (int i = 0; i < m_names.size(); i++) { - if (m_names.at(i).compare(name) == 0) { - desc = m_descriptions.at(i); - break; - } - } - return desc; -} - -QString QGstreamerAudioInputEndpointSelector::defaultEndpoint() const -{ - if (m_names.size() > 0) - return m_names.at(0); - - return QString(); -} - -QString QGstreamerAudioInputEndpointSelector::activeEndpoint() const -{ - return m_audioInput; -} - -void QGstreamerAudioInputEndpointSelector::setActiveEndpoint(const QString& name) -{ - if (m_audioInput.compare(name) != 0) { - m_audioInput = name; - emit activeEndpointChanged(name); - } -} - -void QGstreamerAudioInputEndpointSelector::update() -{ - m_names.clear(); - m_descriptions.clear(); - updateAlsaDevices(); - updateOssDevices(); - updatePulseDevices(); - if (m_names.size() > 0) - m_audioInput = m_names.at(0); -} - -void QGstreamerAudioInputEndpointSelector::updateAlsaDevices() -{ -#ifdef HAVE_ALSA - void **hints, **n; - if (snd_device_name_hint(-1, "pcm", &hints) < 0) { - qWarning()<<"no alsa devices available"; - return; - } - n = hints; - - while (*n != NULL) { - char *name = snd_device_name_get_hint(*n, "NAME"); - char *descr = snd_device_name_get_hint(*n, "DESC"); - char *io = snd_device_name_get_hint(*n, "IOID"); - - if ((name != NULL) && (descr != NULL)) { - if ( io == NULL || qstrcmp(io,"Input") == 0 ) { - m_names.append(QLatin1String("alsa:")+QString::fromUtf8(name)); - m_descriptions.append(QString::fromUtf8(descr)); - } - } - - if (name != NULL) - free(name); - if (descr != NULL) - free(descr); - if (io != NULL) - free(io); - n++; - } - snd_device_name_free_hint(hints); -#endif -} - -void QGstreamerAudioInputEndpointSelector::updateOssDevices() -{ - QDir devDir("/dev"); - devDir.setFilter(QDir::System); - QFileInfoList entries = devDir.entryInfoList(QStringList() << "dsp*"); - foreach(const QFileInfo& entryInfo, entries) { - m_names.append(QLatin1String("oss:")+entryInfo.filePath()); - m_descriptions.append(QString("OSS device %1").arg(entryInfo.fileName())); - } -} - -void QGstreamerAudioInputEndpointSelector::updatePulseDevices() -{ - GstElementFactory *factory = gst_element_factory_find("pulsesrc"); - if (factory) { - m_names.append("pulseaudio:"); - m_descriptions.append("PulseAudio device."); - gst_object_unref(GST_OBJECT(factory)); - } -} diff --git a/src/plugins/gstreamer/qgstreameraudioinputendpointselector.h b/src/plugins/gstreamer/qgstreameraudioinputendpointselector.h deleted file mode 100644 index c69d25e..0000000 --- a/src/plugins/gstreamer/qgstreameraudioinputendpointselector.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERAUDIOINPUTENDPOINTSELECTOR_H -#define QGSTREAMERAUDIOINPUTENDPOINTSELECTOR_H - -#include <qaudioendpointselector.h> -#include <QtCore/qstringlist.h> - -QT_USE_NAMESPACE - -class QGstreamerAudioInputEndpointSelector : public QAudioEndpointSelector -{ -Q_OBJECT -public: - QGstreamerAudioInputEndpointSelector(QObject *parent); - ~QGstreamerAudioInputEndpointSelector(); - - QList<QString> availableEndpoints() const; - QString endpointDescription(const QString& name) const; - QString defaultEndpoint() const; - QString activeEndpoint() const; - -public Q_SLOTS: - void setActiveEndpoint(const QString& name); - -private: - void update(); - void updateAlsaDevices(); - void updateOssDevices(); - void updatePulseDevices(); - - QString m_audioInput; - QList<QString> m_names; - QList<QString> m_descriptions; -}; - -#endif // QGSTREAMERAUDIOINPUTENDPOINTSELECTOR_H diff --git a/src/plugins/gstreamer/qgstreamergltexturerenderer.cpp b/src/plugins/gstreamer/qgstreamergltexturerenderer.cpp deleted file mode 100644 index d9633aa..0000000 --- a/src/plugins/gstreamer/qgstreamergltexturerenderer.cpp +++ /dev/null @@ -1,583 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <private/qvideosurfacegstsink_p.h> -#include <qabstractvideosurface.h> -#include <private/qgstutils_p.h> - -#include <QtGui/qevent.h> -#include <QtWidgets/qapplication.h> -#include <QtWidgets/qx11info_x11.h> -#include <QtCore/qdebug.h> -#include <QtCore/qthread.h> - -#include <QtOpenGL/qgl.h> - -#include <gst/gst.h> -#include <gst/interfaces/xoverlay.h> -#include <gst/interfaces/propertyprobe.h> -#include <gst/interfaces/meegovideotexture.h> -#include <gst/interfaces/meegovideorenderswitch.h> - - -#include <EGL/egl.h> -#include <EGL/eglext.h> - -#include "qgstreamergltexturerenderer.h" - -//#define GL_TEXTURE_SINK_DEBUG 1 - -//from extdefs.h -typedef void *EGLSyncKHR; -typedef khronos_utime_nanoseconds_t EGLTimeKHR; - -#define GL_TEXTURE_EXTERNAL_OES 0x8D65 -#define EGL_SYNC_FENCE_KHR 0x30F9 - -typedef EGLSyncKHR (EGLAPIENTRYP _PFNEGLCREATESYNCKHRPROC) (EGLDisplay dpy, - EGLenum type, const EGLint * attrib_list); -typedef EGLBoolean (EGLAPIENTRYP _PFNEGLDESTROYSYNCKHRPROC) (EGLDisplay dpy, - EGLSyncKHR sync); - - -const QAbstractVideoBuffer::HandleType EGLImageTextureHandle = - QAbstractVideoBuffer::HandleType(QAbstractVideoBuffer::UserHandle+3434); - -// EGLSync functions -_PFNEGLCREATESYNCKHRPROC eglCreateSyncKHR; -_PFNEGLDESTROYSYNCKHRPROC eglDestroySyncKHR; - -class QGStreamerGLTextureBuffer : public QAbstractVideoBuffer -{ -public: - QGStreamerGLTextureBuffer(MeegoGstVideoTexture *textureSink, int frameNumber) : - QAbstractVideoBuffer(EGLImageTextureHandle), - m_textureSink(MEEGO_GST_VIDEO_TEXTURE(textureSink)), - m_frameNumber(frameNumber) - { - } - - ~QGStreamerGLTextureBuffer() - { - } - - - MapMode mapMode() const { return NotMapped; } - uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) - { - Q_UNUSED(mode); - Q_UNUSED(numBytes); - Q_UNUSED(bytesPerLine); - - //acquire_frame should really be called at buffer construction time - //but it conflicts with id-less implementation of gst texture sink. -#if defined(GL_TEXTURE_SINK_DEBUG) && GL_TEXTURE_SINK_DEBUG > 1 - qDebug() << "acquire frame" << m_frameNumber; -#endif - if (!meego_gst_video_texture_acquire_frame(m_textureSink,m_frameNumber)) - qWarning() << Q_FUNC_INFO << "acquire-frame failed" << m_frameNumber; - - -#if defined(GL_TEXTURE_SINK_DEBUG) && GL_TEXTURE_SINK_DEBUG > 1 - qDebug() << "map frame" << m_frameNumber; -#endif - - gboolean bind_status = meego_gst_video_texture_bind_frame(m_textureSink, GL_TEXTURE_EXTERNAL_OES, m_frameNumber); - if (!bind_status) - qWarning() << Q_FUNC_INFO << "bind-frame failed"; - - return (uchar*)1; - } - - void unmap() - { - gboolean bind_status = meego_gst_video_texture_bind_frame(m_textureSink, GL_TEXTURE_EXTERNAL_OES, -1); - -#if defined(GL_TEXTURE_SINK_DEBUG) && GL_TEXTURE_SINK_DEBUG > 1 - qDebug() << "unmap frame" << m_frameNumber; -#endif - - if (!bind_status) - qWarning() << Q_FUNC_INFO << "unbind-frame failed"; - - //release_frame should really be called in destructor - //but this conflicts with id-less implementation of gst texture sink. -#if defined(GL_TEXTURE_SINK_DEBUG) && GL_TEXTURE_SINK_DEBUG > 1 - qDebug() << "release frame" << m_frameNumber; -#endif - EGLSyncKHR sync = eglCreateSyncKHR(eglGetDisplay((EGLNativeDisplayType)QX11Info::display()), EGL_SYNC_FENCE_KHR, NULL); - meego_gst_video_texture_release_frame(m_textureSink, m_frameNumber, sync); - } - - QVariant handle() const - { - return m_frameNumber; - } - -private: - MeegoGstVideoTexture *m_textureSink; - int m_frameNumber; -}; - - -QGstreamerGLTextureRenderer::QGstreamerGLTextureRenderer(QObject *parent) : - QVideoRendererControl(parent), - m_videoSink(0), - m_surface(0), - m_context(0), - m_winId(0), - m_colorKey(49,0,49), - m_overlayEnabled(false), - m_bufferProbeId(-1) -{ - eglCreateSyncKHR = - (_PFNEGLCREATESYNCKHRPROC)eglGetProcAddress("eglCreateSyncKHR"); - eglDestroySyncKHR = - (_PFNEGLDESTROYSYNCKHRPROC)eglGetProcAddress("eglDestroySyncKHR"); -} - -QGstreamerGLTextureRenderer::~QGstreamerGLTextureRenderer() -{ - if (m_surface && m_surface->isActive()) - m_surface->stop(); - - if (m_videoSink) - gst_object_unref(GST_OBJECT(m_videoSink)); -} - -GstElement *QGstreamerGLTextureRenderer::videoSink() -{ - if (!m_videoSink && isReady()) { - if (m_context && !m_surface->supportedPixelFormats(EGLImageTextureHandle).isEmpty()) { -#ifdef GL_TEXTURE_SINK_DEBUG - qDebug() << Q_FUNC_INFO << ": using gltexture sink"; -#endif - if (m_context) - m_context->makeCurrent(); - m_videoSink = gst_element_factory_make("gltexturesink", "egl-texture-sink"); - g_object_set(G_OBJECT(m_videoSink), - "x-display", QX11Info::display(), - "egl-display", eglGetDisplay((EGLNativeDisplayType)QX11Info::display()), - "egl-context", eglGetCurrentContext(), - "colorkey", m_colorKey.rgb(), - "autopaint-colorkey", false, - "use-framebuffer-memory", true, - "render-mode", m_overlayEnabled ? VIDEO_RENDERSWITCH_XOVERLAY_MODE - : VIDEO_RENDERSWITCH_TEXTURE_STREAMING_MODE, - (char*)NULL); - - g_signal_connect(G_OBJECT(m_videoSink), "frame-ready", G_CALLBACK(handleFrameReady), (gpointer)this); - } else { - qWarning() << Q_FUNC_INFO << ": Fallback to QVideoSurfaceGstSink since EGLImageTextureHandle is not supported"; - m_videoSink = reinterpret_cast<GstElement*>(QVideoSurfaceGstSink::createSink(m_surface)); - } - - if (m_videoSink) { - gst_object_ref(GST_OBJECT(m_videoSink)); //Take ownership - gst_object_sink(GST_OBJECT(m_videoSink)); - - GstPad *pad = gst_element_get_static_pad(m_videoSink,"sink"); - m_bufferProbeId = gst_pad_add_buffer_probe(pad, G_CALLBACK(padBufferProbe), this); - } - } - - return m_videoSink; -} - -QAbstractVideoSurface *QGstreamerGLTextureRenderer::surface() const -{ - return m_surface; -} - -void QGstreamerGLTextureRenderer::setSurface(QAbstractVideoSurface *surface) -{ - if (m_surface != surface) { -#ifdef GL_TEXTURE_SINK_DEBUG - qDebug() << Q_FUNC_INFO << surface; -#endif - - bool oldReady = isReady(); - - m_context = const_cast<QGLContext*>(QGLContext::currentContext()); - - if (m_videoSink) - gst_object_unref(GST_OBJECT(m_videoSink)); - - m_videoSink = 0; - - if (m_surface) { - disconnect(m_surface, SIGNAL(supportedFormatsChanged()), - this, SLOT(handleFormatChange())); - } - - m_surface = surface; - - if (oldReady != isReady()) - emit readyChanged(!oldReady); - - if (m_surface) { - connect(m_surface, SIGNAL(supportedFormatsChanged()), - this, SLOT(handleFormatChange())); - } - - emit sinkChanged(); - } -} - -void QGstreamerGLTextureRenderer::handleFormatChange() -{ - if (m_videoSink) - gst_object_unref(GST_OBJECT(m_videoSink)); - - m_videoSink = 0; - emit sinkChanged(); -} - -void QGstreamerGLTextureRenderer::handleFrameReady(GstElement *sink, gint frame, gpointer data) -{ - Q_UNUSED(sink); - QGstreamerGLTextureRenderer* renderer = reinterpret_cast<QGstreamerGLTextureRenderer*>(data); - - QMutexLocker locker(&renderer->m_mutex); - QMetaObject::invokeMethod(renderer, "renderGLFrame", - Qt::QueuedConnection, - Q_ARG(int, frame)); - - //we have to wait to ensure the frame is not reused, - //timeout is added to avoid deadlocks when the main thread is - //waiting for rendering to complete, this is possible for example during state chages. - //If frame is not rendered during 60ms (~1-2 frames interval) it's better to unblock and drop it if necessary - renderer->m_renderCondition.wait(&renderer->m_mutex, 60); -} - -void QGstreamerGLTextureRenderer::renderGLFrame(int frame) -{ -#if defined(GL_TEXTURE_SINK_DEBUG) && GL_TEXTURE_SINK_DEBUG > 1 - qDebug() << Q_FUNC_INFO << "frame:" << frame << "surface active:" << m_surface->isActive(); -#endif - QMutexLocker locker(&m_mutex); - - if (!m_surface) { - m_renderCondition.wakeAll(); - return; - } - - MeegoGstVideoTexture *textureSink = MEEGO_GST_VIDEO_TEXTURE(m_videoSink); - - if (m_context) - m_context->makeCurrent(); - - //don't try to render the frame if state is changed to NULL or READY - GstState pendingState = GST_STATE_NULL; - GstState newState = GST_STATE_NULL; - GstStateChangeReturn res = gst_element_get_state(m_videoSink, - &newState, - &pendingState, - 0);//don't block and return immediately - - if (res == GST_STATE_CHANGE_FAILURE || - newState == GST_STATE_NULL || - pendingState == GST_STATE_NULL) { - stopRenderer(); - m_renderCondition.wakeAll(); - return; - } - - if (!m_surface->isActive()) { - //find the native video size - GstPad *pad = gst_element_get_static_pad(m_videoSink,"sink"); - GstCaps *caps = gst_pad_get_negotiated_caps(pad); - - if (caps) { - QSize newNativeSize = QGstUtils::capsCorrectedResolution(caps); - if (m_nativeSize != newNativeSize) { - m_nativeSize = newNativeSize; - emit nativeSizeChanged(); - } - gst_caps_unref(caps); - } - - //start the surface... - QVideoSurfaceFormat format(m_nativeSize, QVideoFrame::Format_RGB32, EGLImageTextureHandle); - if (!m_surface->start(format)) { - qWarning() << Q_FUNC_INFO << "failed to start video surface" << format; - m_renderCondition.wakeAll(); - return; - } - } - - QGStreamerGLTextureBuffer *buffer = new QGStreamerGLTextureBuffer(textureSink, frame); - QVideoFrame videoFrame(buffer, - m_surface->surfaceFormat().frameSize(), - m_surface->surfaceFormat().pixelFormat()); - m_surface->present(videoFrame); - m_renderCondition.wakeAll(); -} - -bool QGstreamerGLTextureRenderer::isReady() const -{ - if (!m_surface) - return false; - - if (m_winId > 0) - return true; - - //winId is required only for EGLImageTextureHandle compatible surfaces - return m_surface->supportedPixelFormats(EGLImageTextureHandle).isEmpty(); -} - -bool QGstreamerGLTextureRenderer::processBusMessage(const QGstreamerMessage &message) -{ - GstMessage* gm = message.rawMessage(); - -#ifdef GL_TEXTURE_SINK_DEBUG - qDebug() << Q_FUNC_INFO << GST_MESSAGE_TYPE_NAME(gm); -#endif - - if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_STATE_CHANGED && - GST_MESSAGE_SRC(gm) == GST_OBJECT_CAST(m_videoSink)) { - GstState oldState; - GstState newState; - gst_message_parse_state_changed(gm, &oldState, &newState, 0); - -#ifdef GL_TEXTURE_SINK_DEBUG - qDebug() << Q_FUNC_INFO << "State changed:" << oldState << newState; -#endif - - if (newState == GST_STATE_READY || newState == GST_STATE_NULL) { - stopRenderer(); - } - - if (oldState == GST_STATE_READY && newState == GST_STATE_PAUSED) { - updateNativeVideoSize(); - } - } - - return false; -} - -bool QGstreamerGLTextureRenderer::processSyncMessage(const QGstreamerMessage &message) -{ - GstMessage* gm = message.rawMessage(); - - if ((GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ELEMENT) && - gst_structure_has_name(gm->structure, "prepare-xwindow-id") && - m_videoSink && GST_IS_X_OVERLAY(m_videoSink)) { -#ifdef GL_TEXTURE_SINK_DEBUG - qDebug() << Q_FUNC_INFO; -#endif - GstXOverlay *overlay = GST_X_OVERLAY(m_videoSink); - - gst_x_overlay_set_xwindow_id(overlay, m_winId); - - if (!m_displayRect.isEmpty()) { - gst_x_overlay_set_render_rectangle(overlay, - m_displayRect.x(), - m_displayRect.y(), - m_displayRect.width(), - m_displayRect.height()); - } - - GstPad *pad = gst_element_get_static_pad(m_videoSink,"sink"); - m_bufferProbeId = gst_pad_add_buffer_probe(pad, G_CALLBACK(padBufferProbe), this); - - return true; - } - - return false; -} - -void QGstreamerGLTextureRenderer::stopRenderer() -{ -#ifdef GL_TEXTURE_SINK_DEBUG - qDebug() << Q_FUNC_INFO; -#endif - - if (m_surface && m_surface->isActive()) - m_surface->stop(); - - if (!m_nativeSize.isEmpty()) { - m_nativeSize = QSize(); - emit nativeSizeChanged(); - } -} - -bool QGstreamerGLTextureRenderer::overlayEnabled() const -{ - return m_overlayEnabled; -} - -void QGstreamerGLTextureRenderer::setOverlayEnabled(bool enabled) -{ - - if (m_videoSink && (m_overlayEnabled != enabled)) { - qDebug() << Q_FUNC_INFO << enabled; - g_object_set(G_OBJECT(m_videoSink), - "render-mode", - enabled ? VIDEO_RENDERSWITCH_XOVERLAY_MODE : VIDEO_RENDERSWITCH_TEXTURE_STREAMING_MODE, - (char *)NULL); - } - - m_overlayEnabled = enabled; -} - - -WId QGstreamerGLTextureRenderer::winId() const -{ - return m_winId; -} - -void QGstreamerGLTextureRenderer::setWinId(WId id) -{ -#ifdef GL_TEXTURE_SINK_DEBUG - qDebug() << Q_FUNC_INFO << id; -#endif - - if (m_winId == id) - return; - - bool oldReady = isReady(); - - m_winId = id; - - if (m_videoSink && GST_IS_X_OVERLAY(m_videoSink)) { - //don't set winId in NULL state, - //texture sink opens xvideo port on set_xwindow_id, - //this fails if video resource is not granted by resource policy yet. - //state is changed to READY/PAUSED/PLAYING only after resource is granted. - GstState pendingState = GST_STATE_NULL; - GstState newState = GST_STATE_NULL; - GstStateChangeReturn res = gst_element_get_state(m_videoSink, - &newState, - &pendingState, - 0);//don't block and return immediately - - if (res != GST_STATE_CHANGE_FAILURE && - newState != GST_STATE_NULL && - pendingState != GST_STATE_NULL) - gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(m_videoSink), m_winId); - } - - if (oldReady != isReady()) - emit readyChanged(!oldReady); -} - -QRect QGstreamerGLTextureRenderer::overlayGeometry() const -{ - return m_displayRect; -} - -void QGstreamerGLTextureRenderer::setOverlayGeometry(const QRect &geometry) -{ - if (m_displayRect != geometry) { -#ifdef GL_TEXTURE_SINK_DEBUG - qDebug() << Q_FUNC_INFO << geometry; -#endif - m_displayRect = geometry; - - if (m_videoSink && GST_IS_X_OVERLAY(m_videoSink)) { - if (m_displayRect.isEmpty()) - gst_x_overlay_set_render_rectangle(GST_X_OVERLAY(m_videoSink), -1, -1, -1, -1); - else - gst_x_overlay_set_render_rectangle(GST_X_OVERLAY(m_videoSink), - m_displayRect.x(), - m_displayRect.y(), - m_displayRect.width(), - m_displayRect.height()); - repaintOverlay(); - } - } -} - -QColor QGstreamerGLTextureRenderer::colorKey() const -{ - return m_colorKey; -} - -void QGstreamerGLTextureRenderer::repaintOverlay() -{ - if (m_videoSink && GST_IS_X_OVERLAY(m_videoSink)) { - //don't call gst_x_overlay_expose if the sink is in null state - GstState state = GST_STATE_NULL; - GstStateChangeReturn res = gst_element_get_state(m_videoSink, &state, NULL, 1000000); - if (res != GST_STATE_CHANGE_FAILURE && state != GST_STATE_NULL) { - gst_x_overlay_expose(GST_X_OVERLAY(m_videoSink)); - } - } -} - -QSize QGstreamerGLTextureRenderer::nativeSize() const -{ - return m_nativeSize; -} - -gboolean QGstreamerGLTextureRenderer::padBufferProbe(GstPad *pad, GstBuffer *buffer, gpointer user_data) -{ - QGstreamerGLTextureRenderer *control = reinterpret_cast<QGstreamerGLTextureRenderer*>(user_data); - QMetaObject::invokeMethod(control, "updateNativeVideoSize", Qt::QueuedConnection); - gst_pad_remove_buffer_probe(pad, control->m_bufferProbeId); - - return TRUE; -} - -void QGstreamerGLTextureRenderer::updateNativeVideoSize() -{ - const QSize oldSize = m_nativeSize; - - if (m_videoSink) { - //find video native size to update video widget size hint - GstPad *pad = gst_element_get_static_pad(m_videoSink,"sink"); - GstCaps *caps = gst_pad_get_negotiated_caps(pad); - - if (caps) { - m_nativeSize = QGstUtils::capsCorrectedResolution(caps); - gst_caps_unref(caps); - } - } else { - m_nativeSize = QSize(); - } -#ifdef GL_TEXTURE_SINK_DEBUG - qDebug() << Q_FUNC_INFO << oldSize << m_nativeSize << m_videoSink; -#endif - - if (m_nativeSize != oldSize) - emit nativeSizeChanged(); -} diff --git a/src/plugins/gstreamer/qgstreamergltexturerenderer.h b/src/plugins/gstreamer/qgstreamergltexturerenderer.h deleted file mode 100644 index 244e07f..0000000 --- a/src/plugins/gstreamer/qgstreamergltexturerenderer.h +++ /dev/null @@ -1,130 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERGLTEXTURERENDERER_H -#define QGSTREAMERGLTEXTURERENDERER_H - -#include <qvideorenderercontrol.h> -#include <private/qvideosurfacegstsink_p.h> -#include <private/qgstreamerbushelper_p.h> - -#include "qgstreamervideorendererinterface.h" -#include <QtGui/qcolor.h> - -#include <X11/extensions/Xv.h> - -QT_USE_NAMESPACE - -class QGLContext; - -class QGstreamerGLTextureRenderer : public QVideoRendererControl, - public QGstreamerVideoRendererInterface, - public QGstreamerSyncMessageFilter, - public QGstreamerBusMessageFilter -{ - Q_OBJECT - Q_INTERFACES(QGstreamerVideoRendererInterface QGstreamerSyncMessageFilter QGstreamerBusMessageFilter) - - Q_PROPERTY(bool overlayEnabled READ overlayEnabled WRITE setOverlayEnabled) - Q_PROPERTY(qulonglong winId READ winId WRITE setWinId) - Q_PROPERTY(QRect overlayGeometry READ overlayGeometry WRITE setOverlayGeometry) - Q_PROPERTY(QColor colorKey READ colorKey) - Q_PROPERTY(QSize nativeSize READ nativeSize NOTIFY nativeSizeChanged) - -public: - QGstreamerGLTextureRenderer(QObject *parent = 0); - virtual ~QGstreamerGLTextureRenderer(); - - QAbstractVideoSurface *surface() const; - void setSurface(QAbstractVideoSurface *surface); - - GstElement *videoSink(); - - bool isReady() const; - bool processBusMessage(const QGstreamerMessage &message); - bool processSyncMessage(const QGstreamerMessage &message); - void stopRenderer(); - - int framebufferNumber() const; - - bool overlayEnabled() const; - WId winId() const; - QRect overlayGeometry() const; - QColor colorKey() const; - QSize nativeSize() const; - -public slots: - void renderGLFrame(int); - - void setOverlayEnabled(bool); - void setWinId(WId id); - void setOverlayGeometry(const QRect &geometry); - void repaintOverlay(); - -signals: - void sinkChanged(); - void readyChanged(bool); - void nativeSizeChanged(); - -private slots: - void handleFormatChange(); - void updateNativeVideoSize(); - -private: - static void handleFrameReady(GstElement *sink, gint frame, gpointer data); - static gboolean padBufferProbe(GstPad *pad, GstBuffer *buffer, gpointer user_data); - - GstElement *m_videoSink; - QAbstractVideoSurface *m_surface; - QGLContext *m_context; - QSize m_nativeSize; - - WId m_winId; - QColor m_colorKey; - QRect m_displayRect; - bool m_overlayEnabled; - int m_bufferProbeId; - - QMutex m_mutex; - QWaitCondition m_renderCondition; -}; - -#endif // QGSTREAMERVIDEORENDRER_H diff --git a/src/plugins/gstreamer/qgstreamerserviceplugin.cpp b/src/plugins/gstreamer/qgstreamerserviceplugin.cpp deleted file mode 100644 index 64d71c5..0000000 --- a/src/plugins/gstreamer/qgstreamerserviceplugin.cpp +++ /dev/null @@ -1,395 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qstring.h> -#include <QtCore/qdebug.h> -#include <QtWidgets/QIcon> -#include <QtCore/QDir> -#include <QtCore/QDebug> - -#include "qgstreamerserviceplugin.h" - -//#define QT_SUPPORTEDMIMETYPES_DEBUG - -#ifdef QMEDIA_GSTREAMER_PLAYER -#include "qgstreamerplayerservice.h" -#endif - -#if defined(QMEDIA_GSTREAMER_CAPTURE) -#include "qgstreamercaptureservice.h" -#endif - -#ifdef QMEDIA_GSTREAMER_CAMERABIN -#include "camerabinservice.h" -#endif - -#include <qmediaserviceprovider.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> - - -QStringList QGstreamerServicePlugin::keys() const -{ - return QStringList() -#ifdef QMEDIA_GSTREAMER_PLAYER - << QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER) -#endif - -#ifdef QMEDIA_GSTREAMER_CAPTURE - << QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE) - << QLatin1String(Q_MEDIASERVICE_CAMERA) -#elif defined(QMEDIA_GSTREAMER_CAMERABIN) - << QLatin1String(Q_MEDIASERVICE_CAMERA) -#endif - ; - -} - -QMediaService* QGstreamerServicePlugin::create(const QString &key) -{ - static bool initialized = false; - if (!initialized) { - initialized = true; - gst_init(NULL, NULL); - } - -#ifdef QMEDIA_GSTREAMER_PLAYER - if (key == QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER)) - return new QGstreamerPlayerService; -#endif - -#ifdef QMEDIA_GSTREAMER_CAMERABIN - if (key == QLatin1String(Q_MEDIASERVICE_CAMERA) && CameraBinService::isCameraBinAvailable()) - return new CameraBinService(key); -#endif - -#ifdef QMEDIA_GSTREAMER_CAPTURE - if (key == QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE)) - return new QGstreamerCaptureService(key); - - if (key == QLatin1String(Q_MEDIASERVICE_CAMERA)) - return new QGstreamerCaptureService(key); -#endif - - qWarning() << "Gstreamer service plugin: unsupported key:" << key; - return 0; -} - -void QGstreamerServicePlugin::release(QMediaService *service) -{ - delete service; -} - -QMediaServiceProviderHint::Features QGstreamerServicePlugin::supportedFeatures( - const QByteArray &service) const -{ - if (service == Q_MEDIASERVICE_MEDIAPLAYER) - return QMediaServiceProviderHint::StreamPlayback | QMediaServiceProviderHint::VideoSurface; - else if (service == Q_MEDIASERVICE_CAMERA) - return QMediaServiceProviderHint::VideoSurface; - else - return QMediaServiceProviderHint::Features(); -} - -QList<QByteArray> QGstreamerServicePlugin::devices(const QByteArray &service) const -{ - if (service == Q_MEDIASERVICE_CAMERA) { - if (m_cameraDevices.isEmpty()) - updateDevices(); - - return m_cameraDevices; - } - - return QList<QByteArray>(); -} - -QString QGstreamerServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device) -{ - if (service == Q_MEDIASERVICE_CAMERA) { - if (m_cameraDevices.isEmpty()) - updateDevices(); - - for (int i=0; i<m_cameraDevices.count(); i++) - if (m_cameraDevices[i] == device) - return m_cameraDescriptions[i]; - } - - return QString(); -} - -QVariant QGstreamerServicePlugin::deviceProperty(const QByteArray &service, const QByteArray &device, const QByteArray &property) -{ - Q_UNUSED(service); - Q_UNUSED(device); - Q_UNUSED(property); - return QVariant(); -} - -void QGstreamerServicePlugin::updateDevices() const -{ - m_cameraDevices.clear(); - m_cameraDescriptions.clear(); - -#ifdef Q_WS_MAEMO_6 - m_cameraDevices << "primary" << "secondary"; - m_cameraDescriptions << tr("Main camera") << tr("Front camera"); - return; -#endif - - QDir devDir("/dev"); - devDir.setFilter(QDir::System); - - QFileInfoList entries = devDir.entryInfoList(QStringList() << "video*"); - - foreach( const QFileInfo &entryInfo, entries ) { - //qDebug() << "Try" << entryInfo.filePath(); - - int fd = ::open(entryInfo.filePath().toLatin1().constData(), O_RDWR ); - if (fd == -1) - continue; - - bool isCamera = false; - - v4l2_input input; - memset(&input, 0, sizeof(input)); - for (; ::ioctl(fd, VIDIOC_ENUMINPUT, &input) >= 0; ++input.index) { - if(input.type == V4L2_INPUT_TYPE_CAMERA || input.type == 0) { - isCamera = ::ioctl(fd, VIDIOC_S_INPUT, input.index) != 0; - break; - } - } - - if (isCamera) { - // find out its driver "name" - QString name; - struct v4l2_capability vcap; - memset(&vcap, 0, sizeof(struct v4l2_capability)); - - if (ioctl(fd, VIDIOC_QUERYCAP, &vcap) != 0) - name = entryInfo.fileName(); - else - name = QString((const char*)vcap.card); - //qDebug() << "found camera: " << name; - - m_cameraDevices.append(entryInfo.filePath().toLocal8Bit()); - m_cameraDescriptions.append(name); - } - ::close(fd); - } -} - -namespace { - const char* getCodecAlias(const QString &codec) - { - if (codec.startsWith("avc1.")) - return "video/x-h264"; - - if (codec.startsWith("mp4a.")) - return "audio/mpeg4"; - - if (codec.startsWith("mp4v.20.")) - return "video/mpeg4"; - - if (codec == "samr") - return "audio/amr"; - - return 0; - } - - const char* getMimeTypeAlias(const QString &mimeType) - { - if (mimeType == "video/mp4") - return "video/mpeg4"; - - if (mimeType == "audio/mp4") - return "audio/mpeg4"; - - if (mimeType == "video/ogg" - || mimeType == "audio/ogg") - return "application/ogg"; - - return 0; - } -} - -QtMultimedia::SupportEstimate QGstreamerServicePlugin::hasSupport(const QString &mimeType, - const QStringList& codecs) const -{ - if (m_supportedMimeTypeSet.isEmpty()) - updateSupportedMimeTypes(); - - QString mimeTypeLowcase = mimeType.toLower(); - bool containsMimeType = m_supportedMimeTypeSet.contains(mimeTypeLowcase); - if (!containsMimeType) { - const char* mimeTypeAlias = getMimeTypeAlias(mimeTypeLowcase); - containsMimeType = m_supportedMimeTypeSet.contains(mimeTypeAlias); - if (!containsMimeType) { - containsMimeType = m_supportedMimeTypeSet.contains("video/" + mimeTypeLowcase) - || m_supportedMimeTypeSet.contains("video/x-" + mimeTypeLowcase) - || m_supportedMimeTypeSet.contains("audio/" + mimeTypeLowcase) - || m_supportedMimeTypeSet.contains("audio/x-" + mimeTypeLowcase); - } - } - - int supportedCodecCount = 0; - foreach(const QString &codec, codecs) { - QString codecLowcase = codec.toLower(); - const char* codecAlias = getCodecAlias(codecLowcase); - if (codecAlias) { - if (m_supportedMimeTypeSet.contains(codecAlias)) - supportedCodecCount++; - } else if (m_supportedMimeTypeSet.contains("video/" + codecLowcase) - || m_supportedMimeTypeSet.contains("video/x-" + codecLowcase) - || m_supportedMimeTypeSet.contains("audio/" + codecLowcase) - || m_supportedMimeTypeSet.contains("audio/x-" + codecLowcase)) { - supportedCodecCount++; - } - } - if (supportedCodecCount > 0 && supportedCodecCount == codecs.size()) - return QtMultimedia::ProbablySupported; - - if (supportedCodecCount == 0 && !containsMimeType) - return QtMultimedia::NotSupported; - - return QtMultimedia::MaybeSupported; -} - -void QGstreamerServicePlugin::updateSupportedMimeTypes() const -{ - //enumerate supported mime types - gst_init(NULL, NULL); - - GList *plugins, *orig_plugins; - orig_plugins = plugins = gst_default_registry_get_plugin_list (); - - while (plugins) { - GList *features, *orig_features; - - GstPlugin *plugin = (GstPlugin *) (plugins->data); - plugins = g_list_next (plugins); - - if (plugin->flags & (1<<1)) //GST_PLUGIN_FLAG_BLACKLISTED - continue; - - orig_features = features = gst_registry_get_feature_list_by_plugin(gst_registry_get_default (), - plugin->desc.name); - while (features) { - if (!G_UNLIKELY(features->data == NULL)) { - GstPluginFeature *feature = GST_PLUGIN_FEATURE(features->data); - if (GST_IS_ELEMENT_FACTORY (feature)) { - GstElementFactory *factory = GST_ELEMENT_FACTORY(gst_plugin_feature_load(feature)); - if (factory - && factory->numpadtemplates > 0 - && (qstrcmp(factory->details.klass, "Codec/Decoder/Audio") == 0 - || qstrcmp(factory->details.klass, "Codec/Decoder/Video") == 0 - || qstrcmp(factory->details.klass, "Codec/Demux") == 0 )) { - const GList *pads = factory->staticpadtemplates; - while (pads) { - GstStaticPadTemplate *padtemplate = (GstStaticPadTemplate*)(pads->data); - pads = g_list_next (pads); - if (padtemplate->direction != GST_PAD_SINK) - continue; - if (padtemplate->static_caps.string) { - GstCaps *caps = gst_static_caps_get(&padtemplate->static_caps); - if (!gst_caps_is_any (caps) && ! gst_caps_is_empty (caps)) { - for (guint i = 0; i < gst_caps_get_size(caps); i++) { - GstStructure *structure = gst_caps_get_structure(caps, i); - QString nameLowcase = QString(gst_structure_get_name (structure)).toLower(); - - m_supportedMimeTypeSet.insert(nameLowcase); - if (nameLowcase.contains("mpeg")) { - //Because mpeg version number is only included in the detail - //description, it is necessary to manually extract this information - //in order to match the mime type of mpeg4. - const GValue *value = gst_structure_get_value(structure, "mpegversion"); - if (value) { - gchar *str = gst_value_serialize (value); - QString versions(str); - QStringList elements = versions.split(QRegExp("\\D+"), QString::SkipEmptyParts); - foreach(const QString &e, elements) - m_supportedMimeTypeSet.insert(nameLowcase + e); - g_free (str); - } - } - } - } - } - } - gst_object_unref (factory); - } - } else if (GST_IS_TYPE_FIND_FACTORY(feature)) { - QString name(gst_plugin_feature_get_name(feature)); - if (name.contains('/')) //filter out any string without '/' which is obviously not a mime type - m_supportedMimeTypeSet.insert(name.toLower()); - } - } - features = g_list_next (features); - } - gst_plugin_feature_list_free (orig_features); - } - gst_plugin_list_free (orig_plugins); - -#if defined QT_SUPPORTEDMIMETYPES_DEBUG - QStringList list = m_supportedMimeTypeSet.toList(); - list.sort(); - if (qgetenv("QT_DEBUG_PLUGINS").toInt() > 0) { - foreach(const QString &type, list) - qDebug() << type; - } -#endif -} - -QStringList QGstreamerServicePlugin::supportedMimeTypes() const -{ - return QStringList(); -} - -Q_EXPORT_PLUGIN2(qtmedia_gstengine, QGstreamerServicePlugin); diff --git a/src/plugins/gstreamer/qgstreamerserviceplugin.h b/src/plugins/gstreamer/qgstreamerserviceplugin.h deleted file mode 100644 index ddb5dc1..0000000 --- a/src/plugins/gstreamer/qgstreamerserviceplugin.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QGSTREAMERSERVICEPLUGIN_H -#define QGSTREAMERSERVICEPLUGIN_H - -#include <qmediaserviceproviderplugin.h> -#include <QtCore/qset.h> - -QT_USE_NAMESPACE - - -class QGstreamerServicePlugin - : public QMediaServiceProviderPlugin - , public QMediaServiceSupportedDevicesInterface - , public QMediaServiceFeaturesInterface - , public QMediaServiceSupportedFormatsInterface -{ - Q_OBJECT - Q_INTERFACES(QMediaServiceSupportedDevicesInterface) - Q_INTERFACES(QMediaServiceFeaturesInterface) - Q_INTERFACES(QMediaServiceSupportedFormatsInterface) -public: - QStringList keys() const; - QMediaService* create(QString const& key); - void release(QMediaService *service); - - QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const; - - QList<QByteArray> devices(const QByteArray &service) const; - QString deviceDescription(const QByteArray &service, const QByteArray &device); - QVariant deviceProperty(const QByteArray &service, const QByteArray &device, const QByteArray &property); - - QtMultimedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const; - QStringList supportedMimeTypes() const; - -private: - void updateDevices() const; - - mutable QList<QByteArray> m_cameraDevices; - mutable QStringList m_cameraDescriptions; - mutable QSet<QString> m_supportedMimeTypeSet; //for fast access - - void updateSupportedMimeTypes() const; -}; - -#endif // QGSTREAMERSERVICEPLUGIN_H diff --git a/src/plugins/gstreamer/qgstreamervideoinputdevicecontrol.cpp b/src/plugins/gstreamer/qgstreamervideoinputdevicecontrol.cpp deleted file mode 100644 index ec9e9ba..0000000 --- a/src/plugins/gstreamer/qgstreamervideoinputdevicecontrol.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamervideoinputdevicecontrol.h" - -#include <QtWidgets/QIcon> -#include <QtCore/QDir> -#include <QtCore/QDebug> - -#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> - -QGstreamerVideoInputDeviceControl::QGstreamerVideoInputDeviceControl(QObject *parent) - :QVideoDeviceControl(parent), m_selectedDevice(0) -{ - update(); -} - -QGstreamerVideoInputDeviceControl::~QGstreamerVideoInputDeviceControl() -{ -} - -int QGstreamerVideoInputDeviceControl::deviceCount() const -{ - return m_names.size(); -} - -QString QGstreamerVideoInputDeviceControl::deviceName(int index) const -{ - return m_names[index]; -} - -QString QGstreamerVideoInputDeviceControl::deviceDescription(int index) const -{ - return m_descriptions[index]; -} - -QIcon QGstreamerVideoInputDeviceControl::deviceIcon(int index) const -{ - Q_UNUSED(index); - return QIcon(); -} - -int QGstreamerVideoInputDeviceControl::defaultDevice() const -{ - return 0; -} - -int QGstreamerVideoInputDeviceControl::selectedDevice() const -{ - return m_selectedDevice; -} - - -void QGstreamerVideoInputDeviceControl::setSelectedDevice(int index) -{ - if (index != m_selectedDevice) { - m_selectedDevice = index; - emit selectedDeviceChanged(index); - emit selectedDeviceChanged(deviceName(index)); - } -} - - -void QGstreamerVideoInputDeviceControl::update() -{ - m_names.clear(); - m_descriptions.clear(); - -#ifdef Q_WS_MAEMO_6 - m_names << QLatin1String("primary") << QLatin1String("secondary"); - m_descriptions << tr("Main camera") << tr("Front camera"); -#else - QDir devDir("/dev"); - devDir.setFilter(QDir::System); - - QFileInfoList entries = devDir.entryInfoList(QStringList() << "video*"); - - foreach( const QFileInfo &entryInfo, entries ) { - //qDebug() << "Try" << entryInfo.filePath(); - - int fd = ::open(entryInfo.filePath().toLatin1().constData(), O_RDWR ); - if (fd == -1) - continue; - - bool isCamera = false; - - v4l2_input input; - memset(&input, 0, sizeof(input)); - for (; ::ioctl(fd, VIDIOC_ENUMINPUT, &input) >= 0; ++input.index) { - if(input.type == V4L2_INPUT_TYPE_CAMERA || input.type == 0) { - isCamera = ::ioctl(fd, VIDIOC_S_INPUT, input.index) != 0; - break; - } - } - - if (isCamera) { - // find out its driver "name" - QString name; - struct v4l2_capability vcap; - memset(&vcap, 0, sizeof(struct v4l2_capability)); - - if (ioctl(fd, VIDIOC_QUERYCAP, &vcap) != 0) - name = entryInfo.fileName(); - else - name = QString((const char*)vcap.card); - //qDebug() << "found camera: " << name; - - m_names.append(entryInfo.filePath()); - m_descriptions.append(name); - } - ::close(fd); - } -#endif -} diff --git a/src/plugins/gstreamer/qgstreamervideoinputdevicecontrol.h b/src/plugins/gstreamer/qgstreamervideoinputdevicecontrol.h deleted file mode 100644 index cc8129e..0000000 --- a/src/plugins/gstreamer/qgstreamervideoinputdevicecontrol.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERVIDEOINPUTDEVICECONTROL_H -#define QGSTREAMERVIDEOINPUTDEVICECONTROL_H - -#include <qvideodevicecontrol.h> -#include <QtCore/qstringlist.h> - -QT_USE_NAMESPACE - -class QGstreamerVideoInputDeviceControl : public QVideoDeviceControl -{ -Q_OBJECT -public: - QGstreamerVideoInputDeviceControl(QObject *parent); - ~QGstreamerVideoInputDeviceControl(); - - int deviceCount() const; - - QString deviceName(int index) const; - QString deviceDescription(int index) const; - QIcon deviceIcon(int index) const; - - int defaultDevice() const; - int selectedDevice() const; - -public Q_SLOTS: - void setSelectedDevice(int index); - -private: - void update(); - - int m_selectedDevice; - QStringList m_names; - QStringList m_descriptions; -}; - -#endif // QGSTREAMERAUDIOINPUTDEVICECONTROL_H diff --git a/src/plugins/gstreamer/qgstreamervideooverlay.cpp b/src/plugins/gstreamer/qgstreamervideooverlay.cpp deleted file mode 100644 index f19ef6a..0000000 --- a/src/plugins/gstreamer/qgstreamervideooverlay.cpp +++ /dev/null @@ -1,232 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamervideooverlay.h" -#include <private/qvideosurfacegstsink_p.h> - -#include <qvideosurfaceformat.h> - -#include <private/qx11videosurface_p.h> - -#ifndef QT_NO_XVIDEO - -QGstreamerVideoOverlay::QGstreamerVideoOverlay(QObject *parent) - : QVideoWindowControl(parent) - , m_surface(new QX11VideoSurface) - , m_videoSink(reinterpret_cast<GstElement*>(QVideoSurfaceGstSink::createSink(m_surface))) - , m_aspectRatioMode(Qt::KeepAspectRatio) - , m_fullScreen(false) -{ - if (m_videoSink) { - gst_object_ref(GST_OBJECT(m_videoSink)); //Take ownership - gst_object_sink(GST_OBJECT(m_videoSink)); - } - - connect(m_surface, SIGNAL(surfaceFormatChanged(QVideoSurfaceFormat)), - this, SLOT(surfaceFormatChanged())); -} - -QGstreamerVideoOverlay::~QGstreamerVideoOverlay() -{ - if (m_videoSink) - gst_object_unref(GST_OBJECT(m_videoSink)); - - delete m_surface; -} - -WId QGstreamerVideoOverlay::winId() const -{ - return m_surface->winId(); -} - -void QGstreamerVideoOverlay::setWinId(WId id) -{ - bool wasReady = isReady(); - m_surface->setWinId(id); - - if (isReady() != wasReady) - emit readyChanged(!wasReady); -} - -QRect QGstreamerVideoOverlay::displayRect() const -{ - return m_displayRect; -} - -void QGstreamerVideoOverlay::setDisplayRect(const QRect &rect) -{ - m_displayRect = rect; - - setScaledDisplayRect(); -} - -Qt::AspectRatioMode QGstreamerVideoOverlay::aspectRatioMode() const -{ - return m_aspectRatioMode; -} - -void QGstreamerVideoOverlay::setAspectRatioMode(Qt::AspectRatioMode mode) -{ - m_aspectRatioMode = mode; - - setScaledDisplayRect(); -} - -void QGstreamerVideoOverlay::repaint() -{ -} - -int QGstreamerVideoOverlay::brightness() const -{ - return m_surface->brightness(); -} - -void QGstreamerVideoOverlay::setBrightness(int brightness) -{ - m_surface->setBrightness(brightness); - - emit brightnessChanged(m_surface->brightness()); -} - -int QGstreamerVideoOverlay::contrast() const -{ - return m_surface->contrast(); -} - -void QGstreamerVideoOverlay::setContrast(int contrast) -{ - m_surface->setContrast(contrast); - - emit contrastChanged(m_surface->contrast()); -} - -int QGstreamerVideoOverlay::hue() const -{ - return m_surface->hue(); -} - -void QGstreamerVideoOverlay::setHue(int hue) -{ - m_surface->setHue(hue); - - emit hueChanged(m_surface->hue()); -} - -int QGstreamerVideoOverlay::saturation() const -{ - return m_surface->saturation(); -} - -void QGstreamerVideoOverlay::setSaturation(int saturation) -{ - m_surface->setSaturation(saturation); - - emit saturationChanged(m_surface->saturation()); -} - -bool QGstreamerVideoOverlay::isFullScreen() const -{ - return m_fullScreen; -} - -void QGstreamerVideoOverlay::setFullScreen(bool fullScreen) -{ - emit fullScreenChanged(m_fullScreen = fullScreen); -} - -QSize QGstreamerVideoOverlay::nativeSize() const -{ - return m_surface->surfaceFormat().sizeHint(); -} - -QAbstractVideoSurface *QGstreamerVideoOverlay::surface() const -{ - return m_surface; -} - -GstElement *QGstreamerVideoOverlay::videoSink() -{ - return m_videoSink; -} - -void QGstreamerVideoOverlay::surfaceFormatChanged() -{ - setScaledDisplayRect(); - - emit nativeSizeChanged(); -} - -void QGstreamerVideoOverlay::setScaledDisplayRect() -{ - QRect formatViewport = m_surface->surfaceFormat().viewport(); - - switch (m_aspectRatioMode) { - case Qt::KeepAspectRatio: - { - QSize size = m_surface->surfaceFormat().sizeHint(); - size.scale(m_displayRect.size(), Qt::KeepAspectRatio); - - QRect rect(QPoint(0, 0), size); - rect.moveCenter(m_displayRect.center()); - - m_surface->setDisplayRect(rect); - m_surface->setViewport(formatViewport); - } - break; - case Qt::IgnoreAspectRatio: - m_surface->setDisplayRect(m_displayRect); - m_surface->setViewport(formatViewport); - break; - case Qt::KeepAspectRatioByExpanding: - { - QSize size = m_displayRect.size(); - size.scale(m_surface->surfaceFormat().sizeHint(), Qt::KeepAspectRatio); - - QRect viewport(QPoint(0, 0), size); - viewport.moveCenter(formatViewport.center()); - m_surface->setDisplayRect(m_displayRect); - m_surface->setViewport(viewport); - } - break; - }; -} - -#endif //QT_NO_XVIDEO diff --git a/src/plugins/gstreamer/qgstreamervideooverlay.h b/src/plugins/gstreamer/qgstreamervideooverlay.h deleted file mode 100644 index d8c252f..0000000 --- a/src/plugins/gstreamer/qgstreamervideooverlay.h +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERVIDEOOVERLAY_H -#define QGSTREAMERVIDEOOVERLAY_H - -#include <qvideowindowcontrol.h> - -#include "qgstreamervideorendererinterface.h" - -QT_BEGIN_NAMESPACE -class QAbstractVideoSurface; -QT_END_NAMESPACE -class QX11VideoSurface; - -#if defined(Q_WS_X11) && !defined(QT_NO_XVIDEO) - -QT_USE_NAMESPACE - -class QGstreamerVideoOverlay : public QVideoWindowControl, public QGstreamerVideoRendererInterface -{ - Q_OBJECT - Q_INTERFACES(QGstreamerVideoRendererInterface) -public: - QGstreamerVideoOverlay(QObject *parent = 0); - ~QGstreamerVideoOverlay(); - - WId winId() const; - void setWinId(WId id); - - QRect displayRect() const; - void setDisplayRect(const QRect &rect); - - bool isFullScreen() const; - void setFullScreen(bool fullScreen); - - QSize nativeSize() const; - - Qt::AspectRatioMode aspectRatioMode() const; - void setAspectRatioMode(Qt::AspectRatioMode mode); - - void repaint(); - - int brightness() const; - void setBrightness(int brightness); - - int contrast() const; - void setContrast(int contrast); - - int hue() const; - void setHue(int hue); - - int saturation() const; - void setSaturation(int saturation); - - QAbstractVideoSurface *surface() const; - - GstElement *videoSink(); - - bool isReady() const { return winId() != 0; } - -signals: - void sinkChanged(); - void readyChanged(bool); - -private slots: - void surfaceFormatChanged(); - -private: - void setScaledDisplayRect(); - - QX11VideoSurface *m_surface; - GstElement *m_videoSink; - Qt::AspectRatioMode m_aspectRatioMode; - QRect m_displayRect; - bool m_fullScreen; -}; - -#endif //QT_NO_XVIDEO - -#endif diff --git a/src/plugins/gstreamer/qgstreamervideorenderer.cpp b/src/plugins/gstreamer/qgstreamervideorenderer.cpp deleted file mode 100644 index ead0bdc..0000000 --- a/src/plugins/gstreamer/qgstreamervideorenderer.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamervideorenderer.h" -#include <private/qvideosurfacegstsink_p.h> -#include <qabstractvideosurface.h> - -#include <QEvent> -#include <QtWidgets/QApplication> -#include <QDebug> - -#include <gst/gst.h> - -QGstreamerVideoRenderer::QGstreamerVideoRenderer(QObject *parent) - :QVideoRendererControl(parent),m_videoSink(0), m_surface(0) -{ -} - -QGstreamerVideoRenderer::~QGstreamerVideoRenderer() -{ - if (m_videoSink) - gst_object_unref(GST_OBJECT(m_videoSink)); -} - -GstElement *QGstreamerVideoRenderer::videoSink() -{ - if (!m_videoSink && m_surface) { - m_videoSink = QVideoSurfaceGstSink::createSink(m_surface); - gst_object_ref(GST_OBJECT(m_videoSink)); //Take ownership - gst_object_sink(GST_OBJECT(m_videoSink)); - } - - return reinterpret_cast<GstElement*>(m_videoSink); -} - - -QAbstractVideoSurface *QGstreamerVideoRenderer::surface() const -{ - return m_surface; -} - -void QGstreamerVideoRenderer::setSurface(QAbstractVideoSurface *surface) -{ - if (m_surface != surface) { - //qDebug() << Q_FUNC_INFO << surface; - if (m_videoSink) - gst_object_unref(GST_OBJECT(m_videoSink)); - - m_videoSink = 0; - - if (m_surface) { - disconnect(m_surface, SIGNAL(supportedFormatsChanged()), - this, SLOT(handleFormatChange())); - } - - m_surface = surface; - - if (surface && !m_surface) - emit readyChanged(true); - - if (!surface && m_surface) - emit readyChanged(false); - - if (m_surface) { - connect(m_surface, SIGNAL(supportedFormatsChanged()), - this, SLOT(handleFormatChange())); - } - - emit sinkChanged(); - } -} - -void QGstreamerVideoRenderer::handleFormatChange() -{ - //qDebug() << "Supported formats list has changed, reload video output"; - - if (m_videoSink) - gst_object_unref(GST_OBJECT(m_videoSink)); - - m_videoSink = 0; - emit sinkChanged(); -} diff --git a/src/plugins/gstreamer/qgstreamervideorenderer.h b/src/plugins/gstreamer/qgstreamervideorenderer.h deleted file mode 100644 index fbd76f6..0000000 --- a/src/plugins/gstreamer/qgstreamervideorenderer.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERVIDEORENDERER_H -#define QGSTREAMERVIDEORENDERER_H - -#include <qvideorenderercontrol.h> -#include <private/qvideosurfacegstsink_p.h> - -#include "qgstreamervideorendererinterface.h" - -QT_USE_NAMESPACE - -class QGstreamerVideoRenderer : public QVideoRendererControl, public QGstreamerVideoRendererInterface -{ - Q_OBJECT - Q_INTERFACES(QGstreamerVideoRendererInterface) -public: - QGstreamerVideoRenderer(QObject *parent = 0); - virtual ~QGstreamerVideoRenderer(); - - QAbstractVideoSurface *surface() const; - void setSurface(QAbstractVideoSurface *surface); - - GstElement *videoSink(); - - bool isReady() const { return m_surface != 0; } - -signals: - void sinkChanged(); - void readyChanged(bool); - -private slots: - void handleFormatChange(); - -private: - QVideoSurfaceGstSink *m_videoSink; - QAbstractVideoSurface *m_surface; -}; - -#endif // QGSTREAMERVIDEORENDRER_H diff --git a/src/plugins/gstreamer/qgstreamervideorendererinterface.cpp b/src/plugins/gstreamer/qgstreamervideorendererinterface.cpp deleted file mode 100644 index 20ff2ce..0000000 --- a/src/plugins/gstreamer/qgstreamervideorendererinterface.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamervideorendererinterface.h" - -QGstreamerVideoRendererInterface::~QGstreamerVideoRendererInterface() -{ -} diff --git a/src/plugins/gstreamer/qgstreamervideorendererinterface.h b/src/plugins/gstreamer/qgstreamervideorendererinterface.h deleted file mode 100644 index da5107e..0000000 --- a/src/plugins/gstreamer/qgstreamervideorendererinterface.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERVIDEOOUTPUTCONTROL_H -#define QGSTREAMERVIDEOOUTPUTCONTROL_H - -#include <gst/gst.h> - -#include <QtCore/qobject.h> - -class QGstreamerVideoRendererInterface -{ -public: - virtual ~QGstreamerVideoRendererInterface(); - virtual GstElement *videoSink() = 0; - - //stopRenderer() is called when the renderer element is stopped. - //it can be reimplemented when video renderer can't detect - //changes to NULL state but has to free video resources. - virtual void stopRenderer() {} - - //the video output is configured, usually after the first paint event - //(winId is known, - virtual bool isReady() const { return true; } - - //signals: - //void sinkChanged(); - //void readyChanged(bool); -}; - -#define QGstreamerVideoRendererInterface_iid "com.nokia.Qt.QGstreamerVideoRendererInterface/1.0" -QT_BEGIN_NAMESPACE -Q_DECLARE_INTERFACE(QGstreamerVideoRendererInterface, QGstreamerVideoRendererInterface_iid) -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/gstreamer/qgstreamervideowidget.cpp b/src/plugins/gstreamer/qgstreamervideowidget.cpp deleted file mode 100644 index a0fdab7..0000000 --- a/src/plugins/gstreamer/qgstreamervideowidget.cpp +++ /dev/null @@ -1,352 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamervideowidget.h" -#include <private/qgstutils_p.h> - -#include <QtCore/qcoreevent.h> -#include <QtCore/qdebug.h> -#include <QtWidgets/qapplication.h> -#include <QtGui/qpainter.h> - -#ifdef Q_WS_X11 -# include <X11/Xlib.h> -#endif -#include <gst/gst.h> -#include <gst/interfaces/xoverlay.h> -#include <gst/interfaces/propertyprobe.h> - -class QGstreamerVideoWidget : public QWidget -{ -public: - QGstreamerVideoWidget(QWidget *parent = 0) - :QWidget(parent) - { - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - QPalette palette; - palette.setColor(QPalette::Background, Qt::black); - setPalette(palette); - } - - virtual ~QGstreamerVideoWidget() {} - - QSize sizeHint() const - { - return m_nativeSize; - } - - void setNativeSize( const QSize &size) - { - if (size != m_nativeSize) { - m_nativeSize = size; - if (size.isEmpty()) - setMinimumSize(0,0); - else - setMinimumSize(160,120); - - updateGeometry(); - } - } - -protected: - void paintEvent(QPaintEvent *) - { - QPainter painter(this); - painter.fillRect(rect(), palette().background()); - } - - QSize m_nativeSize; -}; - -QGstreamerVideoWidgetControl::QGstreamerVideoWidgetControl(QObject *parent) - : QVideoWidgetControl(parent) - , m_videoSink(0) - , m_widget(0) - , m_fullScreen(false) -{ -} - -QGstreamerVideoWidgetControl::~QGstreamerVideoWidgetControl() -{ - if (m_videoSink) - gst_object_unref(GST_OBJECT(m_videoSink)); - - delete m_widget; -} - -void QGstreamerVideoWidgetControl::createVideoWidget() -{ - if (m_widget) - return; - - m_widget = new QGstreamerVideoWidget; - - m_widget->installEventFilter(this); - m_windowId = m_widget->winId(); - - m_videoSink = gst_element_factory_make ("xvimagesink", NULL); - if (m_videoSink) { - // Check if the xv sink is usable - if (gst_element_set_state(m_videoSink, GST_STATE_READY) != GST_STATE_CHANGE_SUCCESS) { - gst_object_unref(GST_OBJECT(m_videoSink)); - m_videoSink = 0; - } else { - gst_element_set_state(m_videoSink, GST_STATE_NULL); - - g_object_set(G_OBJECT(m_videoSink), "force-aspect-ratio", 1, (const char*)NULL); - } - } - - if (!m_videoSink) - m_videoSink = gst_element_factory_make ("ximagesink", NULL); - - gst_object_ref (GST_OBJECT (m_videoSink)); //Take ownership - gst_object_sink (GST_OBJECT (m_videoSink)); - - -} - -GstElement *QGstreamerVideoWidgetControl::videoSink() -{ - createVideoWidget(); - return m_videoSink; -} - -bool QGstreamerVideoWidgetControl::eventFilter(QObject *object, QEvent *e) -{ - if (m_widget && object == m_widget) { - if (e->type() == QEvent::ParentChange || e->type() == QEvent::Show) { - WId newWId = m_widget->winId(); - if (newWId != m_windowId) { - m_windowId = newWId; - // Even if we have created a winId at this point, other X applications - // need to be aware of it. - QApplication::syncX(); - setOverlay(); - } - } - - if (e->type() == QEvent::Show) { - // Setting these values ensures smooth resizing since it - // will prevent the system from clearing the background - m_widget->setAttribute(Qt::WA_NoSystemBackground, true); - m_widget->setAttribute(Qt::WA_PaintOnScreen, true); - } else if (e->type() == QEvent::Resize) { - // This is a workaround for missing background repaints - // when reducing window size - windowExposed(); - } - } - - return false; -} - -bool QGstreamerVideoWidgetControl::processSyncMessage(const QGstreamerMessage &message) -{ - GstMessage* gm = message.rawMessage(); - - if (gm && (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ELEMENT) && - gst_structure_has_name(gm->structure, "prepare-xwindow-id")) { - - setOverlay(); - QMetaObject::invokeMethod(this, "updateNativeVideoSize", Qt::QueuedConnection); - return true; - } - - return false; -} - -bool QGstreamerVideoWidgetControl::processBusMessage(const QGstreamerMessage &message) -{ - GstMessage* gm = message.rawMessage(); - - if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_STATE_CHANGED && - GST_MESSAGE_SRC(gm) == GST_OBJECT_CAST(m_videoSink)) { - GstState oldState; - GstState newState; - gst_message_parse_state_changed(gm, &oldState, &newState, 0); - - if (oldState == GST_STATE_READY && newState == GST_STATE_PAUSED) - updateNativeVideoSize(); - } - - return false; -} - -void QGstreamerVideoWidgetControl::setOverlay() -{ - if (m_videoSink && GST_IS_X_OVERLAY(m_videoSink)) { - gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(m_videoSink), m_windowId); - } -} - -void QGstreamerVideoWidgetControl::updateNativeVideoSize() -{ - if (m_videoSink) { - //find video native size to update video widget size hint - GstPad *pad = gst_element_get_static_pad(m_videoSink,"sink"); - GstCaps *caps = gst_pad_get_negotiated_caps(pad); - - if (caps) { - m_widget->setNativeSize(QGstUtils::capsCorrectedResolution(caps)); - gst_caps_unref(caps); - } - } else { - if (m_widget) - m_widget->setNativeSize(QSize()); - } -} - - -void QGstreamerVideoWidgetControl::windowExposed() -{ - if (m_videoSink && GST_IS_X_OVERLAY(m_videoSink)) - gst_x_overlay_expose(GST_X_OVERLAY(m_videoSink)); -} - -QWidget *QGstreamerVideoWidgetControl::videoWidget() -{ - createVideoWidget(); - return m_widget; -} - -Qt::AspectRatioMode QGstreamerVideoWidgetControl::aspectRatioMode() const -{ - return m_aspectRatioMode; -} - -void QGstreamerVideoWidgetControl::setAspectRatioMode(Qt::AspectRatioMode mode) -{ - if (m_videoSink) { - g_object_set(G_OBJECT(m_videoSink), - "force-aspect-ratio", - (mode == Qt::KeepAspectRatio), - (const char*)NULL); - } - - m_aspectRatioMode = mode; -} - -bool QGstreamerVideoWidgetControl::isFullScreen() const -{ - return m_fullScreen; -} - -void QGstreamerVideoWidgetControl::setFullScreen(bool fullScreen) -{ - emit fullScreenChanged(m_fullScreen = fullScreen); -} - -int QGstreamerVideoWidgetControl::brightness() const -{ - int brightness = 0; - - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "brightness")) - g_object_get(G_OBJECT(m_videoSink), "brightness", &brightness, NULL); - - return brightness / 10; -} - -void QGstreamerVideoWidgetControl::setBrightness(int brightness) -{ - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "brightness")) { - g_object_set(G_OBJECT(m_videoSink), "brightness", brightness * 10, NULL); - - emit brightnessChanged(brightness); - } -} - -int QGstreamerVideoWidgetControl::contrast() const -{ - int contrast = 0; - - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "contrast")) - g_object_get(G_OBJECT(m_videoSink), "contrast", &contrast, NULL); - - return contrast / 10; -} - -void QGstreamerVideoWidgetControl::setContrast(int contrast) -{ - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "contrast")) { - g_object_set(G_OBJECT(m_videoSink), "contrast", contrast * 10, NULL); - - emit contrastChanged(contrast); - } -} - -int QGstreamerVideoWidgetControl::hue() const -{ - int hue = 0; - - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "hue")) - g_object_get(G_OBJECT(m_videoSink), "hue", &hue, NULL); - - return hue / 10; -} - -void QGstreamerVideoWidgetControl::setHue(int hue) -{ - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "hue")) { - g_object_set(G_OBJECT(m_videoSink), "hue", hue * 10, NULL); - - emit hueChanged(hue); - } -} - -int QGstreamerVideoWidgetControl::saturation() const -{ - int saturation = 0; - - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "saturation")) - g_object_get(G_OBJECT(m_videoSink), "saturation", &saturation, NULL); - - return saturation / 10; -} - -void QGstreamerVideoWidgetControl::setSaturation(int saturation) -{ - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "saturation")) { - g_object_set(G_OBJECT(m_videoSink), "saturation", saturation * 10, NULL); - - emit saturationChanged(saturation); - } -} diff --git a/src/plugins/gstreamer/qgstreamervideowidget.h b/src/plugins/gstreamer/qgstreamervideowidget.h deleted file mode 100644 index 53069fa..0000000 --- a/src/plugins/gstreamer/qgstreamervideowidget.h +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERVIDEOWIDGET_H -#define QGSTREAMERVIDEOWIDGET_H - -#include <qvideowidgetcontrol.h> - -#include "qgstreamervideorendererinterface.h" -#include <private/qgstreamerbushelper_p.h> - -QT_USE_NAMESPACE - -class QGstreamerVideoWidget; - -class QGstreamerVideoWidgetControl - : public QVideoWidgetControl - , public QGstreamerVideoRendererInterface - , public QGstreamerSyncMessageFilter - , public QGstreamerBusMessageFilter -{ - Q_OBJECT - Q_INTERFACES(QGstreamerVideoRendererInterface QGstreamerSyncMessageFilter QGstreamerBusMessageFilter) -public: - QGstreamerVideoWidgetControl(QObject *parent = 0); - virtual ~QGstreamerVideoWidgetControl(); - - GstElement *videoSink(); - - QWidget *videoWidget(); - - Qt::AspectRatioMode aspectRatioMode() const; - void setAspectRatioMode(Qt::AspectRatioMode mode); - - bool isFullScreen() const; - void setFullScreen(bool fullScreen); - - int brightness() const; - void setBrightness(int brightness); - - int contrast() const; - void setContrast(int contrast); - - int hue() const; - void setHue(int hue); - - int saturation() const; - void setSaturation(int saturation); - - void setOverlay(); - - bool eventFilter(QObject *object, QEvent *event); - bool processSyncMessage(const QGstreamerMessage &message); - bool processBusMessage(const QGstreamerMessage &message); - -public slots: - void updateNativeVideoSize(); - -signals: - void sinkChanged(); - void readyChanged(bool); - -private: - void createVideoWidget(); - void windowExposed(); - - GstElement *m_videoSink; - QGstreamerVideoWidget *m_widget; - WId m_windowId; - Qt::AspectRatioMode m_aspectRatioMode; - bool m_fullScreen; -}; - -#endif // QGSTREAMERVIDEOWIDGET_H diff --git a/src/plugins/gstreamer/qgstreamervideowindow.cpp b/src/plugins/gstreamer/qgstreamervideowindow.cpp deleted file mode 100644 index 1c475bd..0000000 --- a/src/plugins/gstreamer/qgstreamervideowindow.cpp +++ /dev/null @@ -1,351 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgstreamervideowindow.h" -#include <private/qgstutils_p.h> - -#include <QtCore/qdebug.h> - -#include <gst/gst.h> -#include <gst/interfaces/xoverlay.h> -#include <gst/interfaces/propertyprobe.h> - - -#ifndef QT_NO_XVIDEO - -/* - QGstreamerVideoWindow is similar to QGstreamerVideoOverlay, - but uses xvimagesink like gstreamer element instead of QX11VideoSurface. - - This allows to use the accelerated elements if available on the target platform, - but requires at least 0.10.29 gstreamer version - with gst_x_overlay_set_render_rectangle to set display rect. -*/ - -QGstreamerVideoWindow::QGstreamerVideoWindow(QObject *parent, const char *elementName) - : QVideoWindowControl(parent) - , m_videoSink(0) - , m_windowId(0) - , m_aspectRatioMode(Qt::KeepAspectRatio) - , m_fullScreen(false) - , m_colorKey(QColor::Invalid) -{ - if (elementName) - m_videoSink = gst_element_factory_make(elementName, NULL); - else - m_videoSink = gst_element_factory_make("xvimagesink", NULL); - - if (m_videoSink) { - gst_object_ref(GST_OBJECT(m_videoSink)); //Take ownership - gst_object_sink(GST_OBJECT(m_videoSink)); - - GstPad *pad = gst_element_get_static_pad(m_videoSink,"sink"); - m_bufferProbeId = gst_pad_add_buffer_probe(pad, G_CALLBACK(padBufferProbe), this); - } -} - -QGstreamerVideoWindow::~QGstreamerVideoWindow() -{ - if (m_videoSink) - gst_object_unref(GST_OBJECT(m_videoSink)); -} - -WId QGstreamerVideoWindow::winId() const -{ - return m_windowId; -} - -void QGstreamerVideoWindow::setWinId(WId id) -{ - if (m_windowId == id) - return; - - qDebug() << Q_FUNC_INFO << id; - - WId oldId = m_windowId; - - m_windowId = id; - - if (m_videoSink && GST_IS_X_OVERLAY(m_videoSink)) { - gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(m_videoSink), m_windowId); - } - - if (!oldId) - emit readyChanged(true); - - if (!id) - emit readyChanged(false); -} - -bool QGstreamerVideoWindow::processSyncMessage(const QGstreamerMessage &message) -{ - GstMessage* gm = message.rawMessage(); - - if ((GST_MESSAGE_TYPE(gm) == GST_MESSAGE_ELEMENT) && - gst_structure_has_name(gm->structure, "prepare-xwindow-id") && - m_videoSink && GST_IS_X_OVERLAY(m_videoSink)) { - - gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(m_videoSink), m_windowId); - - GstPad *pad = gst_element_get_static_pad(m_videoSink,"sink"); - m_bufferProbeId = gst_pad_add_buffer_probe(pad, G_CALLBACK(padBufferProbe), this); - - return true; - } - - return false; -} - -QRect QGstreamerVideoWindow::displayRect() const -{ - return m_displayRect; -} - -void QGstreamerVideoWindow::setDisplayRect(const QRect &rect) -{ - m_displayRect = rect; - - if (m_videoSink && GST_IS_X_OVERLAY(m_videoSink)) { -#if GST_VERSION_MICRO >= 29 - if (m_displayRect.isEmpty()) - gst_x_overlay_set_render_rectangle(GST_X_OVERLAY(m_videoSink), -1, -1, -1, -1); - else - gst_x_overlay_set_render_rectangle(GST_X_OVERLAY(m_videoSink), - m_displayRect.x(), - m_displayRect.y(), - m_displayRect.width(), - m_displayRect.height()); - repaint(); -#endif - } -} - -Qt::AspectRatioMode QGstreamerVideoWindow::aspectRatioMode() const -{ - return m_aspectRatioMode; -} - -void QGstreamerVideoWindow::setAspectRatioMode(Qt::AspectRatioMode mode) -{ - m_aspectRatioMode = mode; - - if (m_videoSink) { - g_object_set(G_OBJECT(m_videoSink), - "force-aspect-ratio", - (m_aspectRatioMode == Qt::KeepAspectRatio), - (const char*)NULL); - } -} - -void QGstreamerVideoWindow::repaint() -{ - if (m_videoSink && GST_IS_X_OVERLAY(m_videoSink)) { - //don't call gst_x_overlay_expose if the sink is in null state - GstState state = GST_STATE_NULL; - GstStateChangeReturn res = gst_element_get_state(m_videoSink, &state, NULL, 1000000); - if (res != GST_STATE_CHANGE_FAILURE && state != GST_STATE_NULL) { - gst_x_overlay_expose(GST_X_OVERLAY(m_videoSink)); - } - } -} - -QColor QGstreamerVideoWindow::colorKey() const -{ - if (!m_colorKey.isValid()) { - gint colorkey = 0; - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "colorkey")) - g_object_get(G_OBJECT(m_videoSink), "colorkey", &colorkey, NULL); - - if (colorkey > 0) - m_colorKey.setRgb(colorkey); - } - - return m_colorKey; -} - -void QGstreamerVideoWindow::setColorKey(const QColor &color) -{ - m_colorKey = color; - - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "colorkey")) - g_object_set(G_OBJECT(m_videoSink), "colorkey", color.rgba(), NULL); -} - -bool QGstreamerVideoWindow::autopaintColorKey() const -{ - bool enabled = true; - - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "autopaint-colorkey")) - g_object_get(G_OBJECT(m_videoSink), "autopaint-colorkey", &enabled, NULL); - - return enabled; -} - -void QGstreamerVideoWindow::setAutopaintColorKey(bool enabled) -{ - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "autopaint-colorkey")) - g_object_set(G_OBJECT(m_videoSink), "autopaint-colorkey", enabled, NULL); -} - -int QGstreamerVideoWindow::brightness() const -{ - int brightness = 0; - - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "brightness")) - g_object_get(G_OBJECT(m_videoSink), "brightness", &brightness, NULL); - - return brightness / 10; -} - -void QGstreamerVideoWindow::setBrightness(int brightness) -{ - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "brightness")) { - g_object_set(G_OBJECT(m_videoSink), "brightness", brightness * 10, NULL); - - emit brightnessChanged(brightness); - } -} - -int QGstreamerVideoWindow::contrast() const -{ - int contrast = 0; - - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "contrast")) - g_object_get(G_OBJECT(m_videoSink), "contrast", &contrast, NULL); - - return contrast / 10; -} - -void QGstreamerVideoWindow::setContrast(int contrast) -{ - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "contrast")) { - g_object_set(G_OBJECT(m_videoSink), "contrast", contrast * 10, NULL); - - emit contrastChanged(contrast); - } -} - -int QGstreamerVideoWindow::hue() const -{ - int hue = 0; - - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "hue")) - g_object_get(G_OBJECT(m_videoSink), "hue", &hue, NULL); - - return hue / 10; -} - -void QGstreamerVideoWindow::setHue(int hue) -{ - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "hue")) { - g_object_set(G_OBJECT(m_videoSink), "hue", hue * 10, NULL); - - emit hueChanged(hue); - } -} - -int QGstreamerVideoWindow::saturation() const -{ - int saturation = 0; - - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "saturation")) - g_object_get(G_OBJECT(m_videoSink), "saturation", &saturation, NULL); - - return saturation / 10; -} - -void QGstreamerVideoWindow::setSaturation(int saturation) -{ - if (m_videoSink && g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSink), "saturation")) { - g_object_set(G_OBJECT(m_videoSink), "saturation", saturation * 10, NULL); - - emit saturationChanged(saturation); - } -} - -bool QGstreamerVideoWindow::isFullScreen() const -{ - return m_fullScreen; -} - -void QGstreamerVideoWindow::setFullScreen(bool fullScreen) -{ - emit fullScreenChanged(m_fullScreen = fullScreen); -} - -QSize QGstreamerVideoWindow::nativeSize() const -{ - return m_nativeSize; -} - -void QGstreamerVideoWindow::padBufferProbe(GstPad *pad, GstBuffer *buffer, gpointer user_data) -{ - QGstreamerVideoWindow *control = reinterpret_cast<QGstreamerVideoWindow*>(user_data); - QMetaObject::invokeMethod(control, "updateNativeVideoSize", Qt::QueuedConnection); - gst_pad_remove_buffer_probe(pad, control->m_bufferProbeId); -} - -void QGstreamerVideoWindow::updateNativeVideoSize() -{ - const QSize oldSize = m_nativeSize; - m_nativeSize = QSize(); - - if (m_videoSink) { - //find video native size to update video widget size hint - GstPad *pad = gst_element_get_static_pad(m_videoSink,"sink"); - GstCaps *caps = gst_pad_get_negotiated_caps(pad); - - if (caps) { - m_nativeSize = QGstUtils::capsCorrectedResolution(caps); - gst_caps_unref(caps); - } - } - - if (m_nativeSize != oldSize) - emit nativeSizeChanged(); -} - -GstElement *QGstreamerVideoWindow::videoSink() -{ - return m_videoSink; -} - -#endif //QT_NO_XVIDEO diff --git a/src/plugins/gstreamer/qgstreamervideowindow.h b/src/plugins/gstreamer/qgstreamervideowindow.h deleted file mode 100644 index 2182148..0000000 --- a/src/plugins/gstreamer/qgstreamervideowindow.h +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGSTREAMERVIDEOWINDOW_H -#define QGSTREAMERVIDEOWINDOW_H - -#include <qvideowindowcontrol.h> - -#include "qgstreamervideorendererinterface.h" -#include <private/qgstreamerbushelper_p.h> - -QT_BEGIN_NAMESPACE -class QAbstractVideoSurface; -QT_END_NAMESPACE -class QX11VideoSurface; - -#if defined(Q_WS_X11) && !defined(QT_NO_XVIDEO) - -QT_USE_NAMESPACE - -class QGstreamerVideoWindow : public QVideoWindowControl, - public QGstreamerVideoRendererInterface, - public QGstreamerSyncMessageFilter -{ - Q_OBJECT - Q_INTERFACES(QGstreamerVideoRendererInterface QGstreamerSyncMessageFilter) - Q_PROPERTY(QColor colorKey READ colorKey WRITE setColorKey) - Q_PROPERTY(bool autopaintColorKey READ autopaintColorKey WRITE setAutopaintColorKey) -public: - QGstreamerVideoWindow(QObject *parent = 0, const char *elementName = 0); - ~QGstreamerVideoWindow(); - - WId winId() const; - void setWinId(WId id); - - QRect displayRect() const; - void setDisplayRect(const QRect &rect); - - bool isFullScreen() const; - void setFullScreen(bool fullScreen); - - QSize nativeSize() const; - - Qt::AspectRatioMode aspectRatioMode() const; - void setAspectRatioMode(Qt::AspectRatioMode mode); - - QColor colorKey() const; - void setColorKey(const QColor &); - - bool autopaintColorKey() const; - void setAutopaintColorKey(bool); - - void repaint(); - - int brightness() const; - void setBrightness(int brightness); - - int contrast() const; - void setContrast(int contrast); - - int hue() const; - void setHue(int hue); - - int saturation() const; - void setSaturation(int saturation); - - QAbstractVideoSurface *surface() const; - - GstElement *videoSink(); - - bool processSyncMessage(const QGstreamerMessage &message); - bool isReady() const { return m_windowId != 0; } - -signals: - void sinkChanged(); - void readyChanged(bool); - -private slots: - void updateNativeVideoSize(); - -private: - static void padBufferProbe(GstPad *pad, GstBuffer *buffer, gpointer user_data); - - GstElement *m_videoSink; - WId m_windowId; - Qt::AspectRatioMode m_aspectRatioMode; - QRect m_displayRect; - bool m_fullScreen; - QSize m_nativeSize; - mutable QColor m_colorKey; - int m_bufferProbeId; -}; - -#endif //QT_NO_XVIDEO - -#endif diff --git a/src/plugins/gstreamer/qx11videosurface.cpp b/src/plugins/gstreamer/qx11videosurface.cpp deleted file mode 100644 index f12be3e..0000000 --- a/src/plugins/gstreamer/qx11videosurface.cpp +++ /dev/null @@ -1,529 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qvariant.h> -#include <QtCore/qdebug.h> -#include <QtWidgets/qx11info_x11.h> -#include <qvideosurfaceformat.h> - -#ifndef QT_NO_XVIDEO - -#include "qx11videosurface.h" - -Q_DECLARE_METATYPE(XvImage*); - -struct XvFormatRgb -{ - QVideoFrame::PixelFormat pixelFormat; - int bits_per_pixel; - int format; - int num_planes; - - int depth; - unsigned int red_mask; - unsigned int green_mask; - unsigned int blue_mask; - -}; - -bool operator ==(const XvImageFormatValues &format, const XvFormatRgb &rgb) -{ - return format.type == XvRGB - && format.bits_per_pixel == rgb.bits_per_pixel - && format.format == rgb.format - && format.num_planes == rgb.num_planes - && format.depth == rgb.depth - && format.red_mask == rgb.red_mask - && format.blue_mask == rgb.blue_mask; -} - -static const XvFormatRgb qt_xvRgbLookup[] = -{ - { QVideoFrame::Format_ARGB32, 32, XvPacked, 1, 32, 0x00FF0000, 0x0000FF00, 0x000000FF }, - { QVideoFrame::Format_RGB32 , 32, XvPacked, 1, 24, 0x00FF0000, 0x0000FF00, 0x000000FF }, - { QVideoFrame::Format_RGB24 , 24, XvPacked, 1, 24, 0x00FF0000, 0x0000FF00, 0x000000FF }, - { QVideoFrame::Format_RGB565, 16, XvPacked, 1, 16, 0x0000F800, 0x000007E0, 0x0000001F }, - { QVideoFrame::Format_BGRA32, 32, XvPacked, 1, 32, 0xFF000000, 0x00FF0000, 0x0000FF00 }, - { QVideoFrame::Format_BGR32 , 32, XvPacked, 1, 24, 0x00FF0000, 0x0000FF00, 0x000000FF }, - { QVideoFrame::Format_BGR24 , 24, XvPacked, 1, 24, 0x00FF0000, 0x0000FF00, 0x000000FF }, - { QVideoFrame::Format_BGR565, 16, XvPacked, 1, 16, 0x0000F800, 0x000007E0, 0x0000001F } -}; - -struct XvFormatYuv -{ - QVideoFrame::PixelFormat pixelFormat; - int bits_per_pixel; - int format; - int num_planes; - - unsigned int y_sample_bits; - unsigned int u_sample_bits; - unsigned int v_sample_bits; - unsigned int horz_y_period; - unsigned int horz_u_period; - unsigned int horz_v_period; - unsigned int vert_y_period; - unsigned int vert_u_period; - unsigned int vert_v_period; - char component_order[32]; -}; - -bool operator ==(const XvImageFormatValues &format, const XvFormatYuv &yuv) -{ - return format.type == XvYUV - && format.bits_per_pixel == yuv.bits_per_pixel - && format.format == yuv.format - && format.num_planes == yuv.num_planes - && format.y_sample_bits == yuv.y_sample_bits - && format.u_sample_bits == yuv.u_sample_bits - && format.v_sample_bits == yuv.v_sample_bits - && format.horz_y_period == yuv.horz_y_period - && format.horz_u_period == yuv.horz_u_period - && format.horz_v_period == yuv.horz_v_period - && format.horz_y_period == yuv.vert_y_period - && format.vert_u_period == yuv.vert_u_period - && format.vert_v_period == yuv.vert_v_period - && qstrncmp(format.component_order, yuv.component_order, 32) == 0; -} - -static const XvFormatYuv qt_xvYuvLookup[] = -{ - { QVideoFrame::Format_YUV444 , 24, XvPacked, 1, 8, 8, 8, 1, 1, 1, 1, 1, 1, "YUV" }, - { QVideoFrame::Format_YUV420P, 12, XvPlanar, 3, 8, 8, 8, 1, 2, 2, 1, 2, 2, "YUV" }, - { QVideoFrame::Format_YV12 , 12, XvPlanar, 3, 8, 8, 8, 1, 2, 2, 1, 2, 2, "YVU" }, - { QVideoFrame::Format_UYVY , 16, XvPacked, 1, 8, 8, 8, 1, 2, 2, 1, 1, 1, "UYVY" }, - { QVideoFrame::Format_YUYV , 16, XvPacked, 1, 8, 8, 8, 1, 2, 2, 1, 1, 1, "YUY2" }, - { QVideoFrame::Format_YUYV , 16, XvPacked, 1, 8, 8, 8, 1, 2, 2, 1, 1, 1, "YUYV" }, - { QVideoFrame::Format_NV12 , 12, XvPlanar, 2, 8, 8, 8, 1, 2, 2, 1, 2, 2, "YUV" }, - { QVideoFrame::Format_NV12 , 12, XvPlanar, 2, 8, 8, 8, 1, 2, 2, 1, 2, 2, "YVU" }, - { QVideoFrame::Format_Y8 , 8 , XvPlanar, 1, 8, 0, 0, 1, 0, 0, 1, 0, 0, "Y" } -}; - -QX11VideoSurface::QX11VideoSurface(QObject *parent) - : QAbstractVideoSurface(parent) - , m_winId(0) - , m_portId(0) - , m_gc(0) - , m_image(0) -{ -} - -QX11VideoSurface::~QX11VideoSurface() -{ - if (m_gc) - XFreeGC(QX11Info::display(), m_gc); - - if (m_portId != 0) - XvUngrabPort(QX11Info::display(), m_portId, 0); -} - -WId QX11VideoSurface::winId() const -{ - return m_winId; -} - -void QX11VideoSurface::setWinId(WId id) -{ - //qDebug() << "setWinID:" << id; - - if (id == m_winId) - return; - - if (m_image) - XFree(m_image); - - if (m_gc) { - XFreeGC(QX11Info::display(), m_gc); - m_gc = 0; - } - - if (m_portId != 0) - XvUngrabPort(QX11Info::display(), m_portId, 0); - - m_supportedPixelFormats.clear(); - m_formatIds.clear(); - - m_winId = id; - - if (m_winId && findPort()) { - querySupportedFormats(); - - m_gc = XCreateGC(QX11Info::display(), m_winId, 0, 0); - - if (m_image) { - m_image = 0; - - if (!start(surfaceFormat())) { - QAbstractVideoSurface::stop(); - qWarning() << "Failed to start video surface with format" << surfaceFormat(); - } - } - } else { - qWarning() << "Failed to find XVideo port"; - if (m_image) { - m_image = 0; - - QAbstractVideoSurface::stop(); - } - } - - emit supportedFormatsChanged(); -} - -QRect QX11VideoSurface::displayRect() const -{ - return m_displayRect; -} - -void QX11VideoSurface::setDisplayRect(const QRect &rect) -{ - m_displayRect = rect; -} - -QRect QX11VideoSurface::viewport() const -{ - return m_viewport; -} - -void QX11VideoSurface::setViewport(const QRect &rect) -{ - m_viewport = rect; -} - -int QX11VideoSurface::brightness() const -{ - return getAttribute("XV_BRIGHTNESS", m_brightnessRange.first, m_brightnessRange.second); -} - -void QX11VideoSurface::setBrightness(int brightness) -{ - setAttribute("XV_BRIGHTNESS", brightness, m_brightnessRange.first, m_brightnessRange.second); -} - -int QX11VideoSurface::contrast() const -{ - return getAttribute("XV_CONTRAST", m_contrastRange.first, m_contrastRange.second); -} - -void QX11VideoSurface::setContrast(int contrast) -{ - setAttribute("XV_CONTRAST", contrast, m_contrastRange.first, m_contrastRange.second); -} - -int QX11VideoSurface::hue() const -{ - return getAttribute("XV_HUE", m_hueRange.first, m_hueRange.second); -} - -void QX11VideoSurface::setHue(int hue) -{ - setAttribute("XV_HUE", hue, m_hueRange.first, m_hueRange.second); -} - -int QX11VideoSurface::saturation() const -{ - return getAttribute("XV_SATURATION", m_saturationRange.first, m_saturationRange.second); -} - -void QX11VideoSurface::setSaturation(int saturation) -{ - setAttribute("XV_SATURATION", saturation, m_saturationRange.first, m_saturationRange.second); -} - -int QX11VideoSurface::getAttribute(const char *attribute, int minimum, int maximum) const -{ - if (m_portId != 0) { - Display *display = QX11Info::display(); - - Atom atom = XInternAtom(display, attribute, True); - - int value = 0; - - XvGetPortAttribute(display, m_portId, atom, &value); - - return redistribute(value, minimum, maximum, -100, 100); - } else { - return 0; - } -} - -void QX11VideoSurface::setAttribute(const char *attribute, int value, int minimum, int maximum) -{ - if (m_portId != 0) { - Display *display = QX11Info::display(); - - Atom atom = XInternAtom(display, attribute, True); - - XvSetPortAttribute( - display, m_portId, atom, redistribute(value, -100, 100, minimum, maximum)); - } -} - -int QX11VideoSurface::redistribute( - int value, int fromLower, int fromUpper, int toLower, int toUpper) -{ - return fromUpper != fromLower - ? ((value - fromLower) * (toUpper - toLower) / (fromUpper - fromLower)) + toLower - : 0; -} - -QList<QVideoFrame::PixelFormat> QX11VideoSurface::supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType) const -{ - return handleType == QAbstractVideoBuffer::NoHandle || handleType == QAbstractVideoBuffer::XvShmImageHandle - ? m_supportedPixelFormats - : QList<QVideoFrame::PixelFormat>(); -} - -bool QX11VideoSurface::start(const QVideoSurfaceFormat &format) -{ - if (m_image) - XFree(m_image); - - int xvFormatId = 0; - for (int i = 0; i < m_supportedPixelFormats.count(); ++i) { - if (m_supportedPixelFormats.at(i) == format.pixelFormat()) { - xvFormatId = m_formatIds.at(i); - break; - } - } - - if (xvFormatId == 0) { - setError(UnsupportedFormatError); - } else { - XvImage *image = XvCreateImage( - QX11Info::display(), - m_portId, - xvFormatId, - 0, - format.frameWidth(), - format.frameHeight()); - - if (!image) { - setError(ResourceError); - } else { - m_viewport = format.viewport(); - m_image = image; - - QVideoSurfaceFormat newFormat = format; - newFormat.setProperty("portId", QVariant(quint64(m_portId))); - newFormat.setProperty("xvFormatId", xvFormatId); - newFormat.setProperty("dataSize", image->data_size); - - return QAbstractVideoSurface::start(newFormat); - } - } - - if (m_image) { - m_image = 0; - - QAbstractVideoSurface::stop(); - } - - return false; -} - -void QX11VideoSurface::stop() -{ - if (m_image) { - XFree(m_image); - m_image = 0; - - QAbstractVideoSurface::stop(); - } -} - -bool QX11VideoSurface::present(const QVideoFrame &frame) -{ - if (!m_image) { - setError(StoppedError); - return false; - } else if (m_image->width != frame.width() || m_image->height != frame.height()) { - setError(IncorrectFormatError); - return false; - } else { - QVideoFrame frameCopy(frame); - - if (!frameCopy.map(QAbstractVideoBuffer::ReadOnly)) { - setError(IncorrectFormatError); - return false; - } else { - bool presented = false; - - if (frame.handleType() != QAbstractVideoBuffer::XvShmImageHandle && - m_image->data_size > frame.mappedBytes()) { - qWarning("Insufficient frame buffer size"); - setError(IncorrectFormatError); - } else if (frame.handleType() != QAbstractVideoBuffer::XvShmImageHandle && - m_image->num_planes > 0 && - m_image->pitches[0] != frame.bytesPerLine()) { - qWarning("Incompatible frame pitches"); - setError(IncorrectFormatError); - } else { - if (frame.handleType() != QAbstractVideoBuffer::XvShmImageHandle) { - m_image->data = reinterpret_cast<char *>(frameCopy.bits()); - - //qDebug() << "copy frame"; - XvPutImage( - QX11Info::display(), - m_portId, - m_winId, - m_gc, - m_image, - m_viewport.x(), - m_viewport.y(), - m_viewport.width(), - m_viewport.height(), - m_displayRect.x(), - m_displayRect.y(), - m_displayRect.width(), - m_displayRect.height()); - - m_image->data = 0; - } else { - XvImage *img = frame.handle().value<XvImage*>(); - - //qDebug() << "render directly"; - if (img) - XvShmPutImage( - QX11Info::display(), - m_portId, - m_winId, - m_gc, - img, - m_viewport.x(), - m_viewport.y(), - m_viewport.width(), - m_viewport.height(), - m_displayRect.x(), - m_displayRect.y(), - m_displayRect.width(), - m_displayRect.height(), - false); - } - - presented = true; - } - - frameCopy.unmap(); - - return presented; - } - } -} - -bool QX11VideoSurface::findPort() -{ - unsigned int count = 0; - XvAdaptorInfo *adaptors = 0; - bool portFound = false; - - if (XvQueryAdaptors(QX11Info::display(), m_winId, &count, &adaptors) == Success) { - for (unsigned int i = 0; i < count && !portFound; ++i) { - if (adaptors[i].type & XvImageMask) { - m_portId = adaptors[i].base_id; - - for (unsigned int j = 0; j < adaptors[i].num_ports && !portFound; ++j, ++m_portId) - portFound = XvGrabPort(QX11Info::display(), m_portId, 0) == Success; - } - } - XvFreeAdaptorInfo(adaptors); - } - - return portFound; -} - -void QX11VideoSurface::querySupportedFormats() -{ - int count = 0; - if (XvImageFormatValues *imageFormats = XvListImageFormats( - QX11Info::display(), m_portId, &count)) { - const int rgbCount = sizeof(qt_xvRgbLookup) / sizeof(XvFormatRgb); - const int yuvCount = sizeof(qt_xvYuvLookup) / sizeof(XvFormatYuv); - - for (int i = 0; i < count; ++i) { - switch (imageFormats[i].type) { - case XvRGB: - for (int j = 0; j < rgbCount; ++j) { - if (imageFormats[i] == qt_xvRgbLookup[j]) { - m_supportedPixelFormats.append(qt_xvRgbLookup[j].pixelFormat); - m_formatIds.append(imageFormats[i].id); - break; - } - } - break; - case XvYUV: - for (int j = 0; j < yuvCount; ++j) { - if (imageFormats[i] == qt_xvYuvLookup[j]) { - m_supportedPixelFormats.append(qt_xvYuvLookup[j].pixelFormat); - m_formatIds.append(imageFormats[i].id); - break; - } - } - break; - } - } - XFree(imageFormats); - } - - m_brightnessRange = qMakePair(0, 0); - m_contrastRange = qMakePair(0, 0); - m_hueRange = qMakePair(0, 0); - m_saturationRange = qMakePair(0, 0); - - if (XvAttribute *attributes = XvQueryPortAttributes(QX11Info::display(), m_portId, &count)) { - for (int i = 0; i < count; ++i) { - if (qstrcmp(attributes[i].name, "XV_BRIGHTNESS") == 0) - m_brightnessRange = qMakePair(attributes[i].min_value, attributes[i].max_value); - else if (qstrcmp(attributes[i].name, "XV_CONTRAST") == 0) - m_contrastRange = qMakePair(attributes[i].min_value, attributes[i].max_value); - else if (qstrcmp(attributes[i].name, "XV_HUE") == 0) - m_hueRange = qMakePair(attributes[i].min_value, attributes[i].max_value); - else if (qstrcmp(attributes[i].name, "XV_SATURATION") == 0) - m_saturationRange = qMakePair(attributes[i].min_value, attributes[i].max_value); - } - - XFree(attributes); - } -} - -#endif //QT_NO_XVIDEO - diff --git a/src/plugins/gstreamer/qx11videosurface.h b/src/plugins/gstreamer/qx11videosurface.h deleted file mode 100644 index ecc84e3..0000000 --- a/src/plugins/gstreamer/qx11videosurface.h +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QX11VIDEOSURFACE_H -#define QX11VIDEOSURFACE_H - -#include <QtWidgets/qwidget.h> -#include <qabstractvideosurface.h> - -#ifndef QT_NO_XVIDEO - -#include <X11/Xlib.h> -#include <X11/extensions/Xv.h> -#include <X11/extensions/Xvlib.h> - -QT_USE_NAMESPACE - -class QX11VideoSurface : public QAbstractVideoSurface -{ - Q_OBJECT -public: - QX11VideoSurface(QObject *parent = 0); - ~QX11VideoSurface(); - - WId winId() const; - void setWinId(WId id); - - QRect displayRect() const; - void setDisplayRect(const QRect &rect); - - QRect viewport() const; - void setViewport(const QRect &rect); - - int brightness() const; - void setBrightness(int brightness); - - int contrast() const; - void setContrast(int contrast); - - int hue() const; - void setHue(int hue); - - int saturation() const; - void setSaturation(int saturation); - - QList<QVideoFrame::PixelFormat> supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const; - - bool start(const QVideoSurfaceFormat &format); - void stop(); - - bool present(const QVideoFrame &frame); - -private: - WId m_winId; - XvPortID m_portId; - GC m_gc; - XvImage *m_image; - QList<QVideoFrame::PixelFormat> m_supportedPixelFormats; - QVector<int> m_formatIds; - QRect m_viewport; - QRect m_displayRect; - QPair<int, int> m_brightnessRange; - QPair<int, int> m_contrastRange; - QPair<int, int> m_hueRange; - QPair<int, int> m_saturationRange; - - bool findPort(); - void querySupportedFormats(); - - int getAttribute(const char *attribute, int minimum, int maximum) const; - void setAttribute(const char *attribute, int value, int minimum, int maximum); - - static int redistribute(int value, int fromLower, int fromUpper, int toLower, int toUpper); -}; - -#endif //QT_NO_XVIDEO - -#endif diff --git a/src/plugins/m3u/m3u.pro b/src/plugins/m3u/m3u.pro deleted file mode 100644 index cd73b14..0000000 --- a/src/plugins/m3u/m3u.pro +++ /dev/null @@ -1,16 +0,0 @@ -load(qt_module) - -TARGET = qtmultimedia_m3u -QT += multimedia-private -PLUGIN_TYPE=playlistformats - -load(qt_plugin) -DESTDIR = $$QT.multimedia.plugins/$${PLUGIN_TYPE} - - -HEADERS += qm3uhandler.h -SOURCES += main.cpp \ - qm3uhandler.cpp - -target.path += $$[QT_INSTALL_PLUGINS]/$${PLUGIN_TYPE} -INSTALLS += target diff --git a/src/plugins/m3u/main.cpp b/src/plugins/m3u/main.cpp deleted file mode 100644 index f322001..0000000 --- a/src/plugins/m3u/main.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qm3uhandler.h" -#include <qstringlist.h> - - -Q_EXPORT_STATIC_PLUGIN(QM3uPlaylistPlugin) -Q_EXPORT_PLUGIN2(qtmultimedia_m3u, QM3uPlaylistPlugin) diff --git a/src/plugins/m3u/qm3uhandler.cpp b/src/plugins/m3u/qm3uhandler.cpp deleted file mode 100644 index f8308cf..0000000 --- a/src/plugins/m3u/qm3uhandler.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qm3uhandler.h" -#include <qmediaresource.h> -#include <QtCore/qiodevice.h> -#include <QtCore/qfileinfo.h> -#include <QtCore/qtextstream.h> -#include <QFile> -#include <QUrl> - - -class QM3uPlaylistReader : public QMediaPlaylistReader -{ -public: - QM3uPlaylistReader(QIODevice *device) - :m_ownDevice(false), m_device(device), m_textStream(new QTextStream(m_device)) - { - readItem(); - } - - QM3uPlaylistReader(const QUrl& location) - :m_location(location), m_ownDevice(true) - { - QFile *f = new QFile(location.toLocalFile()); - if (f->open(QIODevice::ReadOnly | QIODevice::Text)) { - m_device = f; - m_textStream = new QTextStream(m_device); - readItem(); - } else { - delete f; - m_device = 0; - m_textStream = 0; - } - } - - virtual ~QM3uPlaylistReader() - { - if (m_ownDevice) { - delete m_device; - } - delete m_textStream; - } - - virtual bool atEnd() const - { - //we can't just use m_textStream->atEnd(), - //for files with empty lines/comments at end - return nextResource.isNull(); - } - - virtual QMediaContent readItem() - { - QMediaContent item; - if (!nextResource.isNull()) - item = QMediaContent(nextResource); - - nextResource = QMediaContent(); - - while (m_textStream && !m_textStream->atEnd()) { - QString line = m_textStream->readLine().trimmed(); - if (line.isEmpty() || line[0] == '#' || line.size() > 4096) - continue; - - QUrl fileUrl = QUrl::fromLocalFile(line); - QUrl url(line); - - //m3u may contain url encoded entries or absolute/relative file names - //prefer existing file if any - QList<QUrl> candidates; - if (!m_location.isEmpty()) { - candidates << m_location.resolved(fileUrl); - candidates << m_location.resolved(url); - } - candidates << fileUrl; - candidates << url; - - foreach (const QUrl &candidate, candidates) { - if (QFile::exists(candidate.toLocalFile())) { - nextResource = candidate; - break; - } - } - - if (nextResource.isNull()) { - //assume the relative urls are file names, not encoded urls if m3u is local file - if (!m_location.isEmpty() && url.isRelative()) { - if (m_location.scheme() == QLatin1String("file")) - nextResource = m_location.resolved(fileUrl); - else - nextResource = m_location.resolved(url); - } else { - nextResource = QMediaContent(QUrl::fromUserInput(line)); - } - } - - break; - } - - return item; - } - - virtual void close() - { - } - -private: - QUrl m_location; - bool m_ownDevice; - QIODevice *m_device; - QTextStream *m_textStream; - QMediaContent nextResource; -}; - -class QM3uPlaylistWriter : public QMediaPlaylistWriter -{ -public: - QM3uPlaylistWriter(QIODevice *device) - :m_device(device), m_textStream(new QTextStream(m_device)) - { - } - - virtual ~QM3uPlaylistWriter() - { - delete m_textStream; - } - - virtual bool writeItem(const QMediaContent& item) - { - *m_textStream << item.canonicalUrl().toString() << endl; - return true; - } - - virtual void close() - { - } - -private: - QIODevice *m_device; - QTextStream *m_textStream; -}; - - -QM3uPlaylistPlugin::QM3uPlaylistPlugin(QObject *parent) - :QMediaPlaylistIOPlugin(parent) -{ -} - -QM3uPlaylistPlugin::~QM3uPlaylistPlugin() -{ -} - -bool QM3uPlaylistPlugin::canRead(QIODevice *device, const QByteArray &format) const -{ - return device->isReadable() && (format == "m3u" || format.isEmpty()); -} - -bool QM3uPlaylistPlugin::canRead(const QUrl& location, const QByteArray &format) const -{ - if (!QFileInfo(location.toLocalFile()).isReadable()) - return false; - - if (format == "m3u") - return true; - - if (!format.isEmpty()) - return false; - else - return location.toLocalFile().toLower().endsWith(QLatin1String("m3u")); -} - -bool QM3uPlaylistPlugin::canWrite(QIODevice *device, const QByteArray &format) const -{ - return device->isOpen() && device->isWritable() && format == "m3u"; -} - -QStringList QM3uPlaylistPlugin::keys() const -{ - return QStringList() << QLatin1String("m3u"); -} - -QMediaPlaylistReader *QM3uPlaylistPlugin::createReader(QIODevice *device, const QByteArray &format) -{ - Q_UNUSED(format); - return new QM3uPlaylistReader(device); -} - -QMediaPlaylistReader *QM3uPlaylistPlugin::createReader(const QUrl& location, const QByteArray &format) -{ - Q_UNUSED(format); - return new QM3uPlaylistReader(location); -} - -QMediaPlaylistWriter *QM3uPlaylistPlugin::createWriter(QIODevice *device, const QByteArray &format) -{ - Q_UNUSED(format); - return new QM3uPlaylistWriter(device); -} - diff --git a/src/plugins/m3u/qm3uhandler.h b/src/plugins/m3u/qm3uhandler.h deleted file mode 100644 index 5e9f0dd..0000000 --- a/src/plugins/m3u/qm3uhandler.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QM3UHANDLER_H -#define QM3UHANDLER_H - -#include "qmediaplaylistioplugin.h" -#include <QObject> - -QT_USE_NAMESPACE - -class QM3uPlaylistPlugin : public QMediaPlaylistIOPlugin -{ -Q_OBJECT -public: - explicit QM3uPlaylistPlugin(QObject *parent = 0); - virtual ~QM3uPlaylistPlugin(); - - virtual bool canRead(QIODevice *device, const QByteArray &format = QByteArray() ) const; - virtual bool canRead(const QUrl& location, const QByteArray &format = QByteArray()) const; - - virtual bool canWrite(QIODevice *device, const QByteArray &format) const; - - virtual QStringList keys() const; - - virtual QMediaPlaylistReader *createReader(QIODevice *device, const QByteArray &format = QByteArray()); - virtual QMediaPlaylistReader *createReader(const QUrl& location, const QByteArray &format = QByteArray()); - - virtual QMediaPlaylistWriter *createWriter(QIODevice *device, const QByteArray &format); -}; - -#endif // QM3UHANDLER_H diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro deleted file mode 100644 index 8f12a13..0000000 --- a/src/plugins/plugins.pro +++ /dev/null @@ -1,41 +0,0 @@ -###################################################################### -# -# QtMultimedia -# -###################################################################### - -TEMPLATE = subdirs - -SUBDIRS += m3u - -win32 { - SUBDIRS += audiocapture -} - -win32 { - contains(config_test_directshow, yes): SUBDIRS += directshow - contains(config_test_wmf, yes) : SUBDIRS += wmf -} - -simulator: SUBDIRS += simulator - -unix:!mac { - contains(config_test_gstreamer, yes) { - SUBDIRS += gstreamer - } else { - SUBDIRS += audiocapture - } - - # v4l is turned off because it is not supported in Qt 5 - # !maemo*:SUBDIRS += v4l - - contains(config_test_pulseaudio, yes) { - SUBDIRS += pulseaudio - } -} - -mac:!simulator { - SUBDIRS += audiocapture - SUBDIRS += qt7 -} - diff --git a/src/plugins/pulseaudio/pulseaudio.pro b/src/plugins/pulseaudio/pulseaudio.pro deleted file mode 100644 index 9b786b4..0000000 --- a/src/plugins/pulseaudio/pulseaudio.pro +++ /dev/null @@ -1,29 +0,0 @@ -load(qt_module) - -TARGET = qtmedia_pulse -QT += multimedia-private -PLUGIN_TYPE = audio - -load(qt_plugin) -DESTDIR = $$QT.multimedia.plugins/$${PLUGIN_TYPE} - -CONFIG += link_pkgconfig -PKGCONFIG += libpulse - -# Input -HEADERS += qpulseaudioplugin.h \ - qaudiodeviceinfo_pulse.h \ - qaudiooutput_pulse.h \ - qaudioinput_pulse.h \ - qpulseaudioengine.h \ - qpulsehelpers.h - -SOURCES += qpulseaudioplugin.cpp \ - qaudiodeviceinfo_pulse.cpp \ - qaudiooutput_pulse.cpp \ - qaudioinput_pulse.cpp \ - qpulseaudioengine.cpp \ - qpulsehelpers.cpp - -target.path += $$[QT_INSTALL_PLUGINS]/$${PLUGIN_TYPE} -INSTALLS += target diff --git a/src/plugins/pulseaudio/qaudiodeviceinfo_pulse.cpp b/src/plugins/pulseaudio/qaudiodeviceinfo_pulse.cpp deleted file mode 100644 index 129bbde..0000000 --- a/src/plugins/pulseaudio/qaudiodeviceinfo_pulse.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qaudiodeviceinfo_pulse.h" -#include "qpulseaudioengine.h" -#include "qpulsehelpers.h" - -QT_BEGIN_NAMESPACE - -QPulseAudioDeviceInfo::QPulseAudioDeviceInfo(const QByteArray &device, QAudio::Mode mode) - : m_device(device) - , m_mode(mode) -{ -} - -bool QPulseAudioDeviceInfo::isFormatSupported(const QAudioFormat &format) const -{ - pa_sample_spec spec = QPulseAudioInternal::audioFormatToSampleSpec(format); - if (!pa_sample_spec_valid(&spec)) - return false; - - return true; -} - -QAudioFormat QPulseAudioDeviceInfo::preferredFormat() const -{ - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - QAudioFormat format = pulseEngine->m_preferredFormats.value(m_device); - return format; -} - -QString QPulseAudioDeviceInfo::deviceName() const -{ - return m_device; -} - -QStringList QPulseAudioDeviceInfo::supportedCodecs() -{ - return QStringList() << "audio/pcm"; -} - -QList<int> QPulseAudioDeviceInfo::supportedSampleRates() -{ - return QList<int>() << 8000 << 11025 << 22050 << 44100 << 48000; -} - -QList<int> QPulseAudioDeviceInfo::supportedChannelCounts() -{ - return QList<int>() << 1 << 2 << 4 << 6 << 8; -} - -QList<int> QPulseAudioDeviceInfo::supportedSampleSizes() -{ - return QList<int>() << 8 << 16 << 24 << 32; -} - -QList<QAudioFormat::Endian> QPulseAudioDeviceInfo::supportedByteOrders() -{ - return QList<QAudioFormat::Endian>() << QAudioFormat::BigEndian << QAudioFormat::LittleEndian; -} - -QList<QAudioFormat::SampleType> QPulseAudioDeviceInfo::supportedSampleTypes() -{ - return QList<QAudioFormat::SampleType>() << QAudioFormat::SignedInt << QAudioFormat::UnSignedInt << QAudioFormat::Float; -} - -QT_END_NAMESPACE diff --git a/src/plugins/pulseaudio/qaudiodeviceinfo_pulse.h b/src/plugins/pulseaudio/qaudiodeviceinfo_pulse.h deleted file mode 100644 index 4e3f310..0000000 --- a/src/plugins/pulseaudio/qaudiodeviceinfo_pulse.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QAUDIODEVICEINFOPULSE_H -#define QAUDIODEVICEINFOPULSE_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtCore/qbytearray.h> -#include <QtCore/qstringlist.h> -#include <QtCore/qlist.h> - -#include "qaudio.h" -#include "qaudiodeviceinfo.h" -#include "qaudiosystem.h" - -QT_BEGIN_NAMESPACE - -class QPulseAudioDeviceInfo : public QAbstractAudioDeviceInfo -{ - Q_OBJECT - -public: - QPulseAudioDeviceInfo(const QByteArray &device, QAudio::Mode mode); - ~QPulseAudioDeviceInfo() {} - - QAudioFormat preferredFormat() const; - bool isFormatSupported(const QAudioFormat &format) const; - QString deviceName() const; - QStringList supportedCodecs(); - QList<int> supportedSampleRates(); - QList<int> supportedChannelCounts(); - QList<int> supportedSampleSizes(); - QList<QAudioFormat::Endian> supportedByteOrders(); - QList<QAudioFormat::SampleType> supportedSampleTypes(); - -private: - QByteArray m_device; - QAudio::Mode m_mode; -}; - -QT_END_NAMESPACE - -#endif - diff --git a/src/plugins/pulseaudio/qaudioinput_pulse.cpp b/src/plugins/pulseaudio/qaudioinput_pulse.cpp deleted file mode 100644 index d2ee316..0000000 --- a/src/plugins/pulseaudio/qaudioinput_pulse.cpp +++ /dev/null @@ -1,600 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qcoreapplication.h> -#include <QtCore/qdebug.h> - -#include "qaudioinput_pulse.h" -#include "qaudiodeviceinfo_pulse.h" -#include "qpulseaudioengine.h" -#include "qpulsehelpers.h" - -QT_BEGIN_NAMESPACE - -const int PeriodTimeMs = 50; - -static void inputStreamReadCallback(pa_stream *stream, size_t length, void *userdata) -{ - Q_UNUSED(userdata); - Q_UNUSED(length); - Q_UNUSED(stream); - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); -} - -static void inputStreamStateCallback(pa_stream *stream, void *userdata) -{ - Q_UNUSED(userdata); - pa_stream_state_t state = pa_stream_get_state(stream); -#ifdef DEBUG_PULSE - qDebug() << "Stream state: " << QPulseAudioInternal::stateToQString(state); -#endif - switch (state) { - case PA_STREAM_CREATING: - break; - case PA_STREAM_READY: { -#ifdef DEBUG_PULSE - QPulseAudioInput *audioInput = static_cast<QPulseAudioInput*>(userdata); - const pa_buffer_attr *buffer_attr = pa_stream_get_buffer_attr(stream); - qDebug() << "*** maxlength: " << buffer_attr->maxlength; - qDebug() << "*** prebuf: " << buffer_attr->prebuf; - qDebug() << "*** fragsize: " << buffer_attr->fragsize; - qDebug() << "*** minreq: " << buffer_attr->minreq; - qDebug() << "*** tlength: " << buffer_attr->tlength; - - pa_sample_spec spec = QPulseAudioInternal::audioFormatToSampleSpec(audioInput->format()); - qDebug() << "*** bytes_to_usec: " << pa_bytes_to_usec(buffer_attr->fragsize, &spec); -#endif - } - break; - case PA_STREAM_TERMINATED: - break; - case PA_STREAM_FAILED: - default: - qWarning() << QString("Stream error: %1").arg(pa_strerror(pa_context_errno(pa_stream_get_context(stream)))); - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); - break; - } -} - -static void inputStreamUnderflowCallback(pa_stream *stream, void *userdata) -{ - Q_UNUSED(userdata) - Q_UNUSED(stream) - qWarning() << "Got a buffer underflow!"; -} - -static void inputStreamOverflowCallback(pa_stream *stream, void *userdata) -{ - Q_UNUSED(stream) - Q_UNUSED(userdata) - qWarning() << "Got a buffer overflow!"; -} - -static void inputStreamSuccessCallback(pa_stream *stream, int success, void *userdata) -{ - Q_UNUSED(stream); - Q_UNUSED(userdata); - Q_UNUSED(success); - - //if (!success) - //TODO: Is cork success? i->operation_success = success; - - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); -} - -QPulseAudioInput::QPulseAudioInput(const QByteArray &device) - : m_totalTimeValue(0) - , m_audioSource(0) - , m_errorState(QAudio::NoError) - , m_deviceState(QAudio::StoppedState) - , m_pullMode(true) - , m_opened(false) - , m_bytesAvailable(0) - , m_bufferSize(0) - , m_periodSize(0) - , m_intervalTime(1000) - , m_stream(0) - , m_device(device) -{ - m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), SLOT(userFeed())); -} - -QPulseAudioInput::~QPulseAudioInput() -{ - close(); - disconnect(m_timer, SIGNAL(timeout())); - QCoreApplication::processEvents(); - delete m_timer; -} - -QAudio::Error QPulseAudioInput::error() const -{ - return m_errorState; -} - -QAudio::State QPulseAudioInput::state() const -{ - return m_deviceState; -} - -void QPulseAudioInput::setFormat(const QAudioFormat &format) -{ - if (m_deviceState == QAudio::StoppedState) - m_format = format; -} - -QAudioFormat QPulseAudioInput::format() const -{ - return m_format; -} - -void QPulseAudioInput::start(QIODevice *device) -{ - if (m_deviceState != QAudio::StoppedState) - close(); - - if (!m_pullMode && m_audioSource) - delete m_audioSource; - - m_pullMode = true; - m_audioSource = device; - - m_deviceState = QAudio::ActiveState; - - if (!open()) - return; - - emit stateChanged(m_deviceState); -} - -QIODevice *QPulseAudioInput::start() -{ - if (m_deviceState != QAudio::StoppedState) - close(); - - if (!m_pullMode && m_audioSource) - delete m_audioSource; - - m_pullMode = false; - m_audioSource = new InputPrivate(this); - m_audioSource->open(QIODevice::ReadOnly | QIODevice::Unbuffered); - - m_deviceState = QAudio::IdleState; - - if (!open()) - return 0; - - emit stateChanged(m_deviceState); - - return m_audioSource; -} - -void QPulseAudioInput::stop() -{ - if (m_deviceState == QAudio::StoppedState) - return; - - m_errorState = QAudio::NoError; - m_deviceState = QAudio::StoppedState; - - close(); - emit stateChanged(m_deviceState); -} - -bool QPulseAudioInput::open() -{ - if (m_opened) - return false; - -#ifdef DEBUG_PULSE -// QTime now(QTime::currentTime()); -// qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()"; -#endif - m_clockStamp.restart(); - m_timeStamp.restart(); - m_elapsedTimeOffset = 0; - - if (m_streamName.isNull()) - m_streamName = QString(QLatin1String("QtmPulseStream-%1-%2")).arg(::getpid()).arg(quintptr(this)).toUtf8(); - - pa_sample_spec spec = QPulseAudioInternal::audioFormatToSampleSpec(m_format); - - if (!pa_sample_spec_valid(&spec)) { - m_errorState = QAudio::OpenError; - m_deviceState = QAudio::StoppedState; - emit stateChanged(m_deviceState); - return false; - } - -#ifdef DEBUG_PULSE - qDebug() << "Format: " << QPulseAudioInternal::sampleFormatToQString(spec.format); - qDebug() << "Rate: " << spec.rate; - qDebug() << "Channels: " << spec.channels; - qDebug() << "Frame size: " << pa_frame_size(&spec); -#endif - - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - pa_threaded_mainloop_lock(pulseEngine->mainloop()); - pa_channel_map channel_map; - - pa_channel_map_init_extend(&channel_map, spec.channels, PA_CHANNEL_MAP_DEFAULT); - - if (!pa_channel_map_compatible(&channel_map, &spec)) { - qWarning() << "Channel map doesn't match sample specification!"; - } - - m_stream = pa_stream_new(pulseEngine->context(), m_streamName.constData(), &spec, &channel_map); - - pa_stream_set_state_callback(m_stream, inputStreamStateCallback, this); - pa_stream_set_read_callback(m_stream, inputStreamReadCallback, this); - - pa_stream_set_underflow_callback(m_stream, inputStreamUnderflowCallback, this); - pa_stream_set_overflow_callback(m_stream, inputStreamOverflowCallback, this); - - m_periodSize = pa_usec_to_bytes(PeriodTimeMs*1000, &spec); - - int flags = 0; - pa_buffer_attr buffer_attr; - buffer_attr.maxlength = (uint32_t) -1; - buffer_attr.prebuf = (uint32_t) -1; - buffer_attr.tlength = (uint32_t) -1; - buffer_attr.minreq = (uint32_t) -1; - flags |= PA_STREAM_ADJUST_LATENCY; - - if (m_bufferSize > 0) - buffer_attr.fragsize = (uint32_t) m_bufferSize; - else - buffer_attr.fragsize = (uint32_t) m_periodSize; - - if (pa_stream_connect_record(m_stream, m_device.data(), &buffer_attr, (pa_stream_flags_t)flags) < 0) { - qWarning() << "pa_stream_connect_record() failed!"; - m_errorState = QAudio::FatalError; - return false; - } - - while (pa_stream_get_state(m_stream) != PA_STREAM_READY) { - pa_threaded_mainloop_wait(pulseEngine->mainloop()); - } - pa_threaded_mainloop_unlock(pulseEngine->mainloop()); - - m_opened = true; - m_periodSize = pa_usec_to_bytes(PeriodTimeMs*1000, &spec); - m_timer->start(PeriodTimeMs); - m_errorState = QAudio::NoError; - - m_totalTimeValue = 0; - - return true; -} - -void QPulseAudioInput::close() -{ - m_timer->stop(); - - if (m_stream) { - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - pa_threaded_mainloop_lock(pulseEngine->mainloop()); - - pa_stream_set_read_callback(m_stream, 0, 0); - - pa_stream_disconnect(m_stream); - pa_stream_unref(m_stream); - m_stream = 0; - - pa_threaded_mainloop_unlock(pulseEngine->mainloop()); - } - - if (!m_pullMode && m_audioSource) { - delete m_audioSource; - m_audioSource = 0; - } - m_opened = false; -} - -int QPulseAudioInput::checkBytesReady() -{ - if (m_deviceState != QAudio::ActiveState && m_deviceState != QAudio::IdleState) { - m_bytesAvailable = 0; - } else { - m_bytesAvailable = pa_stream_readable_size(m_stream); - } - - return m_bytesAvailable; -} - -int QPulseAudioInput::bytesReady() const -{ - return qMax(m_bytesAvailable, 0); -} - -qint64 QPulseAudioInput::read(char *data, qint64 len) -{ - m_bytesAvailable = checkBytesReady(); - - if (m_deviceState != QAudio::ActiveState) { - m_errorState = QAudio::NoError; - m_deviceState = QAudio::ActiveState; - emit stateChanged(m_deviceState); - } - - int readBytes = 0; - - if (!m_pullMode && !m_tempBuffer.isEmpty()) { - readBytes = qMin(static_cast<int>(len), m_tempBuffer.size()); - memcpy(data, m_tempBuffer.constData(), readBytes); - m_totalTimeValue += readBytes; - - if (readBytes < m_tempBuffer.size()) { - m_tempBuffer.remove(0, readBytes); - return readBytes; - } - - m_tempBuffer.clear(); - } - - while (pa_stream_readable_size(m_stream) > 0) { - size_t readLength = 0; - -#ifdef DEBUG_PULSE - qDebug() << "QPulseAudioInput::read -- " << pa_stream_readable_size(m_stream) << " bytes available from pulse audio"; -#endif - - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - pa_threaded_mainloop_lock(pulseEngine->mainloop()); - const void *audioBuffer; - - // Second and third parameters (audioBuffer and length) to pa_stream_peek are output parameters, - // the audioBuffer pointer is set to point to the actual pulse audio data, - // and the length is set to the length of this data. - if (pa_stream_peek(m_stream, &audioBuffer, &readLength) < 0) { - qWarning() << QString("pa_stream_peek() failed: %1").arg(pa_strerror(pa_context_errno(pa_stream_get_context(m_stream)))); - pa_threaded_mainloop_unlock(pulseEngine->mainloop()); - return 0; - } - - qint64 actualLength = 0; - if (m_pullMode) { - actualLength = m_audioSource->write(static_cast<const char *>(audioBuffer), readLength); - - if (actualLength < readLength) { - pa_threaded_mainloop_unlock(pulseEngine->mainloop()); - - m_errorState = QAudio::UnderrunError; - m_deviceState = QAudio::IdleState; - emit stateChanged(m_deviceState); - - return actualLength; - } - } else { - actualLength = qMin(static_cast<int>(len - readBytes), static_cast<int>(readLength)); - memcpy(data + readBytes, audioBuffer, actualLength); - } - -#ifdef DEBUG_PULSE - qDebug() << "QPulseAudioInput::read -- wrote " << actualLength << " to client"; -#endif - - if (actualLength < readLength) { -#ifdef DEBUG_PULSE - qDebug() << "QPulseAudioInput::read -- appending " << readLength - actualLength << " bytes of data to temp buffer"; -#endif - m_tempBuffer.append(static_cast<const char *>(audioBuffer) + actualLength, readLength - actualLength); - QMetaObject::invokeMethod(this, "userFeed", Qt::QueuedConnection); - } - - m_totalTimeValue += actualLength; - readBytes += actualLength; - - pa_stream_drop(m_stream); - pa_threaded_mainloop_unlock(pulseEngine->mainloop()); - - if (!m_pullMode && readBytes >= len) - break; - } - -#ifdef DEBUG_PULSE - qDebug() << "QPulseAudioInput::read -- returning after reading " << readBytes << " bytes"; -#endif - - return readBytes; -} - -void QPulseAudioInput::resume() -{ - if (m_deviceState == QAudio::SuspendedState || m_deviceState == QAudio::IdleState) { - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - pa_operation *operation; - - pa_threaded_mainloop_lock(pulseEngine->mainloop()); - - operation = pa_stream_cork(m_stream, 0, inputStreamSuccessCallback, 0); - - while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) - pa_threaded_mainloop_wait(pulseEngine->mainloop()); - - pa_operation_unref(operation); - - pa_threaded_mainloop_unlock(pulseEngine->mainloop()); - - m_timer->start(PeriodTimeMs); - - m_deviceState = QAudio::ActiveState; - - emit stateChanged(m_deviceState); - } -} - -void QPulseAudioInput::setBufferSize(int value) -{ - m_bufferSize = value; -} - -int QPulseAudioInput::bufferSize() const -{ - return m_bufferSize; -} - -int QPulseAudioInput::periodSize() const -{ - return m_periodSize; -} - -void QPulseAudioInput::setNotifyInterval(int ms) -{ - m_intervalTime = qMax(0, ms); -} - -int QPulseAudioInput::notifyInterval() const -{ - return m_intervalTime; -} - -qint64 QPulseAudioInput::processedUSecs() const -{ - pa_sample_spec spec = QPulseAudioInternal::audioFormatToSampleSpec(m_format); - qint64 result = pa_bytes_to_usec(m_totalTimeValue, &spec); - - return result; -} - -void QPulseAudioInput::suspend() -{ - if (m_deviceState == QAudio::ActiveState) { - m_timer->stop(); - m_deviceState = QAudio::SuspendedState; - emit stateChanged(m_deviceState); - - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - pa_operation *operation; - - pa_threaded_mainloop_lock(pulseEngine->mainloop()); - - operation = pa_stream_cork(m_stream, 1, inputStreamSuccessCallback, 0); - - while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) - pa_threaded_mainloop_wait(pulseEngine->mainloop()); - - pa_operation_unref(operation); - - pa_threaded_mainloop_unlock(pulseEngine->mainloop()); - } -} - -void QPulseAudioInput::userFeed() -{ - if (m_deviceState == QAudio::StoppedState || m_deviceState == QAudio::SuspendedState) - return; -#ifdef DEBUG_PULSE -// QTime now(QTime::currentTime()); -// qDebug()<< now.second() << "s " << now.msec() << "ms :userFeed() IN"; -#endif - deviceReady(); -} - -bool QPulseAudioInput::deviceReady() -{ - if (m_pullMode) { - // reads some audio data and writes it to QIODevice - read(0,0); - } else { - // emits readyRead() so user will call read() on QIODevice to get some audio data - if (m_audioSource != 0) { - InputPrivate *a = qobject_cast<InputPrivate*>(m_audioSource); - a->trigger(); - } - } - m_bytesAvailable = checkBytesReady(); - - if (m_deviceState != QAudio::ActiveState) - return true; - - if (m_intervalTime && (m_timeStamp.elapsed() + m_elapsedTimeOffset) > m_intervalTime) { - emit notify(); - m_elapsedTimeOffset = m_timeStamp.elapsed() + m_elapsedTimeOffset - m_intervalTime; - m_timeStamp.restart(); - } - - return true; -} - -qint64 QPulseAudioInput::elapsedUSecs() const -{ - if (m_deviceState == QAudio::StoppedState) - return 0; - - return m_clockStamp.elapsed() * 1000; -} - -void QPulseAudioInput::reset() -{ - stop(); - m_bytesAvailable = 0; -} - -InputPrivate::InputPrivate(QPulseAudioInput *audio) -{ - m_audioDevice = qobject_cast<QPulseAudioInput*>(audio); -} - -qint64 InputPrivate::readData(char *data, qint64 len) -{ - return m_audioDevice->read(data, len); -} - -qint64 InputPrivate::writeData(const char *data, qint64 len) -{ - Q_UNUSED(data) - Q_UNUSED(len) - return 0; -} - -void InputPrivate::trigger() -{ - emit readyRead(); -} - -QT_END_NAMESPACE - -#include "moc_qaudioinput_pulse.cpp" diff --git a/src/plugins/pulseaudio/qaudioinput_pulse.h b/src/plugins/pulseaudio/qaudioinput_pulse.h deleted file mode 100644 index f03e419..0000000 --- a/src/plugins/pulseaudio/qaudioinput_pulse.h +++ /dev/null @@ -1,153 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#ifndef QAUDIOINPUTPULSE_H -#define QAUDIOINPUTPULSE_H - -#include <QtCore/qfile.h> -#include <QtCore/qtimer.h> -#include <QtCore/qstring.h> -#include <QtCore/qstringlist.h> -#include <QtCore/qdatetime.h> - -#include "qaudio.h" -#include "qaudiodeviceinfo.h" -#include "qaudiosystem.h" - -#include <pulse/pulseaudio.h> - -QT_BEGIN_NAMESPACE - -class InputPrivate; - -class QPulseAudioInput : public QAbstractAudioInput -{ - Q_OBJECT - -public: - QPulseAudioInput(const QByteArray &device); - ~QPulseAudioInput(); - - qint64 read(char *data, qint64 len); - - void start(QIODevice *device); - QIODevice *start(); - void stop(); - void reset(); - void suspend(); - void resume(); - int bytesReady() const; - int periodSize() const; - void setBufferSize(int value); - int bufferSize() const; - void setNotifyInterval(int milliSeconds); - int notifyInterval() const; - qint64 processedUSecs() const; - qint64 elapsedUSecs() const; - QAudio::Error error() const; - QAudio::State state() const; - void setFormat(const QAudioFormat &format); - QAudioFormat format() const; - - qint64 m_totalTimeValue; - QIODevice *m_audioSource; - QAudioFormat m_format; - QAudio::Error m_errorState; - QAudio::State m_deviceState; - -private slots: - void userFeed(); - bool deviceReady(); - -private: - int checkBytesReady(); - bool open(); - void close(); - - bool m_pullMode; - bool m_opened; - int m_bytesAvailable; - int m_bufferSize; - int m_periodSize; - int m_intervalTime; - unsigned int m_bufferTime; - unsigned int m_periodTime; - QTimer *m_timer; - qint64 m_elapsedTimeOffset; - char *audioBuffer; - pa_stream *m_stream; - QTime m_timeStamp; - QTime m_clockStamp; - QByteArray m_streamName; - QByteArray m_device; - QByteArray m_tempBuffer; -}; - -class InputPrivate : public QIODevice -{ - Q_OBJECT -public: - InputPrivate(QPulseAudioInput *audio); - ~InputPrivate() {}; - - qint64 readData(char *data, qint64 len); - qint64 writeData(const char *data, qint64 len); - - void trigger(); - -private: - QPulseAudioInput *m_audioDevice; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/pulseaudio/qaudiooutput_pulse.cpp b/src/plugins/pulseaudio/qaudiooutput_pulse.cpp deleted file mode 100644 index b638d07..0000000 --- a/src/plugins/pulseaudio/qaudiooutput_pulse.cpp +++ /dev/null @@ -1,621 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qcoreapplication.h> -#include <QtCore/qdebug.h> -#include <QtCore/qmath.h> - -#include "qaudiooutput_pulse.h" -#include "qaudiodeviceinfo_pulse.h" -#include "qpulseaudioengine.h" -#include "qpulsehelpers.h" - -QT_BEGIN_NAMESPACE - -const int PeriodTimeMs = 20; - -static void outputStreamWriteCallback(pa_stream *stream, size_t length, void *userdata) -{ - Q_UNUSED(stream); - Q_UNUSED(length); - Q_UNUSED(userdata); - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); -} - -static void outputStreamStateCallback(pa_stream *stream, void *userdata) -{ - Q_UNUSED(userdata) - pa_stream_state_t state = pa_stream_get_state(stream); -#ifdef DEBUG_PULSE - qDebug() << "Stream state: " << QPulseAudioInternal::stateToQString(state); -#endif - switch (state) { - case PA_STREAM_CREATING: - case PA_STREAM_READY: - case PA_STREAM_TERMINATED: - break; - - case PA_STREAM_FAILED: - default: - qWarning() << QString("Stream error: %1").arg(pa_strerror(pa_context_errno(pa_stream_get_context(stream)))); - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); - break; - } -} - -static void outputStreamUnderflowCallback(pa_stream *stream, void *userdata) -{ - Q_UNUSED(stream) - ((QPulseAudioOutput*)userdata)->streamUnderflowCallback(); - qWarning() << "Got a buffer underflow!"; -} - -static void outputStreamOverflowCallback(pa_stream *stream, void *userdata) -{ - Q_UNUSED(stream) - Q_UNUSED(userdata) - qWarning() << "Got a buffer overflow!"; -} - -static void outputStreamLatencyCallback(pa_stream *stream, void *userdata) -{ - Q_UNUSED(stream) - Q_UNUSED(userdata) - -#ifdef DEBUG_PULSE - const pa_timing_info *info = pa_stream_get_timing_info(stream); - - qDebug() << "Write index corrupt: " << info->write_index_corrupt; - qDebug() << "Write index: " << info->write_index; - qDebug() << "Read index corrupt: " << info->read_index_corrupt; - qDebug() << "Read index: " << info->read_index; - qDebug() << "Sink usec: " << info->sink_usec; - qDebug() << "Configured sink usec: " << info->configured_sink_usec; -#endif -} - -static void outputStreamSuccessCallback(pa_stream *stream, int success, void *userdata) -{ - Q_UNUSED(stream); - Q_UNUSED(success); - Q_UNUSED(userdata); - - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); -} - -static void outputStreamDrainComplete(pa_stream *stream, int success, void *userdata) -{ - Q_UNUSED(stream); - Q_UNUSED(success); - Q_UNUSED(userdata); - -#ifdef DEBUG_PULSE - qDebug() << "Draining completed successfully: " << (bool)success; -#endif -} - -QPulseAudioOutput::QPulseAudioOutput(const QByteArray &device) - : m_device(device) - , m_errorState(QAudio::NoError) - , m_deviceState(QAudio::StoppedState) - , m_pullMode(true) - , m_opened(false) - , m_audioSource(0) - , m_bytesAvailable(0) - , m_stream(0) - , m_notifyInterval(1000) - , m_periodSize(0) - , m_bufferSize(0) - , m_totalTimeValue(0) - , m_tickTimer(new QTimer(this)) - , m_audioBuffer(0) - , m_resuming(false) - , m_volume(1.0) -{ - connect(m_tickTimer, SIGNAL(timeout()), SLOT(userFeed())); -} - -QPulseAudioOutput::~QPulseAudioOutput() -{ - close(); - disconnect(m_tickTimer, SIGNAL(timeout())); - QCoreApplication::processEvents(); -} - -QAudio::Error QPulseAudioOutput::error() const -{ - return m_errorState; -} - -QAudio::State QPulseAudioOutput::state() const -{ - return m_deviceState; -} - -void QPulseAudioOutput::streamUnderflowCallback() -{ - if (m_deviceState != QAudio::IdleState && !m_resuming) { - m_errorState = QAudio::UnderrunError; - emit errorChanged(m_errorState); - m_deviceState = QAudio::IdleState; - emit stateChanged(m_deviceState); - } -} - -void QPulseAudioOutput::start(QIODevice *device) -{ - if (m_deviceState != QAudio::StoppedState) - m_deviceState = QAudio::StoppedState; - - m_errorState = QAudio::NoError; - - // Handle change of mode - if (m_audioSource && !m_pullMode) { - delete m_audioSource; - m_audioSource = 0; - } - - close(); - - m_pullMode = true; - m_audioSource = device; - - m_deviceState = QAudio::ActiveState; - - open(); - - emit stateChanged(m_deviceState); -} - -QIODevice *QPulseAudioOutput::start() -{ - if (m_deviceState != QAudio::StoppedState) - m_deviceState = QAudio::StoppedState; - - m_errorState = QAudio::NoError; - - // Handle change of mode - if (m_audioSource && !m_pullMode) { - delete m_audioSource; - m_audioSource = 0; - } - - close(); - - m_audioSource = new OutputPrivate(this); - m_audioSource->open(QIODevice::WriteOnly|QIODevice::Unbuffered); - m_pullMode = false; - - m_deviceState = QAudio::IdleState; - - open(); - - emit stateChanged(m_deviceState); - - return m_audioSource; -} - -bool QPulseAudioOutput::open() -{ - if (m_opened) - return false; - - pa_sample_spec spec = QPulseAudioInternal::audioFormatToSampleSpec(m_format); - - if (!pa_sample_spec_valid(&spec)) { - m_errorState = QAudio::OpenError; - m_deviceState = QAudio::StoppedState; - return false; - } - - m_spec = spec; - m_totalTimeValue = 0; - m_elapsedTimeOffset = 0; - m_timeStamp.restart(); - - if (m_streamName.isNull()) - m_streamName = QString(QLatin1String("QtmPulseStream-%1-%2")).arg(::getpid()).arg(quintptr(this)).toUtf8(); - -#ifdef DEBUG_PULSE - qDebug() << "Format: " << QPulseAudioInternal::sampleFormatToQString(spec.format); - qDebug() << "Rate: " << spec.rate; - qDebug() << "Channels: " << spec.channels; - qDebug() << "Frame size: " << pa_frame_size(&spec); -#endif - - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - pa_threaded_mainloop_lock(pulseEngine->mainloop()); - m_stream = pa_stream_new(pulseEngine->context(), m_streamName.constData(), &spec, 0); - - pa_stream_set_state_callback(m_stream, outputStreamStateCallback, this); - pa_stream_set_write_callback(m_stream, outputStreamWriteCallback, this); - - pa_stream_set_underflow_callback(m_stream, outputStreamUnderflowCallback, this); - pa_stream_set_overflow_callback(m_stream, outputStreamOverflowCallback, this); - pa_stream_set_latency_update_callback(m_stream, outputStreamLatencyCallback, this); - - pa_volume_t paVolume; - if (qFuzzyCompare(m_volume, 0.0)) { - paVolume = PA_VOLUME_MUTED; - m_volume = 0.0; - } else { - paVolume = qFloor(m_volume * PA_VOLUME_NORM + 0.5); - } - pa_cvolume_set(&m_chVolume, m_spec.channels, paVolume); - - if (pa_stream_connect_playback(m_stream, m_device.data(), NULL, (pa_stream_flags_t)0, &m_chVolume, NULL) < 0) { - qWarning() << "pa_stream_connect_playback() failed!"; - return false; - } - - while (pa_stream_get_state(m_stream) != PA_STREAM_READY) { - pa_threaded_mainloop_wait(pulseEngine->mainloop()); - } - pa_threaded_mainloop_unlock(pulseEngine->mainloop()); - -#ifdef DEBUG_PULSE - const pa_buffer_attr *buffer = pa_stream_get_buffer_attr(m_stream); - - qDebug() << "Buffering info:"; - qDebug() << "\tMax length: " << buffer->maxlength; - qDebug() << "\tTarget length: " << buffer->tlength; - qDebug() << "\tPre-buffering: " << buffer->prebuf; - qDebug() << "\tMinimum request: " << buffer->minreq; - qDebug() << "\tFragment size: " << buffer->fragsize; -#endif - - m_periodSize = pa_usec_to_bytes(PeriodTimeMs*1000, &spec); - m_opened = true; - m_tickTimer->start(PeriodTimeMs); - - m_elapsedTimeOffset = 0; - m_timeStamp.restart(); - m_clockStamp.restart(); - - return true; -} - -void QPulseAudioOutput::userFeed() -{ - if (m_deviceState == QAudio::StoppedState || m_deviceState == QAudio::SuspendedState) - return; - - if (m_deviceState == QAudio::IdleState) - m_bytesAvailable = bytesFree(); - - deviceReady(); -} - -void QPulseAudioOutput::close() -{ - m_tickTimer->stop(); - - if (m_stream) { - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - pa_threaded_mainloop_lock(pulseEngine->mainloop()); - pa_operation *o; - - pa_stream_set_write_callback(m_stream, NULL, NULL); - - if (!(o = pa_stream_drain(m_stream, outputStreamDrainComplete, NULL))) { - qWarning() << QString("pa_stream_drain(): %1").arg(pa_strerror(pa_context_errno(pa_stream_get_context(m_stream)))); - return; - } - pa_operation_unref(o); - - pa_stream_disconnect(m_stream); - pa_stream_unref(m_stream); - m_stream = NULL; - - pa_threaded_mainloop_unlock(pulseEngine->mainloop()); - } - - if (!m_pullMode && m_audioSource) { - delete m_audioSource; - m_audioSource = 0; - } - m_opened = false; -} - -bool QPulseAudioOutput::deviceReady() -{ - m_resuming = false; - - if (m_pullMode) { - int l = 0; - int chunks = m_bytesAvailable/m_periodSize; - if (chunks==0) { - m_bytesAvailable = bytesFree(); - return false; - } - - char buffer[m_periodSize]; - - l = m_audioSource->read(buffer, m_periodSize); - if (l > 0) { - if (m_deviceState != QAudio::ActiveState) - return true; - - qint64 bytesWritten = write(buffer, l); - Q_UNUSED(bytesWritten); - } - } - - if (m_deviceState != QAudio::ActiveState) - return true; - - if (m_notifyInterval && (m_timeStamp.elapsed() + m_elapsedTimeOffset) > m_notifyInterval) { - emit notify(); - m_elapsedTimeOffset = m_timeStamp.elapsed() + m_elapsedTimeOffset - m_notifyInterval; - m_timeStamp.restart(); - } - - return true; -} - -qint64 QPulseAudioOutput::write(const char *data, qint64 len) -{ - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - - pa_threaded_mainloop_lock(pulseEngine->mainloop()); - len = qMin(len, static_cast<qint64>(pa_stream_writable_size(m_stream))); - pa_stream_write(m_stream, data, len, 0, 0, PA_SEEK_RELATIVE); - pa_threaded_mainloop_unlock(pulseEngine->mainloop()); - m_totalTimeValue += len; - - m_errorState = QAudio::NoError; - if (m_deviceState != QAudio::ActiveState) { - m_deviceState = QAudio::ActiveState; - emit stateChanged(m_deviceState); - } - - return len; -} - -void QPulseAudioOutput::stop() -{ - if (m_deviceState == QAudio::StoppedState) - return; - - m_errorState = QAudio::NoError; - m_deviceState = QAudio::StoppedState; - close(); - emit stateChanged(m_deviceState); -} - -int QPulseAudioOutput::bytesFree() const -{ - if (m_deviceState != QAudio::ActiveState && m_deviceState != QAudio::IdleState) - return 0; - - return pa_stream_writable_size(m_stream); -} - -int QPulseAudioOutput::periodSize() const -{ - return m_periodSize; -} - -void QPulseAudioOutput::setBufferSize(int value) -{ - m_bufferSize = value; -} - -int QPulseAudioOutput::bufferSize() const -{ - return m_bufferSize; -} - -void QPulseAudioOutput::setNotifyInterval(int ms) -{ - m_notifyInterval = qMax(0, ms); -} - -int QPulseAudioOutput::notifyInterval() const -{ - return m_notifyInterval; -} - -qint64 QPulseAudioOutput::processedUSecs() const -{ - qint64 result = qint64(1000000) * m_totalTimeValue / - (m_format.channels() * (m_format.sampleSize() / 8)) / - m_format.frequency(); - - return result; -} - -void QPulseAudioOutput::resume() -{ - if (m_deviceState == QAudio::SuspendedState) { - m_resuming = true; - - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - - pa_threaded_mainloop_lock(pulseEngine->mainloop()); - - pa_operation *operation = pa_stream_cork(m_stream, 0, outputStreamSuccessCallback, NULL); - - while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) - pa_threaded_mainloop_wait(pulseEngine->mainloop()); - - pa_operation_unref(operation); - - operation = pa_stream_trigger(m_stream, outputStreamSuccessCallback, NULL); - - while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) - pa_threaded_mainloop_wait(pulseEngine->mainloop()); - - pa_operation_unref(operation); - - pa_threaded_mainloop_unlock(pulseEngine->mainloop()); - - m_deviceState = QAudio::ActiveState; - - m_errorState = QAudio::NoError; - m_tickTimer->start(PeriodTimeMs); - - emit stateChanged(m_deviceState); - } -} - -void QPulseAudioOutput::setFormat(const QAudioFormat &format) -{ - m_format = format; -} - -QAudioFormat QPulseAudioOutput::format() const -{ - return m_format; -} - -void QPulseAudioOutput::suspend() -{ - if (m_deviceState == QAudio::ActiveState || m_deviceState == QAudio::IdleState) { - m_tickTimer->stop(); - m_deviceState = QAudio::SuspendedState; - m_errorState = QAudio::NoError; - emit stateChanged(m_deviceState); - - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - pa_operation *operation; - - pa_threaded_mainloop_lock(pulseEngine->mainloop()); - - operation = pa_stream_cork(m_stream, 1, outputStreamSuccessCallback, NULL); - - while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) - pa_threaded_mainloop_wait(pulseEngine->mainloop()); - - pa_operation_unref(operation); - - pa_threaded_mainloop_unlock(pulseEngine->mainloop()); - } -} - -qint64 QPulseAudioOutput::elapsedUSecs() const -{ - if (m_deviceState == QAudio::StoppedState) - return 0; - - return m_clockStamp.elapsed() * 1000; -} - -void QPulseAudioOutput::reset() -{ - stop(); -} - -OutputPrivate::OutputPrivate(QPulseAudioOutput *audio) -{ - m_audioDevice = qobject_cast<QPulseAudioOutput*>(audio); -} - -qint64 OutputPrivate::readData(char *data, qint64 len) -{ - Q_UNUSED(data) - Q_UNUSED(len) - - return 0; -} - -qint64 OutputPrivate::writeData(const char *data, qint64 len) -{ - int retry = 0; - qint64 written = 0; - - if ((m_audioDevice->m_deviceState == QAudio::ActiveState) - ||(m_audioDevice->m_deviceState == QAudio::IdleState)) { - while(written < len) { - int chunk = m_audioDevice->write(data+written, (len-written)); - if (chunk <= 0) - retry++; - written+=chunk; - if (retry > 10) - return written; - } - } - - return written; -} - -void QPulseAudioOutput::setVolume(qreal vol) -{ - if (vol >= 0.0 && vol <= 1.0) { - if (!qFuzzyCompare(m_volume, vol)) { - m_volume = vol; - if (m_opened) { - QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance(); - pa_threaded_mainloop_lock(pulseEngine->mainloop()); - pa_volume_t paVolume; - if (qFuzzyCompare(vol, 0.0)) { - pa_cvolume_mute(&m_chVolume, m_spec.channels); - m_volume = 0.0; - } else { - paVolume = qFloor(m_volume * PA_VOLUME_NORM + 0.5); - pa_cvolume_set(&m_chVolume, m_spec.channels, paVolume); - } - pa_operation *op = pa_context_set_sink_input_volume(pulseEngine->context(), - pa_stream_get_index(m_stream), - &m_chVolume, - NULL, - NULL); - if (op == NULL) - qWarning()<<"QAudioOutput: Failed to set volume"; - else - pa_operation_unref(op); - pa_threaded_mainloop_unlock(pulseEngine->mainloop()); - } - } - } -} - -qreal QPulseAudioOutput::volume() const -{ - return m_volume; -} - -QT_END_NAMESPACE - -#include "moc_qaudiooutput_pulse.cpp" diff --git a/src/plugins/pulseaudio/qaudiooutput_pulse.h b/src/plugins/pulseaudio/qaudiooutput_pulse.h deleted file mode 100644 index 884164e..0000000 --- a/src/plugins/pulseaudio/qaudiooutput_pulse.h +++ /dev/null @@ -1,160 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QAUDIOOUTPUTPULSE_H -#define QAUDIOOUTPUTPULSE_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtCore/qfile.h> -#include <QtCore/qtimer.h> -#include <QtCore/qstring.h> -#include <QtCore/qstringlist.h> -#include <QtCore/qdatetime.h> - -#include "qaudio.h" -#include "qaudiodeviceinfo.h" -#include "qaudiosystem.h" - -#include <pulse/pulseaudio.h> - -QT_BEGIN_NAMESPACE - -class QPulseAudioOutput : public QAbstractAudioOutput -{ - friend class OutputPrivate; - Q_OBJECT - -public: - QPulseAudioOutput(const QByteArray &device); - ~QPulseAudioOutput(); - - void start(QIODevice *device); - QIODevice *start(); - void stop(); - void reset(); - void suspend(); - void resume(); - int bytesFree() const; - int periodSize() const; - void setBufferSize(int value); - int bufferSize() const; - void setNotifyInterval(int milliSeconds); - int notifyInterval() const; - qint64 processedUSecs() const; - qint64 elapsedUSecs() const; - QAudio::Error error() const; - QAudio::State state() const; - void setFormat(const QAudioFormat &format); - QAudioFormat format() const; - - void setVolume(qreal volume); - qreal volume() const; - -public: - void streamUnderflowCallback(); - -private: - bool open(); - void close(); - qint64 write(const char *data, qint64 len); - -private Q_SLOTS: - bool deviceReady(); - void userFeed(); - -private: - QByteArray m_device; - QByteArray m_streamName; - QAudioFormat m_format; - QAudio::Error m_errorState; - QAudio::State m_deviceState; - bool m_pullMode; - bool m_opened; - QIODevice *m_audioSource; - int m_bytesAvailable; - QTimer m_periodTimer; - pa_stream *m_stream; - int m_notifyInterval; - int m_periodSize; - int m_bufferSize; - QTime m_clockStamp; - qint64 m_totalTimeValue; - QTimer *m_tickTimer; - char *m_audioBuffer; - QTime m_timeStamp; - qint64 m_elapsedTimeOffset; - bool m_resuming; - - qreal m_volume; - pa_cvolume m_chVolume; - pa_sample_spec m_spec; -}; - -class OutputPrivate : public QIODevice -{ - friend class QPulseAudioOutput; - Q_OBJECT - -public: - OutputPrivate(QPulseAudioOutput *audio); - virtual ~OutputPrivate() {} - -protected: - qint64 readData(char *data, qint64 len); - qint64 writeData(const char *data, qint64 len); - -private: - QPulseAudioOutput *m_audioDevice; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/pulseaudio/qpulseaudioengine.cpp b/src/plugins/pulseaudio/qpulseaudioengine.cpp deleted file mode 100644 index 06afa5b..0000000 --- a/src/plugins/pulseaudio/qpulseaudioengine.cpp +++ /dev/null @@ -1,354 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qdebug.h> - -#include <qaudiodeviceinfo.h> -#include "qpulseaudioengine.h" -#include "qaudiodeviceinfo_pulse.h" -#include "qaudiooutput_pulse.h" -#include "qpulsehelpers.h" - -QT_BEGIN_NAMESPACE - -static void serverInfoCallback(pa_context *context, const pa_server_info *info, void *userdata) -{ - if (!info) { - qWarning() << QString("Failed to get server information: %s").arg(pa_strerror(pa_context_errno(context))); - return; - } - -#ifdef DEBUG_PULSE - char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX]; - - pa_sample_spec_snprint(ss, sizeof(ss), &info->sample_spec); - pa_channel_map_snprint(cm, sizeof(cm), &info->channel_map); - - qDebug() << QString("User name: %1\n" - "Host Name: %2\n" - "Server Name: %3\n" - "Server Version: %4\n" - "Default Sample Specification: %5\n" - "Default Channel Map: %6\n" - "Default Sink: %7\n" - "Default Source: %8\n").arg( - info->user_name, - info->host_name, - info->server_name, - info->server_version, - ss, - cm, - info->default_sink_name, - info->default_source_name); -#endif - - QPulseAudioEngine *pulseEngine = static_cast<QPulseAudioEngine*>(userdata); - pulseEngine->m_defaultSink = info->default_sink_name; - pulseEngine->m_defaultSource = info->default_source_name; - - pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); -} - -static void sinkInfoCallback(pa_context *context, const pa_sink_info *info, int isLast, void *userdata) -{ - QPulseAudioEngine *pulseEngine = static_cast<QPulseAudioEngine*>(userdata); - QMap<pa_sink_state, QString> stateMap; - stateMap[PA_SINK_INVALID_STATE] = "n/a"; - stateMap[PA_SINK_RUNNING] = "RUNNING"; - stateMap[PA_SINK_IDLE] = "IDLE"; - stateMap[PA_SINK_SUSPENDED] = "SUSPENDED"; - - if (isLast < 0) { - qWarning() << QString("Failed to get sink information: %s").arg(pa_strerror(pa_context_errno(context))); - return; - } - - if (isLast) { - pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); - return; - } - - Q_ASSERT(info); - -#ifdef DEBUG_PULSE - qDebug() << QString("Sink #%1\n" - "\tState: %2\n" - "\tName: %3\n" - "\tDescription: %4\n" - ).arg(QString::number(info->index), - stateMap.value(info->state), - info->name, - info->description); -#endif - - QAudioFormat format = QPulseAudioInternal::sampleSpecToAudioFormat(info->sample_spec); - pulseEngine->m_preferredFormats.insert(info->name, format); - pulseEngine->m_sinks.append(info->name); -} - -static void sourceInfoCallback(pa_context *context, const pa_source_info *info, int isLast, void *userdata) -{ - Q_UNUSED(context) - QPulseAudioEngine *pulseEngine = static_cast<QPulseAudioEngine*>(userdata); - - QMap<pa_source_state, QString> stateMap; - stateMap[PA_SOURCE_INVALID_STATE] = "n/a"; - stateMap[PA_SOURCE_RUNNING] = "RUNNING"; - stateMap[PA_SOURCE_IDLE] = "IDLE"; - stateMap[PA_SOURCE_SUSPENDED] = "SUSPENDED"; - - if (isLast) { - pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); - return; - } - - Q_ASSERT(info); - -#ifdef DEBUG_PULSE - qDebug() << QString("Source #%1\n" - "\tState: %2\n" - "\tName: %3\n" - "\tDescription: %4\n" - ).arg(QString::number(info->index), - stateMap.value(info->state), - info->name, - info->description); -#endif - - QAudioFormat format = QPulseAudioInternal::sampleSpecToAudioFormat(info->sample_spec); - pulseEngine->m_preferredFormats.insert(info->name, format); - pulseEngine->m_sources.append(info->name); -} - -static void contextStateCallbackInit(pa_context *context, void *userdata) -{ - Q_UNUSED(context); -#ifdef DEBUG_PULSE - qDebug() << QPulseAudioInternal::stateToQString(pa_context_get_state(context)); -#endif - QPulseAudioEngine *pulseEngine = reinterpret_cast<QPulseAudioEngine*>(userdata); - pa_threaded_mainloop_signal(pulseEngine->mainloop(), 0); -} - -static void contextStateCallback(pa_context *context, void *userdata) -{ - Q_UNUSED(userdata); - Q_UNUSED(context); - -#ifdef DEBUG_PULSE - pa_context_state_t state = pa_context_get_state(context); - qDebug() << QPulseAudioInternal::stateToQString(state); -#endif -} - -Q_GLOBAL_STATIC(QPulseAudioEngine, pulseEngine); - -QPulseAudioEngine::QPulseAudioEngine(QObject *parent) - : QObject(parent) -{ - bool keepGoing = true; - bool ok = true; - - m_mainLoop = pa_threaded_mainloop_new(); - if (m_mainLoop == 0) { - qWarning("Unable to create pulseaudio mainloop"); - return; - } - - if (pa_threaded_mainloop_start(m_mainLoop) != 0) { - qWarning("Unable to start pulseaudio mainloop"); - pa_threaded_mainloop_free(m_mainLoop); - return; - } - - m_mainLoopApi = pa_threaded_mainloop_get_api(m_mainLoop); - - pa_threaded_mainloop_lock(m_mainLoop); - - m_context = pa_context_new(m_mainLoopApi, QString(QLatin1String("QtmPulseContext:%1")).arg(::getpid()).toAscii().constData()); - pa_context_set_state_callback(m_context, contextStateCallbackInit, this); - - if (!m_context) { - qWarning("Unable to create new pulseaudio context"); - pa_threaded_mainloop_free(m_mainLoop); - return; - } - - if (pa_context_connect(m_context, NULL, (pa_context_flags_t)0, NULL) < 0) { - qWarning("Unable to create a connection to the pulseaudio context"); - pa_context_unref(m_context); - pa_threaded_mainloop_free(m_mainLoop); - return; - } - - pa_threaded_mainloop_wait(m_mainLoop); - - while (keepGoing) { - switch (pa_context_get_state(m_context)) { - case PA_CONTEXT_CONNECTING: - case PA_CONTEXT_AUTHORIZING: - case PA_CONTEXT_SETTING_NAME: - break; - - case PA_CONTEXT_READY: -#ifdef DEBUG_PULSE - qDebug("Connection established."); -#endif - keepGoing = false; - break; - - case PA_CONTEXT_TERMINATED: - qCritical("Context terminated."); - keepGoing = false; - ok = false; - break; - - case PA_CONTEXT_FAILED: - default: - qCritical() << QString("Connection failure: %1").arg(pa_strerror(pa_context_errno(m_context))); - keepGoing = false; - ok = false; - } - - if (keepGoing) { - pa_threaded_mainloop_wait(m_mainLoop); - } - } - - if (ok) { - pa_context_set_state_callback(m_context, contextStateCallback, this); - } else { - if (m_context) { - pa_context_unref(m_context); - m_context = 0; - } - } - - pa_threaded_mainloop_unlock(m_mainLoop); - - serverInfo(); - sinks(); - sources(); -} - -QPulseAudioEngine::~QPulseAudioEngine() -{ - if (m_context) { - pa_threaded_mainloop_lock(m_mainLoop); - pa_context_disconnect(m_context); - pa_threaded_mainloop_unlock(m_mainLoop); - m_context = 0; - } - - if (m_mainLoop) { - pa_threaded_mainloop_stop(m_mainLoop); - pa_threaded_mainloop_free(m_mainLoop); - m_mainLoop = 0; - } -} - -void QPulseAudioEngine::serverInfo() -{ - pa_operation *operation; - - pa_threaded_mainloop_lock(m_mainLoop); - - operation = pa_context_get_server_info(m_context, serverInfoCallback, this); - - while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) - pa_threaded_mainloop_wait(m_mainLoop); - - pa_operation_unref(operation); - - pa_threaded_mainloop_unlock(m_mainLoop); -} - -void QPulseAudioEngine::sinks() -{ - pa_operation *operation; - - pa_threaded_mainloop_lock(m_mainLoop); - - operation = pa_context_get_sink_info_list(m_context, sinkInfoCallback, this); - - while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) - pa_threaded_mainloop_wait(m_mainLoop); - - pa_operation_unref(operation); - - pa_threaded_mainloop_unlock(m_mainLoop); - - // Swap the default sink to index 0 - m_sinks.removeOne(m_defaultSink); - m_sinks.prepend(m_defaultSink); -} - -void QPulseAudioEngine::sources() -{ - pa_operation *operation; - - pa_threaded_mainloop_lock(m_mainLoop); - - operation = pa_context_get_source_info_list(m_context, sourceInfoCallback, this); - - while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) - pa_threaded_mainloop_wait(m_mainLoop); - - pa_operation_unref(operation); - - pa_threaded_mainloop_unlock(m_mainLoop); - - // Swap the default source to index 0 - m_sources.removeOne(m_defaultSource); - m_sources.prepend(m_defaultSource); -} - -QPulseAudioEngine *QPulseAudioEngine::instance() -{ - return pulseEngine(); -} - -QList<QByteArray> QPulseAudioEngine::availableDevices(QAudio::Mode mode) const -{ - return mode == QAudio::AudioOutput ? m_sinks : m_sources; -} - -QT_END_NAMESPACE diff --git a/src/plugins/pulseaudio/qpulseaudioengine.h b/src/plugins/pulseaudio/qpulseaudioengine.h deleted file mode 100644 index 63495ce..0000000 --- a/src/plugins/pulseaudio/qpulseaudioengine.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QPULSEAUDIOENGINE_H -#define QPULSEAUDIOENGINE_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtCore/qmap.h> -#include <QtCore/qbytearray.h> -#include <qaudiosystemplugin.h> -#include <pulse/pulseaudio.h> -#include "qpulsehelpers.h" -#include <qaudioformat.h> - -QT_BEGIN_NAMESPACE - -class QPulseAudioEngine : public QObject -{ - Q_OBJECT - -public: - QPulseAudioEngine(QObject *parent = 0); - ~QPulseAudioEngine(); - - static QPulseAudioEngine *instance(); - pa_threaded_mainloop *mainloop() { return m_mainLoop; } - pa_context *context() { return m_context; } - - QList<QByteArray> availableDevices(QAudio::Mode mode) const; - -private: - void serverInfo(); - void sinks(); - void sources(); - -public: - QList<QByteArray> m_sinks; - QList<QByteArray> m_sources; - QMap<QByteArray, QAudioFormat> m_preferredFormats; - - QByteArray m_defaultSink; - QByteArray m_defaultSource; - -private: - pa_mainloop_api *m_mainLoopApi; - pa_threaded_mainloop *m_mainLoop; - pa_context *m_context; - }; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/pulseaudio/qpulseaudioplugin.cpp b/src/plugins/pulseaudio/qpulseaudioplugin.cpp deleted file mode 100644 index 2544ebb..0000000 --- a/src/plugins/pulseaudio/qpulseaudioplugin.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qaudiodeviceinfo.h> - -#include "qpulseaudioplugin.h" -#include "qaudiodeviceinfo_pulse.h" -#include "qaudiooutput_pulse.h" -#include "qaudioinput_pulse.h" -#include "qpulseaudioengine.h" - -QT_BEGIN_NAMESPACE - -QPulseAudioPlugin::QPulseAudioPlugin(QObject *parent) - : QAudioSystemPlugin(parent) - , m_pulseEngine(QPulseAudioEngine::instance()) -{ -} - -QStringList QPulseAudioPlugin::keys() const -{ - return QStringList() << "default"; -} - -QList<QByteArray> QPulseAudioPlugin::availableDevices(QAudio::Mode mode) const -{ - return m_pulseEngine->availableDevices(mode); -} - -QAbstractAudioInput *QPulseAudioPlugin::createInput(const QByteArray &device) -{ - QPulseAudioInput *input = new QPulseAudioInput(device); - return input; -} - -QAbstractAudioOutput *QPulseAudioPlugin::createOutput(const QByteArray &device) -{ - - QPulseAudioOutput *output = new QPulseAudioOutput(device); - return output; -} - -QAbstractAudioDeviceInfo *QPulseAudioPlugin::createDeviceInfo(const QByteArray &device, QAudio::Mode mode) -{ - QPulseAudioDeviceInfo *deviceInfo = new QPulseAudioDeviceInfo(device, mode); - return deviceInfo; -} - -Q_EXPORT_PLUGIN2(qtmedia_pulse, QPulseAudioPlugin); - -QT_END_NAMESPACE diff --git a/src/plugins/pulseaudio/qpulseaudioplugin.h b/src/plugins/pulseaudio/qpulseaudioplugin.h deleted file mode 100644 index 7bb6e8b..0000000 --- a/src/plugins/pulseaudio/qpulseaudioplugin.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QPULSEAUDIOPLUGIN_H -#define QPULSEAUDIOPLUGIN_H - -#include <qaudiosystemplugin.h> - -QT_BEGIN_NAMESPACE - -class QPulseAudioEngine; - -class QPulseAudioPlugin : public QAudioSystemPlugin -{ - Q_OBJECT - -public: - QPulseAudioPlugin(QObject *parent = 0); - ~QPulseAudioPlugin() {} - - QStringList keys() const; - QList<QByteArray> availableDevices(QAudio::Mode mode) const; - QAbstractAudioInput *createInput(const QByteArray &device); - QAbstractAudioOutput *createOutput(const QByteArray &device); - QAbstractAudioDeviceInfo *createDeviceInfo(const QByteArray &device, QAudio::Mode mode); - -private: - QPulseAudioEngine *m_pulseEngine; -}; - -QT_BEGIN_NAMESPACE - -#endif diff --git a/src/plugins/pulseaudio/qpulsehelpers.cpp b/src/plugins/pulseaudio/qpulsehelpers.cpp deleted file mode 100644 index 10d54ed..0000000 --- a/src/plugins/pulseaudio/qpulsehelpers.cpp +++ /dev/null @@ -1,220 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qpulsehelpers.h" - -QT_BEGIN_NAMESPACE - -namespace QPulseAudioInternal -{ -pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format) -{ - pa_sample_spec spec; - - spec.rate = format.frequency(); - spec.channels = format.channels(); - - if (format.sampleSize() == 8) { - spec.format = PA_SAMPLE_U8; - } else if (format.sampleSize() == 16) { - switch (format.byteOrder()) { - case QAudioFormat::BigEndian: spec.format = PA_SAMPLE_S16BE; break; - case QAudioFormat::LittleEndian: spec.format = PA_SAMPLE_S16LE; break; - } - } else if (format.sampleSize() == 24) { - switch (format.byteOrder()) { - case QAudioFormat::BigEndian: spec.format = PA_SAMPLE_S24BE; break; - case QAudioFormat::LittleEndian: spec.format = PA_SAMPLE_S24LE; break; - } - } else if (format.sampleSize() == 32) { - switch (format.byteOrder()) { - case QAudioFormat::BigEndian: - format.sampleType() == QAudioFormat::Float ? spec.format = PA_SAMPLE_FLOAT32BE : spec.format = PA_SAMPLE_S32BE; - break; - case QAudioFormat::LittleEndian: - format.sampleType() == QAudioFormat::Float ? spec.format = PA_SAMPLE_FLOAT32LE : spec.format = PA_SAMPLE_S32LE; - break; - } - } else { - spec.format = PA_SAMPLE_INVALID; - } - - return spec; -} - -#ifdef DEBUG_PULSE -QString stateToQString(pa_stream_state_t state) -{ - switch (state) - { - case PA_STREAM_UNCONNECTED: return "Unconnected"; - case PA_STREAM_CREATING: return "Creating"; - case PA_STREAM_READY: return "Ready"; - case PA_STREAM_FAILED: return "Failed"; - case PA_STREAM_TERMINATED: return "Terminated"; - } - - return QString("Unknown state: %0").arg(state); -} - -QString sampleFormatToQString(pa_sample_format format) -{ - switch (format) - { - case PA_SAMPLE_U8: return "Unsigned 8 Bit PCM."; - case PA_SAMPLE_ALAW: return "8 Bit a-Law "; - case PA_SAMPLE_ULAW: return "8 Bit mu-Law"; - case PA_SAMPLE_S16LE: return "Signed 16 Bit PCM, little endian (PC)."; - case PA_SAMPLE_S16BE: return "Signed 16 Bit PCM, big endian."; - case PA_SAMPLE_FLOAT32LE: return "32 Bit IEEE floating point, little endian (PC), range -1.0 to 1.0"; - case PA_SAMPLE_FLOAT32BE: return "32 Bit IEEE floating point, big endian, range -1.0 to 1.0"; - case PA_SAMPLE_S32LE: return "Signed 32 Bit PCM, little endian (PC)."; - case PA_SAMPLE_S32BE: return "Signed 32 Bit PCM, big endian."; - case PA_SAMPLE_S24LE: return "Signed 24 Bit PCM packed, little endian (PC)."; - case PA_SAMPLE_S24BE: return "Signed 24 Bit PCM packed, big endian."; - case PA_SAMPLE_S24_32LE: return "Signed 24 Bit PCM in LSB of 32 Bit words, little endian (PC)."; - case PA_SAMPLE_S24_32BE: return "Signed 24 Bit PCM in LSB of 32 Bit words, big endian."; - case PA_SAMPLE_MAX: return "Upper limit of valid sample types."; - case PA_SAMPLE_INVALID: return "Invalid sample format"; - } - - return QString("Invalid value: %0").arg(format); -} - -QString stateToQString(pa_context_state_t state) -{ - switch (state) - { - case PA_CONTEXT_UNCONNECTED: return "Unconnected"; - case PA_CONTEXT_CONNECTING: return "Connecting"; - case PA_CONTEXT_AUTHORIZING: return "Authorizing"; - case PA_CONTEXT_SETTING_NAME: return "Setting Name"; - case PA_CONTEXT_READY: return "Ready"; - case PA_CONTEXT_FAILED: return "Failed"; - case PA_CONTEXT_TERMINATED: return "Terminated"; - } - - return QString("Unknown state: %0").arg(state); -} -#endif - -QAudioFormat sampleSpecToAudioFormat(pa_sample_spec spec) -{ - QAudioFormat format; - format.setFrequency(spec.rate); - format.setChannelCount(spec.channels); - format.setCodec("audio/pcm"); - - switch (spec.format) { - case PA_SAMPLE_U8: - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleType(QAudioFormat::UnSignedInt); - format.setSampleSize(8); - break; - case PA_SAMPLE_ALAW: - // TODO: - break; - case PA_SAMPLE_ULAW: - // TODO: - break; - case PA_SAMPLE_S16LE: - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleType(QAudioFormat::SignedInt); - format.setSampleSize(16); - break; - case PA_SAMPLE_S16BE: - format.setByteOrder(QAudioFormat::BigEndian); - format.setSampleType(QAudioFormat::SignedInt); - format.setSampleSize(16); - break; - case PA_SAMPLE_FLOAT32LE: - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleType(QAudioFormat::Float); - format.setSampleSize(32); - break; - case PA_SAMPLE_FLOAT32BE: - format.setByteOrder(QAudioFormat::BigEndian); - format.setSampleType(QAudioFormat::Float); - format.setSampleSize(32); - break; - case PA_SAMPLE_S32LE: - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleType(QAudioFormat::SignedInt); - format.setSampleSize(32); - break; - case PA_SAMPLE_S32BE: - format.setByteOrder(QAudioFormat::BigEndian); - format.setSampleType(QAudioFormat::SignedInt); - format.setSampleSize(32); - break; - case PA_SAMPLE_S24LE: - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleType(QAudioFormat::SignedInt); - format.setSampleSize(24); - break; - case PA_SAMPLE_S24BE: - format.setByteOrder(QAudioFormat::BigEndian); - format.setSampleType(QAudioFormat::SignedInt); - format.setSampleSize(24); - break; - case PA_SAMPLE_S24_32LE: - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleType(QAudioFormat::SignedInt); - format.setSampleSize(24); - break; - case PA_SAMPLE_S24_32BE: - format.setByteOrder(QAudioFormat::BigEndian); - format.setSampleType(QAudioFormat::SignedInt); - format.setSampleSize(24); - break; - case PA_SAMPLE_MAX: - case PA_SAMPLE_INVALID: - default: - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleType(QAudioFormat::Unknown); - format.setSampleSize(0); - } - - return format; -} -} - -QT_END_NAMESPACE diff --git a/src/plugins/pulseaudio/qpulsehelpers.h b/src/plugins/pulseaudio/qpulsehelpers.h deleted file mode 100644 index 035e92e..0000000 --- a/src/plugins/pulseaudio/qpulsehelpers.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QPULSEHELPER_H -#define QPULSEHELPER_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qaudiodeviceinfo.h" -#include <qaudioformat.h> -#include <pulse/pulseaudio.h> - -QT_BEGIN_NAMESPACE - -namespace QPulseAudioInternal -{ -pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format); -QString stateToQString(pa_stream_state_t state); -QString stateToQString(pa_context_state_t state); -QString sampleFormatToQString(pa_sample_format format); -QAudioFormat sampleSpecToAudioFormat(pa_sample_spec spec); -} - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/qt7/mediaplayer/mediaplayer.pri b/src/plugins/qt7/mediaplayer/mediaplayer.pri deleted file mode 100644 index 2edb1d2..0000000 --- a/src/plugins/qt7/mediaplayer/mediaplayer.pri +++ /dev/null @@ -1,16 +0,0 @@ -INCLUDEPATH += $$PWD - -DEFINES += QMEDIA_QT7_PLAYER - -HEADERS += \ - $$PWD/qt7playercontrol.h \ - $$PWD/qt7playermetadata.h \ - $$PWD/qt7playerservice.h \ - $$PWD/qt7playersession.h - -OBJECTIVE_SOURCES += \ - $$PWD/qt7playercontrol.mm \ - $$PWD/qt7playermetadata.mm \ - $$PWD/qt7playerservice.mm \ - $$PWD/qt7playersession.mm - diff --git a/src/plugins/qt7/mediaplayer/qt7playercontrol.h b/src/plugins/qt7/mediaplayer/qt7playercontrol.h deleted file mode 100644 index 54b9f4e..0000000 --- a/src/plugins/qt7/mediaplayer/qt7playercontrol.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT7PLAYERCONTROL_H -#define QT7PLAYERCONTROL_H - -#include <QtCore/qobject.h> - -#include <qmediaplayercontrol.h> -#include <qmediaplayer.h> - -#include <QtWidgets/qmacdefines_mac.h> - - -QT_BEGIN_NAMESPACE - -class QT7PlayerSession; -class QT7PlayerService; -class QMediaPlaylist; -class QMediaPlaylistNavigator; - -class QT7PlayerControl : public QMediaPlayerControl -{ -Q_OBJECT -public: - QT7PlayerControl(QObject *parent = 0); - ~QT7PlayerControl(); - - void setSession(QT7PlayerSession *session); - - QMediaPlayer::State state() const; - QMediaPlayer::MediaStatus mediaStatus() const; - - QMediaContent media() const; - const QIODevice *mediaStream() const; - void setMedia(const QMediaContent &content, QIODevice *stream); - - qint64 position() const; - qint64 duration() const; - - int bufferStatus() const; - - int volume() const; - bool isMuted() const; - - bool isAudioAvailable() const; - bool isVideoAvailable() const; - - bool isSeekable() const; - QMediaTimeRange availablePlaybackRanges() const; - - qreal playbackRate() const; - void setPlaybackRate(qreal rate); - -public Q_SLOTS: - void setPosition(qint64 pos); - - void play(); - void pause(); - void stop(); - - void setVolume(int volume); - void setMuted(bool muted); - -private: - QT7PlayerSession *m_session; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/qt7/mediaplayer/qt7playercontrol.mm b/src/plugins/qt7/mediaplayer/qt7playercontrol.mm deleted file mode 100644 index 56a6a61..0000000 --- a/src/plugins/qt7/mediaplayer/qt7playercontrol.mm +++ /dev/null @@ -1,191 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qt7playercontrol.h" -#include "qt7playersession.h" - -#include <qmediaplaylistnavigator.h> - -#include <QtCore/qurl.h> -#include <QtCore/qdebug.h> - -QT_USE_NAMESPACE - -QT7PlayerControl::QT7PlayerControl(QObject *parent) - : QMediaPlayerControl(parent) -{ -} - -QT7PlayerControl::~QT7PlayerControl() -{ -} - -void QT7PlayerControl::setSession(QT7PlayerSession *session) -{ - m_session = session; - - connect(m_session, SIGNAL(positionChanged(qint64)), this, SIGNAL(positionChanged(qint64))); - connect(m_session, SIGNAL(durationChanged(qint64)), this, SIGNAL(durationChanged(qint64))); - connect(m_session, SIGNAL(stateChanged(QMediaPlayer::State)), - this, SIGNAL(stateChanged(QMediaPlayer::State))); - connect(m_session, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), - this, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); - connect(m_session, SIGNAL(volumeChanged(int)), this, SIGNAL(volumeChanged(int))); - connect(m_session, SIGNAL(mutedChanged(bool)), this, SIGNAL(mutedChanged(bool))); - connect(m_session, SIGNAL(audioAvailableChanged(bool)), this, SIGNAL(audioAvailableChanged(bool))); - connect(m_session, SIGNAL(videoAvailableChanged(bool)), this, SIGNAL(videoAvailableChanged(bool))); - connect(m_session, SIGNAL(error(int,QString)), this, SIGNAL(error(int,QString))); -} - -qint64 QT7PlayerControl::position() const -{ - return m_session->position(); -} - -qint64 QT7PlayerControl::duration() const -{ - return m_session->duration(); -} - -QMediaPlayer::State QT7PlayerControl::state() const -{ - return m_session->state(); -} - -QMediaPlayer::MediaStatus QT7PlayerControl::mediaStatus() const -{ - return m_session->mediaStatus(); -} - -int QT7PlayerControl::bufferStatus() const -{ - return m_session->bufferStatus(); -} - -int QT7PlayerControl::volume() const -{ - return m_session->volume(); -} - -bool QT7PlayerControl::isMuted() const -{ - return m_session->isMuted(); -} - -bool QT7PlayerControl::isSeekable() const -{ - return m_session->isSeekable(); -} - -QMediaTimeRange QT7PlayerControl::availablePlaybackRanges() const -{ - return m_session->availablePlaybackRanges(); -} - -qreal QT7PlayerControl::playbackRate() const -{ - return m_session->playbackRate(); -} - -void QT7PlayerControl::setPlaybackRate(qreal rate) -{ - m_session->setPlaybackRate(rate); -} - -void QT7PlayerControl::setPosition(qint64 pos) -{ - m_session->setPosition(pos); -} - -void QT7PlayerControl::play() -{ - m_session->play(); -} - -void QT7PlayerControl::pause() -{ - m_session->pause(); -} - -void QT7PlayerControl::stop() -{ - m_session->stop(); -} - -void QT7PlayerControl::setVolume(int volume) -{ - m_session->setVolume(volume); -} - -void QT7PlayerControl::setMuted(bool muted) -{ - m_session->setMuted(muted); -} - -QMediaContent QT7PlayerControl::media() const -{ - return m_session->media(); -} - -const QIODevice *QT7PlayerControl::mediaStream() const -{ - return m_session->mediaStream(); -} - -void QT7PlayerControl::setMedia(const QMediaContent &content, QIODevice *stream) -{ - m_session->setMedia(content, stream); - - emit mediaChanged(content); -} - -bool QT7PlayerControl::isAudioAvailable() const -{ - return m_session->isAudioAvailable(); -} - -bool QT7PlayerControl::isVideoAvailable() const -{ - return m_session->isVideoAvailable(); -} - - -#include "moc_qt7playercontrol.cpp" diff --git a/src/plugins/qt7/mediaplayer/qt7playermetadata.h b/src/plugins/qt7/mediaplayer/qt7playermetadata.h deleted file mode 100644 index c5984a4..0000000 --- a/src/plugins/qt7/mediaplayer/qt7playermetadata.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT7PLAYERMETADATACONTROL_H -#define QT7PLAYERMETADATACONTROL_H - -#include <qmetadatareadercontrol.h> - -QT_BEGIN_NAMESPACE - -class QT7PlayerSession; - -class QT7PlayerMetaDataControl : public QMetaDataReaderControl -{ - Q_OBJECT -public: - QT7PlayerMetaDataControl(QT7PlayerSession *session, QObject *parent); - virtual ~QT7PlayerMetaDataControl(); - - bool isMetaDataAvailable() const; - bool isWritable() const; - - QVariant metaData(QtMultimedia::MetaData key) const; - QList<QtMultimedia::MetaData> availableMetaData() const; - - QVariant extendedMetaData(const QString &key) const ; - QStringList availableExtendedMetaData() const; - -private slots: - void updateTags(); - -private: - QT7PlayerSession *m_session; - QMap<QtMultimedia::MetaData, QVariant> m_tags; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/qt7/mediaplayer/qt7playermetadata.mm b/src/plugins/qt7/mediaplayer/qt7playermetadata.mm deleted file mode 100644 index 7432431..0000000 --- a/src/plugins/qt7/mediaplayer/qt7playermetadata.mm +++ /dev/null @@ -1,260 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qt7backend.h" -#include "qt7playermetadata.h" -#include "qt7playersession.h" -#include <QtCore/qvarlengtharray.h> - -#import <QTKit/QTMovie.h> - -#ifdef QUICKTIME_C_API_AVAILABLE - #include <QuickTime/QuickTime.h> - #undef check // avoid name clash; -#endif - -QT_USE_NAMESPACE - -QT7PlayerMetaDataControl::QT7PlayerMetaDataControl(QT7PlayerSession *session, QObject *parent) - :QMetaDataReaderControl(parent), m_session(session) -{ -} - -QT7PlayerMetaDataControl::~QT7PlayerMetaDataControl() -{ -} - -bool QT7PlayerMetaDataControl::isMetaDataAvailable() const -{ - return !m_tags.isEmpty(); -} - -bool QT7PlayerMetaDataControl::isWritable() const -{ - return false; -} - -QVariant QT7PlayerMetaDataControl::metaData(QtMultimedia::MetaData key) const -{ - return m_tags.value(key); -} - -QList<QtMultimedia::MetaData> QT7PlayerMetaDataControl::availableMetaData() const -{ - return m_tags.keys(); -} - -QVariant QT7PlayerMetaDataControl::extendedMetaData(const QString &key) const -{ - Q_UNUSED(key); - return QVariant(); -} - -QStringList QT7PlayerMetaDataControl::availableExtendedMetaData() const -{ - return QStringList(); -} - -#ifdef QUICKTIME_C_API_AVAILABLE - -static QString stripCopyRightSymbol(const QString &key) -{ - return key.right(key.length()-1); -} - -static QString convertQuickTimeKeyToUserKey(const QString &key) -{ - if (key == QLatin1String("com.apple.quicktime.displayname")) - return QLatin1String("nam"); - else if (key == QLatin1String("com.apple.quicktime.album")) - return QLatin1String("alb"); - else if (key == QLatin1String("com.apple.quicktime.artist")) - return QLatin1String("ART"); - else - return QLatin1String("???"); -} - -static OSStatus readMetaValue(QTMetaDataRef metaDataRef, QTMetaDataItem item, QTPropertyClass propClass, - QTPropertyID id, QTPropertyValuePtr *value, ByteCount *size) -{ - QTPropertyValueType type; - ByteCount propSize; - UInt32 propFlags; - OSStatus err = QTMetaDataGetItemPropertyInfo(metaDataRef, item, propClass, id, &type, &propSize, &propFlags); - - if (err == noErr) { - *value = malloc(propSize); - if (*value != 0) { - err = QTMetaDataGetItemProperty(metaDataRef, item, propClass, id, propSize, *value, size); - - if (err == noErr && (type == 'code' || type == 'itsk' || type == 'itlk')) { - // convert from native endian to big endian - OSTypePtr pType = (OSTypePtr)*value; - *pType = EndianU32_NtoB(*pType); - } - } - else - return -1; - } - - return err; -} - -static UInt32 getMetaType(QTMetaDataRef metaDataRef, QTMetaDataItem item) -{ - QTPropertyValuePtr value = 0; - ByteCount ignore = 0; - OSStatus err = readMetaValue( - metaDataRef, item, kPropertyClass_MetaDataItem, kQTMetaDataItemPropertyID_DataType, &value, &ignore); - - if (err == noErr) { - UInt32 type = *((UInt32 *) value); - if (value) - free(value); - return type; - } - - return 0; -} - -static QString cFStringToQString(CFStringRef str) -{ - if(!str) - return QString(); - CFIndex length = CFStringGetLength(str); - const UniChar *chars = CFStringGetCharactersPtr(str); - if (chars) - return QString(reinterpret_cast<const QChar *>(chars), length); - - QVarLengthArray<UniChar> buffer(length); - CFStringGetCharacters(str, CFRangeMake(0, length), buffer.data()); - return QString(reinterpret_cast<const QChar *>(buffer.constData()), length); -} - - -static QString getMetaValue(QTMetaDataRef metaDataRef, QTMetaDataItem item, SInt32 id) -{ - QTPropertyValuePtr value = 0; - ByteCount size = 0; - OSStatus err = readMetaValue(metaDataRef, item, kPropertyClass_MetaDataItem, id, &value, &size); - QString string; - - if (err == noErr) { - UInt32 dataType = getMetaType(metaDataRef, item); - switch (dataType){ - case kQTMetaDataTypeUTF8: - case kQTMetaDataTypeMacEncodedText: - string = cFStringToQString(CFStringCreateWithBytes(0, (UInt8*)value, size, kCFStringEncodingUTF8, false)); - break; - case kQTMetaDataTypeUTF16BE: - string = cFStringToQString(CFStringCreateWithBytes(0, (UInt8*)value, size, kCFStringEncodingUTF16BE, false)); - break; - default: - break; - } - - if (value) - free(value); - } - - return string; -} - - -static void readFormattedData(QTMetaDataRef metaDataRef, OSType format, QMultiMap<QString, QString> &result) -{ - QTMetaDataItem item = kQTMetaDataItemUninitialized; - OSStatus err = QTMetaDataGetNextItem(metaDataRef, format, item, kQTMetaDataKeyFormatWildcard, 0, 0, &item); - while (err == noErr){ - QString key = getMetaValue(metaDataRef, item, kQTMetaDataItemPropertyID_Key); - if (format == kQTMetaDataStorageFormatQuickTime) - key = convertQuickTimeKeyToUserKey(key); - else - key = stripCopyRightSymbol(key); - - if (!result.contains(key)){ - QString val = getMetaValue(metaDataRef, item, kQTMetaDataItemPropertyID_Value); - result.insert(key, val); - } - err = QTMetaDataGetNextItem(metaDataRef, format, item, kQTMetaDataKeyFormatWildcard, 0, 0, &item); - } -} -#endif - - -void QT7PlayerMetaDataControl::updateTags() -{ - bool wasEmpty = m_tags.isEmpty(); - m_tags.clear(); - - QTMovie *movie = (QTMovie*)m_session->movie(); - - if (movie) { - QMultiMap<QString, QString> metaMap; - -#ifdef QUICKTIME_C_API_AVAILABLE - QTMetaDataRef metaDataRef; - OSStatus err = QTCopyMovieMetaData([movie quickTimeMovie], &metaDataRef); - if (err == noErr) { - readFormattedData(metaDataRef, kQTMetaDataStorageFormatUserData, metaMap); - readFormattedData(metaDataRef, kQTMetaDataStorageFormatQuickTime, metaMap); - readFormattedData(metaDataRef, kQTMetaDataStorageFormatiTunes, metaMap); - } -#else - AutoReleasePool pool; - NSString *name = [movie attributeForKey:@"QTMovieDisplayNameAttribute"]; - metaMap.insert(QLatin1String("nam"), QString::fromUtf8([name UTF8String])); -#endif // QUICKTIME_C_API_AVAILABLE - - m_tags.insert(QtMultimedia::AlbumArtist, metaMap.value(QLatin1String("ART"))); - m_tags.insert(QtMultimedia::AlbumTitle, metaMap.value(QLatin1String("alb"))); - m_tags.insert(QtMultimedia::Title, metaMap.value(QLatin1String("nam"))); - m_tags.insert(QtMultimedia::Date, metaMap.value(QLatin1String("day"))); - m_tags.insert(QtMultimedia::Genre, metaMap.value(QLatin1String("gnre"))); - m_tags.insert(QtMultimedia::TrackNumber, metaMap.value(QLatin1String("trk"))); - m_tags.insert(QtMultimedia::Description, metaMap.value(QLatin1String("des"))); - } - - if (!wasEmpty || !m_tags.isEmpty()) - emit metaDataChanged(); -} - -#include "moc_qt7playermetadata.cpp" diff --git a/src/plugins/qt7/mediaplayer/qt7playerservice.h b/src/plugins/qt7/mediaplayer/qt7playerservice.h deleted file mode 100644 index b71eaf4..0000000 --- a/src/plugins/qt7/mediaplayer/qt7playerservice.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT7PLAYERSERVICE_H -#define QT7PLAYERSERVICE_H - -#include <QtCore/qobject.h> -#include <QtCore/qset.h> -#include <qmediaservice.h> - - -QT_BEGIN_NAMESPACE -class QMediaMetaData; -class QMediaPlayerControl; -class QMediaPlaylist; -class QMediaPlaylistNavigator; -class QT7PlayerControl; -class QT7PlayerMetaDataControl; -class QT7VideoWindowControl; -class QT7VideoWidgetControl; -class QT7VideoRendererControl; -class QT7VideoOutput; -class QT7PlayerSession; - -class QT7PlayerService : public QMediaService -{ -Q_OBJECT -public: - QT7PlayerService(QObject *parent = 0); - ~QT7PlayerService(); - - QMediaControl* requestControl(const char *name); - void releaseControl(QMediaControl *control); - -private: - QT7PlayerSession *m_session; - QT7PlayerControl *m_control; - QMediaControl * m_videoOutput; - QT7PlayerMetaDataControl *m_playerMetaDataControl; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/qt7/mediaplayer/qt7playerservice.mm b/src/plugins/qt7/mediaplayer/qt7playerservice.mm deleted file mode 100644 index f868fd5..0000000 --- a/src/plugins/qt7/mediaplayer/qt7playerservice.mm +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qvariant.h> -#include <QtCore/qdebug.h> -#include <QtWidgets/qwidget.h> - -#include "qt7backend.h" -#include "qt7playerservice.h" -#include "qt7playercontrol.h" -#include "qt7playersession.h" -#include "qt7videooutput.h" -#include "qt7movieviewoutput.h" -#include "qt7movieviewrenderer.h" -#include "qt7movierenderer.h" -#include "qt7movievideowidget.h" -#include "qt7playermetadata.h" - -#include <qmediaplaylistnavigator.h> -#include <qmediaplaylist.h> - -QT_USE_NAMESPACE - -QT7PlayerService::QT7PlayerService(QObject *parent): - QMediaService(parent), - m_videoOutput(0) -{ - m_session = new QT7PlayerSession(this); - - m_control = new QT7PlayerControl(this); - m_control->setSession(m_session); - - m_playerMetaDataControl = new QT7PlayerMetaDataControl(m_session, this); - connect(m_control, SIGNAL(mediaChanged(QMediaContent)), m_playerMetaDataControl, SLOT(updateTags())); -} - -QT7PlayerService::~QT7PlayerService() -{ -} - -QMediaControl *QT7PlayerService::requestControl(const char *name) -{ - if (qstrcmp(name, QMediaPlayerControl_iid) == 0) - return m_control; - - if (qstrcmp(name, QMetaDataReaderControl_iid) == 0) - return m_playerMetaDataControl; - -#ifndef QT_NO_OPENGL - if (!m_videoOutput) { - if (qstrcmp(name, QVideoWindowControl_iid) == 0) { -#if defined(QT_MAC_USE_COCOA) - m_videoOutput = new QT7MovieViewOutput(this); -#endif - } - - if (qstrcmp(name, QVideoRendererControl_iid) == 0) { -#ifdef QUICKTIME_C_API_AVAILABLE - m_videoOutput = new QT7MovieRenderer(this); -#else - m_videoOutput = new QT7MovieViewRenderer(this); -#endif - } - - if (qstrcmp(name, QVideoWidgetControl_iid) == 0) { -#ifdef QUICKTIME_C_API_AVAILABLE - m_videoOutput = new QT7MovieVideoWidget(this); -#endif - } - - if (m_videoOutput) { - QT7VideoOutput *videoOutput = qobject_cast<QT7VideoOutput*>(m_videoOutput); - m_session->setVideoOutput(videoOutput); - return m_videoOutput; - } - } -#endif // !defined(QT_NO_OPENGL) - - return 0; -} - -void QT7PlayerService::releaseControl(QMediaControl *control) -{ - if (m_videoOutput == control) { - m_videoOutput = 0; - m_session->setVideoOutput(0); - delete control; - } -} - -#include "moc_qt7playerservice.cpp" diff --git a/src/plugins/qt7/mediaplayer/qt7playersession.h b/src/plugins/qt7/mediaplayer/qt7playersession.h deleted file mode 100644 index c6e0115..0000000 --- a/src/plugins/qt7/mediaplayer/qt7playersession.h +++ /dev/null @@ -1,194 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT7PLAYERSESSION_H -#define QT7PLAYERSESSION_H - -#include <QtCore/qobject.h> -#include <QtCore/qbytearray.h> -#include <QtCore/qset.h> -#include <QtCore/qresource.h> - -#include <qmediaplayercontrol.h> -#include <qmediaplayer.h> - -#include <QtWidgets/qmacdefines_mac.h> - - -QT_BEGIN_NAMESPACE - -class QT7PlayerControl; -class QMediaPlaylist; -class QMediaPlaylistNavigator; -class QT7VideoOutput; -class QT7PlayerSession; -class QT7PlayerService; - - -class QT7PlayerSession : public QObject -{ - Q_OBJECT -public: - QT7PlayerSession(QObject *parent = 0); - ~QT7PlayerSession(); - - void *movie() const; - - void setControl(QT7PlayerControl *control); - - void setVideoOutput(QT7VideoOutput *output); - - QMediaPlayer::State state() const; - QMediaPlayer::MediaStatus mediaStatus() const; - - QMediaContent media() const; - const QIODevice *mediaStream() const; - void setMedia(const QMediaContent &content, QIODevice *stream); - - qint64 position() const; - qint64 duration() const; - - int bufferStatus() const; - - int volume() const; - bool isMuted() const; - - bool isAudioAvailable() const; - bool isVideoAvailable() const; - - bool isSeekable() const; - QMediaTimeRange availablePlaybackRanges() const; - - qreal playbackRate() const; - -public slots: - void setPlaybackRate(qreal rate); - - void setPosition(qint64 pos); - - void play(); - void pause(); - void stop(); - - void setVolume(int volume); - void setMuted(bool muted); - - void processEOS(); - void processLoadStateChange(); - void processVolumeChange(); - void processNaturalSizeChange(); - void processPositionChange(); - -signals: - void positionChanged(qint64 position); - void durationChanged(qint64 duration); - void stateChanged(QMediaPlayer::State newState); - void mediaStatusChanged(QMediaPlayer::MediaStatus status); - void volumeChanged(int volume); - void mutedChanged(bool muted); - void audioAvailableChanged(bool audioAvailable); - void videoAvailableChanged(bool videoAvailable); - void error(int error, const QString &errorString); - -private: - class ResourceHandler { - public: - ResourceHandler():resource(0) {} - ~ResourceHandler() { clear(); } - void setResourceFile(const QString &file) { - if (resource) { - if (resource->fileName() == file) - return; - delete resource; - rawData.clear(); - } - resource = new QResource(file); - } - bool isValid() const { return resource && resource->isValid() && resource->data() != 0; } - const uchar *data() { - if (!isValid()) - return 0; - if (resource->isCompressed()) { - if (rawData.size() == 0) - rawData = qUncompress(resource->data(), resource->size()); - return (const uchar *)rawData.constData(); - } - return resource->data(); - } - qint64 size() { - if (data() == 0) - return 0; - return resource->isCompressed() ? rawData.size() : resource->size(); - } - void clear() { - delete resource; - rawData.clear(); - } - QResource *resource; - QByteArray rawData; - }; - - void openMovie(bool tryAsync); - - void *m_QTMovie; - void *m_movieObserver; - - QMediaPlayer::State m_state; - QMediaPlayer::MediaStatus m_mediaStatus; - QIODevice *m_mediaStream; - QMediaContent m_resources; - ResourceHandler m_resourceHandler; - - QT7VideoOutput * m_videoOutput; - - bool m_muted; - bool m_tryingAsync; - int m_volume; - qreal m_rate; - - qint64 m_duration; - bool m_videoAvailable; - bool m_audioAvailable; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/qt7/mediaplayer/qt7playersession.mm b/src/plugins/qt7/mediaplayer/qt7playersession.mm deleted file mode 100644 index 1c1277a..0000000 --- a/src/plugins/qt7/mediaplayer/qt7playersession.mm +++ /dev/null @@ -1,751 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#import <QTKit/QTDataReference.h> -#import <QTKit/QTMovie.h> - -#include "qt7backend.h" - -#include "qt7playersession.h" -#include "qt7playercontrol.h" -#include "qt7videooutput.h" - -#include <QtNetwork/qnetworkcookie.h> -#include <qmediaplaylistnavigator.h> - -#include <CoreFoundation/CoreFoundation.h> -#include <Foundation/Foundation.h> - -#include <QtCore/qdatetime.h> -#include <QtCore/qurl.h> - -#include <QtCore/qdebug.h> - -QT_USE_NAMESPACE - -//#define QT_DEBUG_QT7 - -@interface QTMovieObserver : NSObject -{ -@private - QT7PlayerSession *m_session; - QTMovie *m_movie; -} - -- (QTMovieObserver *) initWithPlayerSession:(QT7PlayerSession*)session; -- (void) setMovie:(QTMovie *)movie; -- (void) processEOS:(NSNotification *)notification; -- (void) processLoadStateChange:(NSNotification *)notification; -- (void) processVolumeChange:(NSNotification *)notification; -- (void) processNaturalSizeChange :(NSNotification *)notification; -- (void) processPositionChange :(NSNotification *)notification; -@end - -@implementation QTMovieObserver - -- (QTMovieObserver *) initWithPlayerSession:(QT7PlayerSession*)session -{ - if (!(self = [super init])) - return nil; - - self->m_session = session; - return self; -} - -- (void) setMovie:(QTMovie *)movie -{ - if (m_movie == movie) - return; - - if (m_movie) { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [m_movie release]; - } - - m_movie = movie; - - if (movie) { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(processEOS:) - name:QTMovieDidEndNotification - object:m_movie]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(processLoadStateChange:) - name:QTMovieLoadStateDidChangeNotification - object:m_movie]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(processVolumeChange:) - name:QTMovieVolumeDidChangeNotification - object:m_movie]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(processPositionChange:) - name:QTMovieTimeDidChangeNotification - object:m_movie]; - - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(processNaturalSizeChange:) - name:@"QTMovieNaturalSizeDidChangeNotification" - object:m_movie]; - - } - else { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(processNaturalSizeChange:) - name:QTMovieEditedNotification - object:m_movie]; - } - - [movie retain]; - } -} - -- (void) processEOS:(NSNotification *)notification -{ - Q_UNUSED(notification); - QMetaObject::invokeMethod(m_session, "processEOS", Qt::AutoConnection); -} - -- (void) processLoadStateChange:(NSNotification *)notification -{ - Q_UNUSED(notification); - QMetaObject::invokeMethod(m_session, "processLoadStateChange", Qt::AutoConnection); -} - -- (void) processVolumeChange:(NSNotification *)notification -{ - Q_UNUSED(notification); - QMetaObject::invokeMethod(m_session, "processVolumeChange", Qt::AutoConnection); -} - -- (void) processNaturalSizeChange :(NSNotification *)notification -{ - Q_UNUSED(notification); - QMetaObject::invokeMethod(m_session, "processNaturalSizeChange", Qt::AutoConnection); -} - -- (void) processPositionChange :(NSNotification *)notification -{ - Q_UNUSED(notification); - QMetaObject::invokeMethod(m_session, "processPositionChange", Qt::AutoConnection); -} - -@end - -static inline NSString *qString2CFStringRef(const QString &string) -{ - return [NSString stringWithCharacters:reinterpret_cast<const UniChar *>(string.unicode()) length:string.length()]; -} - -QT7PlayerSession::QT7PlayerSession(QObject *parent) - : QObject(parent) - , m_QTMovie(0) - , m_state(QMediaPlayer::StoppedState) - , m_mediaStatus(QMediaPlayer::NoMedia) - , m_mediaStream(0) - , m_videoOutput(0) - , m_muted(false) - , m_tryingAsync(false) - , m_volume(100) - , m_rate(1.0) - , m_duration(0) - , m_videoAvailable(false) - , m_audioAvailable(false) -{ - m_movieObserver = [[QTMovieObserver alloc] initWithPlayerSession:this]; -} - -QT7PlayerSession::~QT7PlayerSession() -{ - if (m_videoOutput) - m_videoOutput->setMovie(0); - - [(QTMovieObserver*)m_movieObserver setMovie:nil]; - [(QTMovieObserver*)m_movieObserver release]; - [(QTMovie*)m_QTMovie release]; -} - -void *QT7PlayerSession::movie() const -{ - return m_QTMovie; -} - -void QT7PlayerSession::setVideoOutput(QT7VideoOutput *output) -{ - if (m_videoOutput == output) - return; - - if (m_videoOutput) - m_videoOutput->setMovie(0); - - m_videoOutput = output; - - if (m_videoOutput && m_state != QMediaPlayer::StoppedState) - m_videoOutput->setMovie(m_QTMovie); -} - -qint64 QT7PlayerSession::position() const -{ - if (!m_QTMovie) - return 0; - - QTTime qtTime = [(QTMovie*)m_QTMovie currentTime]; - - return static_cast<quint64>(float(qtTime.timeValue) / float(qtTime.timeScale) * 1000.0f); -} - -qint64 QT7PlayerSession::duration() const -{ - if (!m_QTMovie) - return 0; - - QTTime qtTime = [(QTMovie*)m_QTMovie duration]; - - return static_cast<quint64>(float(qtTime.timeValue) / float(qtTime.timeScale) * 1000.0f); -} - -QMediaPlayer::State QT7PlayerSession::state() const -{ - return m_state; -} - -QMediaPlayer::MediaStatus QT7PlayerSession::mediaStatus() const -{ - return m_mediaStatus; -} - -int QT7PlayerSession::bufferStatus() const -{ - return 100; -} - -int QT7PlayerSession::volume() const -{ - return m_volume; -} - -bool QT7PlayerSession::isMuted() const -{ - return m_muted; -} - -bool QT7PlayerSession::isSeekable() const -{ - return true; -} - -#ifndef QUICKTIME_C_API_AVAILABLE -@interface QTMovie(QtExtensions) -- (NSArray*)loadedRanges; -- (QTTime)maxTimeLoaded; -@end -#endif - -QMediaTimeRange QT7PlayerSession::availablePlaybackRanges() const -{ - QTMovie *movie = (QTMovie*)m_QTMovie; -#ifndef QUICKTIME_C_API_AVAILABLE - AutoReleasePool pool; - if ([movie respondsToSelector:@selector(loadedRanges)]) { - QMediaTimeRange rc; - NSArray *r = [movie loadedRanges]; - for (NSValue *tr in r) { - QTTimeRange timeRange = [tr QTTimeRangeValue]; - qint64 startTime = qint64(float(timeRange.time.timeValue) / timeRange.time.timeScale * 1000.0); - rc.addInterval(startTime, startTime + qint64(float(timeRange.duration.timeValue) / timeRange.duration.timeScale * 1000.0)); - } - return rc; - } - else if ([movie respondsToSelector:@selector(maxTimeLoaded)]) { - QTTime loadedTime = [movie maxTimeLoaded]; - return QMediaTimeRange(0, qint64(float(loadedTime.timeValue) / loadedTime.timeScale * 1000.0)); - } -#else - TimeValue loadedTime; - TimeScale scale; - Movie m = [movie quickTimeMovie]; - if (GetMaxLoadedTimeInMovie(m, &loadedTime) == noErr) { - scale = GetMovieTimeScale(m); - return QMediaTimeRange(0, qint64(float(loadedTime) / scale * 1000.0f)); - } -#endif - return QMediaTimeRange(0, duration()); -} - -qreal QT7PlayerSession::playbackRate() const -{ - return m_rate; -} - -void QT7PlayerSession::setPlaybackRate(qreal rate) -{ - if (qFuzzyCompare(m_rate, rate)) - return; - - m_rate = rate; - - if (m_QTMovie != 0 && m_state == QMediaPlayer::PlayingState) { - AutoReleasePool pool; - float preferredRate = [[(QTMovie*)m_QTMovie attributeForKey:@"QTMoviePreferredRateAttribute"] floatValue]; - [(QTMovie*)m_QTMovie setRate:preferredRate * m_rate]; - } -} - -void QT7PlayerSession::setPosition(qint64 pos) -{ - if ( !isSeekable() || pos == position()) - return; - - if (duration() > 0) - pos = qMin(pos, duration()); - - QTTime newQTTime = [(QTMovie*)m_QTMovie currentTime]; - newQTTime.timeValue = (pos / 1000.0f) * newQTTime.timeScale; - [(QTMovie*)m_QTMovie setCurrentTime:newQTTime]; - - //reset the EndOfMedia status position is changed after playback is finished - if (m_mediaStatus == QMediaPlayer::EndOfMedia) - processLoadStateChange(); -} - -void QT7PlayerSession::play() -{ - if (m_state == QMediaPlayer::PlayingState) - return; - - m_state = QMediaPlayer::PlayingState; - - if (m_videoOutput) - m_videoOutput->setMovie(m_QTMovie); - - //reset the EndOfMedia status if the same file is played again - if (m_mediaStatus == QMediaPlayer::EndOfMedia) - processLoadStateChange(); - - AutoReleasePool pool; - float preferredRate = [[(QTMovie*)m_QTMovie attributeForKey:@"QTMoviePreferredRateAttribute"] floatValue]; - [(QTMovie*)m_QTMovie setRate:preferredRate * m_rate]; - - processLoadStateChange(); - emit stateChanged(m_state); -} - -void QT7PlayerSession::pause() -{ - if (m_state == QMediaPlayer::PausedState) - return; - - m_state = QMediaPlayer::PausedState; - - if (m_videoOutput) - m_videoOutput->setMovie(m_QTMovie); - - //reset the EndOfMedia status if the same file is played again - if (m_mediaStatus == QMediaPlayer::EndOfMedia) - processLoadStateChange(); - - [(QTMovie*)m_QTMovie setRate:0]; - - processLoadStateChange(); - emit stateChanged(m_state); -} - -void QT7PlayerSession::stop() -{ - if (m_state == QMediaPlayer::StoppedState) - return; - - m_state = QMediaPlayer::StoppedState; - - [(QTMovie*)m_QTMovie setRate:0]; - setPosition(0); - - if (m_videoOutput) - m_videoOutput->setMovie(0); - - processLoadStateChange(); - emit stateChanged(m_state); - emit positionChanged(position()); -} - -void QT7PlayerSession::setVolume(int volume) -{ - if (m_volume == volume) - return; - - m_volume = volume; - - if (m_QTMovie != 0) - [(QTMovie*)m_QTMovie setVolume:m_volume / 100.0f]; - - emit volumeChanged(m_volume); -} - -void QT7PlayerSession::setMuted(bool muted) -{ - if (m_muted == muted) - return; - - m_muted = muted; - - if (m_QTMovie != 0) - [(QTMovie*)m_QTMovie setMuted:m_muted]; - - emit mutedChanged(muted); -} - -QMediaContent QT7PlayerSession::media() const -{ - return m_resources; -} - -const QIODevice *QT7PlayerSession::mediaStream() const -{ - return m_mediaStream; -} - -void QT7PlayerSession::setMedia(const QMediaContent &content, QIODevice *stream) -{ - AutoReleasePool pool; - -#ifdef QT_DEBUG_QT7 - qDebug() << Q_FUNC_INFO << content.canonicalUrl(); -#endif - - if (m_QTMovie) { - [(QTMovieObserver*)m_movieObserver setMovie:nil]; - - if (m_videoOutput) - m_videoOutput->setMovie(0); - - [(QTMovie*)m_QTMovie release]; - m_QTMovie = 0; - m_resourceHandler.clear(); - } - - m_resources = content; - m_mediaStream = stream; - QMediaPlayer::MediaStatus oldMediaStatus = m_mediaStatus; - - if (content.isNull()) { - m_mediaStatus = QMediaPlayer::NoMedia; - if (m_state != QMediaPlayer::StoppedState) - emit stateChanged(m_state = QMediaPlayer::StoppedState); - - if (m_mediaStatus != oldMediaStatus) - emit mediaStatusChanged(m_mediaStatus); - emit positionChanged(position()); - return; - } - - m_mediaStatus = QMediaPlayer::LoadingMedia; - if (m_mediaStatus != oldMediaStatus) - emit mediaStatusChanged(m_mediaStatus); - - QNetworkRequest request = content.canonicalResource().request(); - - QVariant cookies = request.header(QNetworkRequest::CookieHeader); - if (cookies.isValid()) { - NSHTTPCookieStorage *store = [NSHTTPCookieStorage sharedHTTPCookieStorage]; - QList<QNetworkCookie> cookieList = cookies.value<QList<QNetworkCookie> >(); - - foreach (const QNetworkCookie &requestCookie, cookieList) { - NSMutableDictionary *p = [NSMutableDictionary dictionaryWithObjectsAndKeys: - qString2CFStringRef(requestCookie.name()), NSHTTPCookieName, - qString2CFStringRef(requestCookie.value()), NSHTTPCookieValue, - qString2CFStringRef(requestCookie.domain()), NSHTTPCookieDomain, - qString2CFStringRef(requestCookie.path()), NSHTTPCookiePath, - nil - ]; - if (requestCookie.isSessionCookie()) - [p setObject:[NSString stringWithUTF8String:"TRUE"] forKey:NSHTTPCookieDiscard]; - else - [p setObject:[NSDate dateWithTimeIntervalSince1970:requestCookie.expirationDate().toTime_t()] forKey:NSHTTPCookieExpires]; - - [store setCookie:[NSHTTPCookie cookieWithProperties:p]]; - } - } - - // Attempt multiple times to open the movie. - // First try - attempt open in async mode - openMovie(true); - - emit positionChanged(position()); -} - -void QT7PlayerSession::openMovie(bool tryAsync) -{ - QUrl requestUrl = m_resources.canonicalResource().request().url(); - if (requestUrl.scheme().isEmpty()) - requestUrl.setScheme(QLatin1String("file")); - -#ifdef QT_DEBUG_QT7 - qDebug() << Q_FUNC_INFO << requestUrl; -#endif - - NSError *err = 0; - NSString *urlString = [NSString stringWithUTF8String:requestUrl.toEncoded().constData()]; - - NSMutableDictionary *attr = [NSMutableDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithBool:YES], QTMovieOpenAsyncOKAttribute, - [NSNumber numberWithBool:YES], QTMovieIsActiveAttribute, - [NSNumber numberWithBool:YES], QTMovieResolveDataRefsAttribute, - [NSNumber numberWithBool:YES], QTMovieDontInteractWithUserAttribute, - nil]; - - - if (requestUrl.scheme() == QLatin1String("qrc")) { - // Load from Qt resource - m_resourceHandler.setResourceFile(QLatin1Char(':') + requestUrl.path()); - if (!m_resourceHandler.isValid()) { - emit error(QMediaPlayer::FormatError, tr("Attempting to play invalid Qt resource")); - return; - } - - CFDataRef resourceData = - CFDataCreateWithBytesNoCopy(0, m_resourceHandler.data(), m_resourceHandler.size(), kCFAllocatorNull); - - QTDataReference *dataReference = - [QTDataReference dataReferenceWithReferenceToData:(NSData*)resourceData - name:qString2CFStringRef(requestUrl.path()) - MIMEType:nil]; - - [attr setObject:dataReference forKey:QTMovieDataReferenceAttribute]; - - CFRelease(resourceData); - } else { - [attr setObject:[NSURL URLWithString:urlString] forKey:QTMovieURLAttribute]; - } - - if (tryAsync && QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) { - [attr setObject:[NSNumber numberWithBool:YES] forKey:@"QTMovieOpenAsyncRequiredAttribute"]; -// XXX: This is disabled for now. causes some problems with video playback for some formats -// [attr setObject:[NSNumber numberWithBool:YES] forKey:@"QTMovieOpenForPlaybackAttribute"]; - m_tryingAsync = true; - } - else - m_tryingAsync = false; - - m_QTMovie = [QTMovie movieWithAttributes:attr error:&err]; - if (err != nil) { - // First attempt to test for inability to perform async -// if ([err code] == QTErrorMovieOpeningCannotBeAsynchronous) { XXX: error code unknown! - if (m_tryingAsync) { - m_tryingAsync = false; - err = nil; - [attr removeObjectForKey:@"QTMovieOpenAsyncRequiredAttribute"]; - m_QTMovie = [QTMovie movieWithAttributes:attr error:&err]; - } - } - - if (err != nil) { - m_QTMovie = 0; - QString description = QString::fromUtf8([[err localizedDescription] UTF8String]); - emit error(QMediaPlayer::FormatError, description); - -#ifdef QT_DEBUG_QT7 - qDebug() << Q_FUNC_INFO << description; -#endif - } - else { - [(QTMovie*)m_QTMovie retain]; - - [(QTMovieObserver*)m_movieObserver setMovie:(QTMovie*)m_QTMovie]; - - if (m_state != QMediaPlayer::StoppedState && m_videoOutput) - m_videoOutput->setMovie(m_QTMovie); - - processLoadStateChange(); - - [(QTMovie*)m_QTMovie setMuted:m_muted]; - [(QTMovie*)m_QTMovie setVolume:m_volume / 100.0f]; - } -} - -bool QT7PlayerSession::isAudioAvailable() const -{ - if (!m_QTMovie) - return false; - - AutoReleasePool pool; - return [[(QTMovie*)m_QTMovie attributeForKey:@"QTMovieHasAudioAttribute"] boolValue] == YES; -} - -bool QT7PlayerSession::isVideoAvailable() const -{ - if (!m_QTMovie) - return false; - - AutoReleasePool pool; - return [[(QTMovie*)m_QTMovie attributeForKey:@"QTMovieHasVideoAttribute"] boolValue] == YES; -} - -void QT7PlayerSession::processEOS() -{ -#ifdef QT_DEBUG_QT7 - qDebug() << Q_FUNC_INFO; -#endif - emit positionChanged(position()); - m_mediaStatus = QMediaPlayer::EndOfMedia; - if (m_videoOutput) - m_videoOutput->setMovie(0); - emit stateChanged(m_state = QMediaPlayer::StoppedState); - emit mediaStatusChanged(m_mediaStatus); -} - -void QT7PlayerSession::processLoadStateChange() -{ - if (!m_QTMovie) - return; - - AutoReleasePool pool; - - long state = [[(QTMovie*)m_QTMovie attributeForKey:QTMovieLoadStateAttribute] longValue]; - -#ifdef QT_DEBUG_QT7 - qDebug() << Q_FUNC_INFO << state; -#endif - -#ifndef QUICKTIME_C_API_AVAILABLE - enum { - kMovieLoadStateError = -1L, - kMovieLoadStateLoading = 1000, - kMovieLoadStateLoaded = 2000, - kMovieLoadStatePlayable = 10000, - kMovieLoadStatePlaythroughOK = 20000, - kMovieLoadStateComplete = 100000 - }; -#endif - - if (state == kMovieLoadStateError) { - if (m_tryingAsync) { - NSError *error = [(QTMovie*)m_QTMovie attributeForKey:@"QTMovieLoadStateErrorAttribute"]; - if ([error code] == componentNotThreadSafeErr) { - // Last Async check, try again with no such flag - openMovie(false); - } - } - else { - if (m_videoOutput) - m_videoOutput->setMovie(0); - - emit error(QMediaPlayer::FormatError, tr("Failed to load media")); - emit mediaStatusChanged(m_mediaStatus = QMediaPlayer::InvalidMedia); - emit stateChanged(m_state = QMediaPlayer::StoppedState); - } - - return; - } - - QMediaPlayer::MediaStatus newStatus = QMediaPlayer::NoMedia; - bool isPlaying = (m_state != QMediaPlayer::StoppedState); - - if (state >= kMovieLoadStatePlaythroughOK) { - newStatus = isPlaying ? QMediaPlayer::BufferedMedia : QMediaPlayer::LoadedMedia; - } else if (state >= kMovieLoadStatePlayable) - newStatus = isPlaying ? QMediaPlayer::BufferingMedia : QMediaPlayer::LoadingMedia; - else if (state >= kMovieLoadStateLoading) { - if (!isPlaying) - newStatus = QMediaPlayer::LoadingMedia; - else if (m_mediaStatus >= QMediaPlayer::LoadedMedia) - newStatus = QMediaPlayer::StalledMedia; - else - newStatus = QMediaPlayer::LoadingMedia; - } - - if (state >= kMovieLoadStatePlayable && - m_state == QMediaPlayer::PlayingState && - [(QTMovie*)m_QTMovie rate] == 0) { - - float preferredRate = [[(QTMovie*)m_QTMovie attributeForKey:@"QTMoviePreferredRateAttribute"] floatValue]; - - [(QTMovie*)m_QTMovie setRate:preferredRate * m_rate]; - } - - if (state >= kMovieLoadStateLoaded) { - qint64 currentDuration = duration(); - if (m_duration != currentDuration) - emit durationChanged(m_duration = currentDuration); - - if (m_audioAvailable != isAudioAvailable()) - emit audioAvailableChanged(m_audioAvailable = !m_audioAvailable); - - if (m_videoAvailable != isVideoAvailable()) - emit videoAvailableChanged(m_videoAvailable = !m_videoAvailable); - } - - if (newStatus != m_mediaStatus) - emit mediaStatusChanged(m_mediaStatus = newStatus); -} - -void QT7PlayerSession::processVolumeChange() -{ - if (!m_QTMovie) - return; - - int newVolume = qRound(100.0f * [((QTMovie*)m_QTMovie) volume]); - - if (newVolume != m_volume) { - emit volumeChanged(m_volume = newVolume); - } -} - -void QT7PlayerSession::processNaturalSizeChange() -{ - AutoReleasePool pool; - NSSize size = [[(QTMovie*)m_QTMovie attributeForKey:@"QTMovieNaturalSizeAttribute"] sizeValue]; -#ifdef QT_DEBUG_QT7 - qDebug() << Q_FUNC_INFO << QSize(size.width, size.height); -#endif - - if (m_videoOutput) - m_videoOutput->updateNaturalSize(QSize(size.width, size.height)); -} - -void QT7PlayerSession::processPositionChange() -{ - emit positionChanged(position()); -} - -#include "moc_qt7playersession.cpp" diff --git a/src/plugins/qt7/qcvdisplaylink.h b/src/plugins/qt7/qcvdisplaylink.h deleted file mode 100644 index 46462ec..0000000 --- a/src/plugins/qt7/qcvdisplaylink.h +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QCVDISPLAYLINK_H -#define QCVDISPLAYLINK_H - -#include <QtCore/qobject.h> -#include <QtCore/qmutex.h> - -#include <qtmultimediadefs.h> - -#include <QuartzCore/CVDisplayLink.h> - -QT_BEGIN_NAMESPACE - -class QCvDisplayLink : public QObject -{ -Q_OBJECT -public: - QCvDisplayLink(QObject *parent = 0); - virtual ~QCvDisplayLink(); - - bool isValid(); - bool isActive() const; - -public slots: - void start(); - void stop(); - -signals: - void tick(const CVTimeStamp &ts); - -public: - void displayLinkEvent(const CVTimeStamp *); - -protected: - virtual bool event(QEvent *); - -private: - CVDisplayLinkRef m_displayLink; - QMutex m_displayLinkMutex; - bool m_pendingDisplayLinkEvent; - bool m_isActive; - CVTimeStamp m_frameTimeStamp; -}; - -QT_END_NAMESPACE - -#endif - diff --git a/src/plugins/qt7/qcvdisplaylink.mm b/src/plugins/qt7/qcvdisplaylink.mm deleted file mode 100644 index ea1b84b..0000000 --- a/src/plugins/qt7/qcvdisplaylink.mm +++ /dev/null @@ -1,156 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qcvdisplaylink.h" - -#include <QtCore/qcoreapplication.h> -#include <QtCore/qdebug.h> - -QT_USE_NAMESPACE - -static CVReturn CVDisplayLinkCallback(CVDisplayLinkRef displayLink, - const CVTimeStamp *inNow, - const CVTimeStamp *inOutputTime, - CVOptionFlags flagsIn, - CVOptionFlags *flagsOut, - void *displayLinkContext) -{ - Q_UNUSED(displayLink); - Q_UNUSED(inNow); - Q_UNUSED(flagsIn); - Q_UNUSED(flagsOut); - - QCvDisplayLink *link = (QCvDisplayLink *)displayLinkContext; - - link->displayLinkEvent(inOutputTime); - return kCVReturnSuccess; -} - - -QCvDisplayLink::QCvDisplayLink(QObject *parent) - :QObject(parent), - m_pendingDisplayLinkEvent(false), - m_isActive(false) -{ - // create display link for the main display - CVDisplayLinkCreateWithCGDisplay(kCGDirectMainDisplay, &m_displayLink); - if (m_displayLink) { - // set the current display of a display link. - CVDisplayLinkSetCurrentCGDisplay(m_displayLink, kCGDirectMainDisplay); - - // set the renderer output callback function - CVDisplayLinkSetOutputCallback(m_displayLink, &CVDisplayLinkCallback, this); - } -} - -QCvDisplayLink::~QCvDisplayLink() -{ - if (m_displayLink) { - CVDisplayLinkStop(m_displayLink); - CVDisplayLinkRelease(m_displayLink); - m_displayLink = NULL; - } -} - -bool QCvDisplayLink::isValid() -{ - return m_displayLink != 0; -} - -bool QCvDisplayLink::isActive() const -{ - return m_isActive; -} - -void QCvDisplayLink::start() -{ - if (m_displayLink && !m_isActive) { - CVDisplayLinkStart(m_displayLink); - m_isActive = true; - } -} - -void QCvDisplayLink::stop() -{ - if (m_displayLink && m_isActive) { - CVDisplayLinkStop(m_displayLink); - m_isActive = false; - } -} - -void QCvDisplayLink::displayLinkEvent(const CVTimeStamp *ts) -{ - // This function is called from a - // thread != gui thread. So we post the event. - // But we need to make sure that we don't post faster - // than the event loop can eat: - m_displayLinkMutex.lock(); - bool pending = m_pendingDisplayLinkEvent; - m_pendingDisplayLinkEvent = true; - m_frameTimeStamp = *ts; - m_displayLinkMutex.unlock(); - - if (!pending) - qApp->postEvent(this, new QEvent(QEvent::User), Qt::HighEventPriority); -} - -bool QCvDisplayLink::event(QEvent *event) -{ - switch (event->type()){ - case QEvent::User: { - m_displayLinkMutex.lock(); - m_pendingDisplayLinkEvent = false; - CVTimeStamp ts = m_frameTimeStamp; - m_displayLinkMutex.unlock(); - - emit tick(ts); - - return false; - } - break; - default: - break; - } - return QObject::event(event); -} - -#include "moc_qcvdisplaylink.cpp" - diff --git a/src/plugins/qt7/qt7.pro b/src/plugins/qt7/qt7.pro deleted file mode 100644 index e58b199..0000000 --- a/src/plugins/qt7/qt7.pro +++ /dev/null @@ -1,61 +0,0 @@ -load(qt_module) - -TARGET = qqt7engine -QT += multimedia-private multimediawidgets-private network widgets -PLUGIN_TYPE = mediaservice - -load(qt_plugin) -DESTDIR = $$QT.multimedia.plugins/$${PLUGIN_TYPE} - -!simulator { -QT += opengl -} - -#DEFINES += QT_DEBUG_QT7 - -LIBS += -framework AppKit -framework AudioUnit \ - -framework AudioToolbox -framework CoreAudio \ - -framework QuartzCore -framework QTKit - -# The Quicktime framework is only awailable for 32-bit builds, so we -# need to check for this before linking against it. -# QMAKE_MAC_XARCH is not awailable on Tiger, but at the same time, -# we never build for 64-bit architechtures on Tiger either: -contains(QMAKE_MAC_XARCH, no) { - LIBS += -framework QuickTime -} else { - LIBS += -Xarch_i386 -framework QuickTime -Xarch_ppc -framework QuickTime -} - -HEADERS += \ - qt7backend.h \ - qt7videooutput.h \ - qt7serviceplugin.h - -OBJECTIVE_SOURCES += \ - qt7backend.mm \ - qt7serviceplugin.mm - -!simulator { - HEADERS += \ - qt7movieviewoutput.h \ - qt7movievideowidget.h \ - qt7movieviewrenderer.h \ - qt7movierenderer.h \ - qt7ciimagevideobuffer.h \ - qcvdisplaylink.h - - OBJECTIVE_SOURCES += \ - qt7movieviewoutput.mm \ - qt7movievideowidget.mm \ - qt7movieviewrenderer.mm \ - qt7movierenderer.mm \ - qt7videooutput.mm \ - qt7ciimagevideobuffer.mm \ - qcvdisplaylink.mm -} - -include(mediaplayer/mediaplayer.pri) - -target.path += $$[QT_INSTALL_PLUGINS]/$${PLUGIN_TYPE} -INSTALLS += target diff --git a/src/plugins/qt7/qt7backend.h b/src/plugins/qt7/qt7backend.h deleted file mode 100644 index 92c56ed..0000000 --- a/src/plugins/qt7/qt7backend.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT7BACKEND_H -#define QT7BACKEND_H - -#include "qtmultimediadefs.h" - -#include <QtCore/QString> - -#ifndef Q_OS_SIMULATOR -#ifndef Q_OS_MAC64 -#define QUICKTIME_C_API_AVAILABLE -#endif -#endif // !defined(Q_WS_SIMULATOR) - -QT_BEGIN_NAMESPACE - -class AutoReleasePool -{ -private: - void *pool; -public: - AutoReleasePool(); - ~AutoReleasePool(); -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/qt7/qt7backend.mm b/src/plugins/qt7/qt7backend.mm deleted file mode 100644 index 9332b5f..0000000 --- a/src/plugins/qt7/qt7backend.mm +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qt7backend.h" - -#import <Foundation/NSAutoreleasePool.h> -#include <CoreFoundation/CFBase.h> - - -QT_BEGIN_NAMESPACE - -AutoReleasePool::AutoReleasePool() -{ - pool = (void*)[[NSAutoreleasePool alloc] init]; -} - -AutoReleasePool::~AutoReleasePool() -{ - [(NSAutoreleasePool*)pool release]; -} - -QT_END_NAMESPACE diff --git a/src/plugins/qt7/qt7ciimagevideobuffer.h b/src/plugins/qt7/qt7ciimagevideobuffer.h deleted file mode 100644 index 95d404a..0000000 --- a/src/plugins/qt7/qt7ciimagevideobuffer.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT7CIIMAGEVIDEOBUFFER_H -#define QT7CIIMAGEVIDEOBUFFER_H - -#include "qt7backend.h" -#import <QTKit/QTKit.h> - -#include <QtCore/qvariant.h> -#include <qabstractvideobuffer.h> - - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -QT_BEGIN_NAMESPACE - -class QT7CIImageVideoBuffer : public QAbstractVideoBuffer -{ -public: - QT7CIImageVideoBuffer(CIImage *image); - - virtual ~QT7CIImageVideoBuffer(); - - MapMode mapMode() const; - uchar *map(MapMode mode, int *numBytes, int *bytesPerLine); - void unmap(); - QVariant handle() const; - -private: - CIImage *m_image; - NSBitmapImageRep *m_buffer; - MapMode m_mode; -}; - - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/qt7/qt7ciimagevideobuffer.mm b/src/plugins/qt7/qt7ciimagevideobuffer.mm deleted file mode 100644 index cf85372..0000000 --- a/src/plugins/qt7/qt7ciimagevideobuffer.mm +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qt7ciimagevideobuffer.h" - -#include <QuartzCore/CIFilter.h> -#include <QuartzCore/CIVector.h> - -QT7CIImageVideoBuffer::QT7CIImageVideoBuffer(CIImage *image) - : QAbstractVideoBuffer(CoreImageHandle) - , m_image(image) - , m_buffer(0) - , m_mode(NotMapped) -{ - [m_image retain]; -} - -QT7CIImageVideoBuffer::~QT7CIImageVideoBuffer() -{ - [m_image release]; - [m_buffer release]; -} - -QAbstractVideoBuffer::MapMode QT7CIImageVideoBuffer::mapMode() const -{ - return m_mode; -} - -uchar *QT7CIImageVideoBuffer::map(QAbstractVideoBuffer::MapMode mode, int *numBytes, int *bytesPerLine) -{ - if (mode == NotMapped || m_mode != NotMapped || !m_image) - return 0; - - if (!m_buffer) { - //swap R and B channels - CIFilter *colorSwapFilter = [CIFilter filterWithName: @"CIColorMatrix" keysAndValues: - @"inputImage", m_image, - @"inputRVector", [CIVector vectorWithX: 0 Y: 0 Z: 1 W: 0], - @"inputGVector", [CIVector vectorWithX: 0 Y: 1 Z: 0 W: 0], - @"inputBVector", [CIVector vectorWithX: 1 Y: 0 Z: 0 W: 0], - @"inputAVector", [CIVector vectorWithX: 0 Y: 0 Z: 0 W: 1], - @"inputBiasVector", [CIVector vectorWithX: 0 Y: 0 Z: 0 W: 0], - nil]; - CIImage *img = [colorSwapFilter valueForKey: @"outputImage"]; - - m_buffer = [[NSBitmapImageRep alloc] initWithCIImage:img]; - } - - if (numBytes) - *numBytes = [m_buffer bytesPerPlane]; - - if (bytesPerLine) - *bytesPerLine = [m_buffer bytesPerRow]; - - m_mode = mode; - - return [m_buffer bitmapData]; -} - -void QT7CIImageVideoBuffer::unmap() -{ - m_mode = NotMapped; -} - -QVariant QT7CIImageVideoBuffer::handle() const -{ - return QVariant::fromValue<void*>(m_image); -} - diff --git a/src/plugins/qt7/qt7movierenderer.h b/src/plugins/qt7/qt7movierenderer.h deleted file mode 100644 index 7055158..0000000 --- a/src/plugins/qt7/qt7movierenderer.h +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT7MOVIERENDERER_H -#define QT7MOVIERENDERER_H - -#include "qt7backend.h" - -#include <QtCore/qobject.h> -#include <QtCore/qmutex.h> - -#include <qvideorenderercontrol.h> -#include <qmediaplayer.h> - -#include <QtWidgets/qmacdefines_mac.h> -#include "qt7videooutput.h" - -#include <QuartzCore/CVOpenGLTexture.h> -#include <QuickTime/QuickTime.h> - -QT_BEGIN_NAMESPACE - -class QGLContext; - -class QCvDisplayLink; -class QT7PlayerSession; -class QT7PlayerService; - -class QT7MovieRenderer : public QT7VideoRendererControl -{ -Q_OBJECT -public: - QT7MovieRenderer(QObject *parent = 0); - virtual ~QT7MovieRenderer(); - - void setMovie(void *movie); - void updateNaturalSize(const QSize &newSize); - - QAbstractVideoSurface *surface() const; - void setSurface(QAbstractVideoSurface *surface); - - QSize nativeSize() const; - -private slots: - void updateVideoFrame(const CVTimeStamp &ts); - -private: - void setupVideoOutput(); - bool createPixelBufferVisualContext(); - bool createGLVisualContext(); - - void *m_movie; - - QMutex m_mutex; - - QCvDisplayLink *m_displayLink; -#ifdef QUICKTIME_C_API_AVAILABLE - QTVisualContextRef m_visualContext; - bool m_usingGLContext; - const QGLContext *m_currentGLContext; - QSize m_pixelBufferContextGeometry; -#endif - QAbstractVideoSurface *m_surface; - QSize m_nativeSize; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/qt7/qt7movierenderer.mm b/src/plugins/qt7/qt7movierenderer.mm deleted file mode 100644 index b020f4c..0000000 --- a/src/plugins/qt7/qt7movierenderer.mm +++ /dev/null @@ -1,479 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#import <QTKit/QTKit.h> - -#include "qt7backend.h" - -#include "qt7playercontrol.h" -#include "qt7movierenderer.h" -#include "qt7playersession.h" -#include "qt7ciimagevideobuffer.h" -#include "qcvdisplaylink.h" -#include <QtCore/qdebug.h> -#include <QtCore/qcoreapplication.h> - -#include <QGLWidget> - -#include <qabstractvideobuffer.h> -#include <qabstractvideosurface.h> -#include <qvideosurfaceformat.h> - -QT_USE_NAMESPACE - -//#define USE_MAIN_MONITOR_COLOR_SPACE 1 - -class CVGLTextureVideoBuffer : public QAbstractVideoBuffer -{ -public: - CVGLTextureVideoBuffer(CVOpenGLTextureRef buffer) - : QAbstractVideoBuffer(GLTextureHandle) - , m_buffer(buffer) - , m_mode(NotMapped) - { - CVOpenGLTextureRetain(m_buffer); - } - - virtual ~CVGLTextureVideoBuffer() - { - CVOpenGLTextureRelease(m_buffer); - } - - QVariant handle() const - { - GLuint id = CVOpenGLTextureGetName(m_buffer); - return QVariant(int(id)); - } - - MapMode mapMode() const { return m_mode; } - - uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) - { - if (numBytes) - *numBytes = 0; - - if (bytesPerLine) - *bytesPerLine = 0; - - m_mode = mode; - return 0; - } - - void unmap() { m_mode = NotMapped; } - -private: - CVOpenGLTextureRef m_buffer; - MapMode m_mode; -}; - - -class CVPixelBufferVideoBuffer : public QAbstractVideoBuffer -{ -public: - CVPixelBufferVideoBuffer(CVPixelBufferRef buffer) - : QAbstractVideoBuffer(NoHandle) - , m_buffer(buffer) - , m_mode(NotMapped) - { - CVPixelBufferRetain(m_buffer); - } - - virtual ~CVPixelBufferVideoBuffer() - { - CVPixelBufferRelease(m_buffer); - } - - MapMode mapMode() const { return m_mode; } - - uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) - { - if (mode != NotMapped && m_mode == NotMapped) { - CVPixelBufferLockBaseAddress(m_buffer, 0); - - if (numBytes) - *numBytes = CVPixelBufferGetDataSize(m_buffer); - - if (bytesPerLine) - *bytesPerLine = CVPixelBufferGetBytesPerRow(m_buffer); - - m_mode = mode; - - return (uchar*)CVPixelBufferGetBaseAddress(m_buffer); - } else { - return 0; - } - } - - void unmap() - { - if (m_mode != NotMapped) { - m_mode = NotMapped; - CVPixelBufferUnlockBaseAddress(m_buffer, 0); - } - } - -private: - CVPixelBufferRef m_buffer; - MapMode m_mode; -}; - - - -QT7MovieRenderer::QT7MovieRenderer(QObject *parent) - :QT7VideoRendererControl(parent), - m_movie(0), -#ifdef QUICKTIME_C_API_AVAILABLE - m_visualContext(0), - m_usingGLContext(false), - m_currentGLContext(0), -#endif - m_surface(0) -{ -#ifdef QT_DEBUG_QT7 - qDebug() << "QT7MovieRenderer"; -#endif - m_displayLink = new QCvDisplayLink(this); - connect(m_displayLink, SIGNAL(tick(CVTimeStamp)), SLOT(updateVideoFrame(CVTimeStamp))); -} - - -bool QT7MovieRenderer::createGLVisualContext() -{ -#ifdef QUICKTIME_C_API_AVAILABLE - AutoReleasePool pool; - CGLContextObj cglContext = CGLGetCurrentContext(); - NSOpenGLPixelFormat *nsglPixelFormat = [NSOpenGLView defaultPixelFormat]; - CGLPixelFormatObj cglPixelFormat = static_cast<CGLPixelFormatObj>([nsglPixelFormat CGLPixelFormatObj]); - - OSStatus err = QTOpenGLTextureContextCreate(kCFAllocatorDefault, cglContext, - cglPixelFormat, NULL, &m_visualContext); - if (err != noErr) - qWarning() << "Could not create visual context (OpenGL)"; - - return (err == noErr); -#endif // QUICKTIME_C_API_AVAILABLE - - return false; -} - -#ifdef QUICKTIME_C_API_AVAILABLE -static bool DictionarySetValue(CFMutableDictionaryRef dict, CFStringRef key, SInt32 value) -{ - CFNumberRef number = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value); - - if (number) { - CFDictionarySetValue( dict, key, number ); - CFRelease( number ); - return true; - } - return false; -} -#endif // QUICKTIME_C_API_AVAILABLE - -bool QT7MovieRenderer::createPixelBufferVisualContext() -{ -#ifdef QUICKTIME_C_API_AVAILABLE - if (m_visualContext) { - QTVisualContextRelease(m_visualContext); - m_visualContext = 0; - } - - m_pixelBufferContextGeometry = m_nativeSize; - - CFMutableDictionaryRef pixelBufferOptions = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); - //DictionarySetValue(pixelBufferOptions, kCVPixelBufferPixelFormatTypeKey, k32ARGBPixelFormat ); - DictionarySetValue(pixelBufferOptions, kCVPixelBufferPixelFormatTypeKey, k32BGRAPixelFormat ); - DictionarySetValue(pixelBufferOptions, kCVPixelBufferWidthKey, m_nativeSize.width() ); - DictionarySetValue(pixelBufferOptions, kCVPixelBufferHeightKey, m_nativeSize.height() ); - DictionarySetValue(pixelBufferOptions, kCVPixelBufferBytesPerRowAlignmentKey, 16); - //CFDictionarySetValue(pixelBufferOptions, kCVPixelBufferOpenGLCompatibilityKey, kCFBooleanTrue); - - CFMutableDictionaryRef visualContextOptions = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); - CFDictionarySetValue(visualContextOptions, kQTVisualContextPixelBufferAttributesKey, pixelBufferOptions); - - CGColorSpaceRef colorSpace = NULL; - -#if USE_MAIN_MONITOR_COLOR_SPACE - CMProfileRef sysprof = NULL; - - // Get the Systems Profile for the main display - if (CMGetSystemProfile(&sysprof) == noErr) { - // Create a colorspace with the systems profile - colorSpace = CGColorSpaceCreateWithPlatformColorSpace(sysprof); - CMCloseProfile(sysprof); - } -#endif - - if (!colorSpace) - colorSpace = CGColorSpaceCreateDeviceRGB(); - - CFDictionarySetValue(visualContextOptions, kQTVisualContextOutputColorSpaceKey, colorSpace); - - OSStatus err = QTPixelBufferContextCreate(kCFAllocatorDefault, - visualContextOptions, - &m_visualContext); - CFRelease(pixelBufferOptions); - CFRelease(visualContextOptions); - - if (err != noErr) { - qWarning() << "Could not create visual context (PixelBuffer)"; - return false; - } - - return true; -#endif // QUICKTIME_C_API_AVAILABLE - - return false; -} - - -QT7MovieRenderer::~QT7MovieRenderer() -{ - m_displayLink->stop(); -} - -void QT7MovieRenderer::setupVideoOutput() -{ - AutoReleasePool pool; - -#ifdef QT_DEBUG_QT7 - qDebug() << "QT7MovieRenderer::setupVideoOutput" << m_movie; -#endif - - if (m_movie == 0 || m_surface == 0) { - m_displayLink->stop(); - return; - } - - NSSize size = [[(QTMovie*)m_movie attributeForKey:@"QTMovieNaturalSizeAttribute"] sizeValue]; - m_nativeSize = QSize(size.width, size.height); - -#ifdef QUICKTIME_C_API_AVAILABLE - bool usedGLContext = m_usingGLContext; - - if (!m_nativeSize.isEmpty()) { - - bool glSupported = !m_surface->supportedPixelFormats(QAbstractVideoBuffer::GLTextureHandle).isEmpty(); - - //Try rendering using opengl textures first: - if (glSupported) { - QVideoSurfaceFormat format(m_nativeSize, QVideoFrame::Format_RGB32, QAbstractVideoBuffer::GLTextureHandle); - - if (m_surface->isActive()) - m_surface->stop(); - - if (!m_surface->start(format)) { - qWarning() << "failed to start video surface" << m_surface->error(); - qWarning() << "Surface format:" << format; - glSupported = false; - } else { - m_usingGLContext = true; - } - - } - - if (!glSupported) { - m_usingGLContext = false; - QVideoSurfaceFormat format(m_nativeSize, QVideoFrame::Format_RGB32); - - if (m_surface->isActive() && m_surface->surfaceFormat() != format) { -#ifdef QT_DEBUG_QT7 - qDebug() << "Surface format was changed, stop the surface."; -#endif - m_surface->stop(); - } - - if (!m_surface->isActive()) { -#ifdef QT_DEBUG_QT7 - qDebug() << "Starting the surface with format" << format; -#endif - if (!m_surface->start(format)) { - qWarning() << "failed to start video surface" << m_surface->error(); - qWarning() << "Surface format:" << format; - } - } - } - } - - - if (m_visualContext) { - //check if the visual context still can be reused - if (usedGLContext != m_usingGLContext || - (m_usingGLContext && (m_currentGLContext != QGLContext::currentContext())) || - (!m_usingGLContext && (m_pixelBufferContextGeometry != m_nativeSize))) { - QTVisualContextRelease(m_visualContext); - m_pixelBufferContextGeometry = QSize(); - m_visualContext = 0; - } - } - - if (!m_nativeSize.isEmpty()) { - if (!m_visualContext) { - if (m_usingGLContext) { -#ifdef QT_DEBUG_QT7 - qDebug() << "Building OpenGL visual context" << m_nativeSize; -#endif - m_currentGLContext = QGLContext::currentContext(); - if (!createGLVisualContext()) { - qWarning() << "QT7MovieRenderer: failed to create visual context"; - return; - } - } else { -#ifdef QT_DEBUG_QT7 - qDebug() << "Building Pixel Buffer visual context" << m_nativeSize; -#endif - if (!createPixelBufferVisualContext()) { - qWarning() << "QT7MovieRenderer: failed to create visual context"; - return; - } - } - } - - // targets a Movie to render into a visual context - SetMovieVisualContext([(QTMovie*)m_movie quickTimeMovie], m_visualContext); - - m_displayLink->start(); - } -#endif - -} - -void QT7MovieRenderer::setMovie(void *movie) -{ -#ifdef QT_DEBUG_QT7 - qDebug() << "QT7MovieRenderer::setMovie" << movie; -#endif - -#ifdef QUICKTIME_C_API_AVAILABLE - QMutexLocker locker(&m_mutex); - - if (m_movie != movie) { - if (m_movie) { - //ensure the old movie doesn't hold the visual context, otherwise it can't be reused - SetMovieVisualContext([(QTMovie*)m_movie quickTimeMovie], nil); - [(QTMovie*)m_movie release]; - } - - m_movie = movie; - [(QTMovie*)m_movie retain]; - - setupVideoOutput(); - } -#endif -} - -void QT7MovieRenderer::updateNaturalSize(const QSize &newSize) -{ - if (m_nativeSize != newSize) { - m_nativeSize = newSize; - setupVideoOutput(); - } -} - -QAbstractVideoSurface *QT7MovieRenderer::surface() const -{ - return m_surface; -} - -void QT7MovieRenderer::setSurface(QAbstractVideoSurface *surface) -{ -#ifdef QT_DEBUG_QT7 - qDebug() << "Set video surface" << surface; -#endif - - if (surface == m_surface) - return; - - QMutexLocker locker(&m_mutex); - - if (m_surface && m_surface->isActive()) - m_surface->stop(); - - m_surface = surface; - setupVideoOutput(); -} - - -QSize QT7MovieRenderer::nativeSize() const -{ - return m_nativeSize; -} - -void QT7MovieRenderer::updateVideoFrame(const CVTimeStamp &ts) -{ -#ifdef QUICKTIME_C_API_AVAILABLE - - QMutexLocker locker(&m_mutex); - - if (m_surface && m_surface->isActive() && - m_visualContext && QTVisualContextIsNewImageAvailable(m_visualContext, &ts)) { - - CVImageBufferRef imageBuffer = NULL; - - OSStatus status = QTVisualContextCopyImageForTime(m_visualContext, NULL, &ts, &imageBuffer); - - if (status == noErr && imageBuffer) { - QAbstractVideoBuffer *buffer = 0; - - if (m_usingGLContext) { - buffer = new QT7CIImageVideoBuffer([CIImage imageWithCVImageBuffer:imageBuffer]); - CVOpenGLTextureRelease((CVOpenGLTextureRef)imageBuffer); - } else { - buffer = new CVPixelBufferVideoBuffer((CVPixelBufferRef)imageBuffer); - //buffer = new QT7CIImageVideoBuffer( [CIImage imageWithCVImageBuffer:imageBuffer] ); - CVPixelBufferRelease((CVPixelBufferRef)imageBuffer); - } - - QVideoFrame frame(buffer, m_nativeSize, QVideoFrame::Format_RGB32); - m_surface->present(frame); - QTVisualContextTask(m_visualContext); - } - } -#else - Q_UNUSED(ts); -#endif -} - -#include "moc_qt7movierenderer.cpp" diff --git a/src/plugins/qt7/qt7movievideowidget.h b/src/plugins/qt7/qt7movievideowidget.h deleted file mode 100644 index d3e6078..0000000 --- a/src/plugins/qt7/qt7movievideowidget.h +++ /dev/null @@ -1,126 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT7MOVIEVIDEOWIDGET_H -#define QT7MOVIEVIDEOWIDGET_H - -#include <QtCore/qobject.h> -#include <QtCore/qmutex.h> - -#include <qvideowindowcontrol.h> -#include <qmediaplayer.h> - -#include <QtWidgets/qmacdefines_mac.h> -#include "qt7videooutput.h" - -#include <QuartzCore/CVOpenGLTexture.h> -#include <QuickTime/QuickTime.h> - -class GLVideoWidget; - -QT_BEGIN_NAMESPACE - -class QCvDisplayLink; -class QT7PlayerSession; -class QT7PlayerService; - -class QT7MovieVideoWidget : public QT7VideoWidgetControl -{ -Q_OBJECT -public: - QT7MovieVideoWidget(QObject *parent = 0); - virtual ~QT7MovieVideoWidget(); - - void setMovie(void *movie); - void updateNaturalSize(const QSize &newSize); - - QWidget *videoWidget(); - - bool isFullScreen() const; - void setFullScreen(bool fullScreen); - - QSize nativeSize() const; - - Qt::AspectRatioMode aspectRatioMode() const; - void setAspectRatioMode(Qt::AspectRatioMode mode); - - int brightness() const; - void setBrightness(int brightness); - - int contrast() const; - void setContrast(int contrast); - - int hue() const; - void setHue(int hue); - - int saturation() const; - void setSaturation(int saturation); - -private slots: - void updateVideoFrame(const CVTimeStamp &ts); - -private: - void setupVideoOutput(); - bool createVisualContext(); - - void updateColors(); - - void *m_movie; - GLVideoWidget *m_videoWidget; - - QCvDisplayLink *m_displayLink; - -#ifdef QUICKTIME_C_API_AVAILABLE - QTVisualContextRef m_visualContext; -#endif - - bool m_fullscreen; - QSize m_nativeSize; - Qt::AspectRatioMode m_aspectRatioMode; - int m_brightness; - int m_contrast; - int m_hue; - int m_saturation; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/qt7/qt7movievideowidget.mm b/src/plugins/qt7/qt7movievideowidget.mm deleted file mode 100644 index 5d9ea21..0000000 --- a/src/plugins/qt7/qt7movievideowidget.mm +++ /dev/null @@ -1,437 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qt7backend.h" - -#import <QTKit/QTDataReference.h> -#import <QTKit/QTMovie.h> -#import <QTKit/QTMovieView.h> -#import <QTKit/QTMovieLayer.h> -#import <AppKit/NSImage.h> -#import <OpenGL/glu.h> - - -#include "qt7playercontrol.h" -#include "qt7movievideowidget.h" -#include "qt7playersession.h" -#include "qcvdisplaylink.h" -#include <QtCore/qdebug.h> -#include <QtCore/qcoreapplication.h> - -#include <QGLWidget> - -#include <CoreFoundation/CoreFoundation.h> - -#import <QuartzCore/QuartzCore.h> - -#include "math.h" - -QT_USE_NAMESPACE - -class GLVideoWidget : public QGLWidget -{ -public: - - GLVideoWidget(QWidget *parent, const QGLFormat &format) - : QGLWidget(format, parent), - m_texRef(0), - m_nativeSize(640,480), - m_aspectRatioMode(Qt::KeepAspectRatio) - { - setAutoFillBackground(false); - } - - void initializeGL() - { - QColor bgColor = palette().color(QPalette::Background); - glClearColor(bgColor.redF(), bgColor.greenF(), bgColor.blueF(), bgColor.alphaF()); - } - - void resizeGL(int w, int h) - { - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glViewport(0, 0, GLsizei(w), GLsizei(h)); - gluOrtho2D(0, GLsizei(w), 0, GLsizei(h)); - updateGL(); - } - - void paintGL() - { - glClear(GL_COLOR_BUFFER_BIT); - if (!m_texRef) - return; - - glPushMatrix(); - glDisable(GL_CULL_FACE); - GLenum target = CVOpenGLTextureGetTarget(m_texRef); - glEnable(target); - - glBindTexture(target, CVOpenGLTextureGetName(m_texRef)); - glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - GLfloat lowerLeft[2], lowerRight[2], upperRight[2], upperLeft[2]; - CVOpenGLTextureGetCleanTexCoords(m_texRef, lowerLeft, lowerRight, upperRight, upperLeft); - - glBegin(GL_QUADS); - QRect rect = displayRect(); - glTexCoord2f(lowerLeft[0], lowerLeft[1]); - glVertex2i(rect.topLeft().x(), rect.topLeft().y()); - glTexCoord2f(lowerRight[0], lowerRight[1]); - glVertex2i(rect.topRight().x() + 1, rect.topRight().y()); - glTexCoord2f(upperRight[0], upperRight[1]); - glVertex2i(rect.bottomRight().x() + 1, rect.bottomRight().y() + 1); - glTexCoord2f(upperLeft[0], upperLeft[1]); - glVertex2i(rect.bottomLeft().x(), rect.bottomLeft().y() + 1); - glEnd(); - glPopMatrix(); - } - - void setCVTexture(CVOpenGLTextureRef texRef) - { - if (m_texRef) - CVOpenGLTextureRelease(m_texRef); - - m_texRef = texRef; - - if (m_texRef) - CVOpenGLTextureRetain(m_texRef); - - if (isVisible()) { - makeCurrent(); - paintGL(); - swapBuffers(); - } - } - - QSize sizeHint() const - { - return m_nativeSize; - } - - void setNativeSize(const QSize &size) - { - m_nativeSize = size; - } - - void setAspectRatioMode(Qt::AspectRatioMode mode) - { - if (m_aspectRatioMode != mode) { - m_aspectRatioMode = mode; - update(); - } - } - -private: - QRect displayRect() const - { - QRect displayRect = rect(); - - if (m_aspectRatioMode == Qt::KeepAspectRatio) { - QSize size = m_nativeSize; - size.scale(displayRect.size(), Qt::KeepAspectRatio); - - displayRect = QRect(QPoint(0, 0), size); - displayRect.moveCenter(rect().center()); - } - return displayRect; - } - - CVOpenGLTextureRef m_texRef; - QSize m_nativeSize; - Qt::AspectRatioMode m_aspectRatioMode; -}; - -QT7MovieVideoWidget::QT7MovieVideoWidget(QObject *parent) - :QT7VideoWidgetControl(parent), - m_movie(0), - m_videoWidget(0), - m_fullscreen(false), - m_aspectRatioMode(Qt::KeepAspectRatio), - m_brightness(0), - m_contrast(0), - m_hue(0), - m_saturation(0) -{ -#ifdef QT_DEBUG_QT7 - qDebug() << "QT7MovieVideoWidget"; -#endif - - QGLFormat format = QGLFormat::defaultFormat(); - format.setSwapInterval(1); // Vertical sync (avoid tearing) - m_videoWidget = new GLVideoWidget(0, format); - - m_displayLink = new QCvDisplayLink(this); - - connect(m_displayLink, SIGNAL(tick(CVTimeStamp)), SLOT(updateVideoFrame(CVTimeStamp))); - - if (!createVisualContext()) { - qWarning() << "QT7MovieVideoWidget: failed to create visual context"; - } -} - -bool QT7MovieVideoWidget::createVisualContext() -{ -#ifdef QUICKTIME_C_API_AVAILABLE - m_videoWidget->makeCurrent(); - - AutoReleasePool pool; - CGLContextObj cglContext = CGLGetCurrentContext(); - NSOpenGLPixelFormat *nsglPixelFormat = [NSOpenGLView defaultPixelFormat]; - CGLPixelFormatObj cglPixelFormat = static_cast<CGLPixelFormatObj>([nsglPixelFormat CGLPixelFormatObj]); - - CFTypeRef keys[] = { kQTVisualContextOutputColorSpaceKey }; - CGColorSpaceRef colorSpace = NULL; - CMProfileRef sysprof = NULL; - - // Get the Systems Profile for the main display - if (CMGetSystemProfile(&sysprof) == noErr) { - // Create a colorspace with the systems profile - colorSpace = CGColorSpaceCreateWithPlatformColorSpace(sysprof); - CMCloseProfile(sysprof); - } - - if (!colorSpace) - colorSpace = CGColorSpaceCreateDeviceRGB(); - - CFDictionaryRef textureContextAttributes = CFDictionaryCreate(kCFAllocatorDefault, - (const void **)keys, - (const void **)&colorSpace, 1, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); - - OSStatus err = QTOpenGLTextureContextCreate(kCFAllocatorDefault, - cglContext, - cglPixelFormat, - textureContextAttributes, - &m_visualContext); - if (err != noErr) - qWarning() << "Could not create visual context (OpenGL)"; - - - return (err == noErr); -#endif // QUICKTIME_C_API_AVAILABLE - - return false; -} - -QT7MovieVideoWidget::~QT7MovieVideoWidget() -{ - m_displayLink->stop(); - [(QTMovie*)m_movie release]; - delete m_videoWidget; -} - -QWidget *QT7MovieVideoWidget::videoWidget() -{ - return m_videoWidget; -} - -void QT7MovieVideoWidget::setupVideoOutput() -{ - AutoReleasePool pool; - -#ifdef QT_DEBUG_QT7 - qDebug() << "QT7MovieVideoWidget::setupVideoOutput" << m_movie; -#endif - - if (m_movie == 0) { - m_displayLink->stop(); - return; - } - - NSSize size = [[(QTMovie*)m_movie attributeForKey:@"QTMovieNaturalSizeAttribute"] sizeValue]; - m_nativeSize = QSize(size.width, size.height); - m_videoWidget->setNativeSize(m_nativeSize); - -#ifdef QUICKTIME_C_API_AVAILABLE - // targets a Movie to render into a visual context - SetMovieVisualContext([(QTMovie*)m_movie quickTimeMovie], m_visualContext); -#endif - - m_displayLink->start(); -} - -void QT7MovieVideoWidget::setMovie(void *movie) -{ - if (m_movie == movie) - return; - - if (m_movie) { -#ifdef QUICKTIME_C_API_AVAILABLE - SetMovieVisualContext([(QTMovie*)m_movie quickTimeMovie], nil); -#endif - [(QTMovie*)m_movie release]; - } - - m_movie = movie; - [(QTMovie*)m_movie retain]; - - setupVideoOutput(); -} - -void QT7MovieVideoWidget::updateNaturalSize(const QSize &newSize) -{ - if (m_nativeSize != newSize) { - m_nativeSize = newSize; - setupVideoOutput(); - } -} - -bool QT7MovieVideoWidget::isFullScreen() const -{ - return m_fullscreen; -} - -void QT7MovieVideoWidget::setFullScreen(bool fullScreen) -{ - m_fullscreen = fullScreen; -} - -QSize QT7MovieVideoWidget::nativeSize() const -{ - return m_nativeSize; -} - -Qt::AspectRatioMode QT7MovieVideoWidget::aspectRatioMode() const -{ - return m_aspectRatioMode; -} - -void QT7MovieVideoWidget::setAspectRatioMode(Qt::AspectRatioMode mode) -{ - m_aspectRatioMode = mode; - m_videoWidget->setAspectRatioMode(mode); -} - -int QT7MovieVideoWidget::brightness() const -{ - return m_brightness; -} - -void QT7MovieVideoWidget::setBrightness(int brightness) -{ - m_brightness = brightness; - updateColors(); -} - -int QT7MovieVideoWidget::contrast() const -{ - return m_contrast; -} - -void QT7MovieVideoWidget::setContrast(int contrast) -{ - m_contrast = contrast; - updateColors(); -} - -int QT7MovieVideoWidget::hue() const -{ - return m_hue; -} - -void QT7MovieVideoWidget::setHue(int hue) -{ - m_hue = hue; - updateColors(); -} - -int QT7MovieVideoWidget::saturation() const -{ - return m_saturation; -} - -void QT7MovieVideoWidget::setSaturation(int saturation) -{ - m_saturation = saturation; - updateColors(); -} - -void QT7MovieVideoWidget::updateColors() -{ -#ifdef QUICKTIME_C_API_AVAILABLE - if (m_movie) { - QTMovie *movie = (QTMovie*)m_movie; - - Float32 value; - value = m_brightness/100.0; - SetMovieVisualBrightness([movie quickTimeMovie], value, 0); - value = pow(2, m_contrast/50.0); - SetMovieVisualContrast([movie quickTimeMovie], value, 0); - value = m_hue/100.0; - SetMovieVisualHue([movie quickTimeMovie], value, 0); - value = 1.0+m_saturation/100.0; - SetMovieVisualSaturation([movie quickTimeMovie], value, 0); - } -#endif -} - -void QT7MovieVideoWidget::updateVideoFrame(const CVTimeStamp &ts) -{ -#ifdef QUICKTIME_C_API_AVAILABLE - AutoReleasePool pool; - // check for new frame - if (m_visualContext && QTVisualContextIsNewImageAvailable(m_visualContext, &ts)) { - CVOpenGLTextureRef currentFrame = NULL; - - // get a "frame" (image buffer) from the Visual Context, indexed by the provided time - OSStatus status = QTVisualContextCopyImageForTime(m_visualContext, NULL, &ts, ¤tFrame); - - // the above call may produce a null frame so check for this first - // if we have a frame, then draw it - if (status == noErr && currentFrame) { -#ifdef QT_DEBUG_QT7 - qDebug() << "render video frame"; -#endif - m_videoWidget->setCVTexture(currentFrame); - CVOpenGLTextureRelease(currentFrame); - } - QTVisualContextTask(m_visualContext); - } -#else - Q_UNUSED(ts); -#endif -} - -#include "moc_qt7movievideowidget.cpp" diff --git a/src/plugins/qt7/qt7movieviewoutput.h b/src/plugins/qt7/qt7movieviewoutput.h deleted file mode 100644 index d48255d..0000000 --- a/src/plugins/qt7/qt7movieviewoutput.h +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT7MOVIEVIEWOUTPUT_H -#define QT7MOVIEVIEWOUTPUT_H - -#include <QtCore/qobject.h> - -#include <qvideowindowcontrol.h> -#include <qmediaplayer.h> - -#include <QtWidgets/qmacdefines_mac.h> -#include "qt7videooutput.h" - - -QT_BEGIN_NAMESPACE - -class QT7PlayerSession; -class QT7PlayerService; - -class QT7MovieViewOutput : public QT7VideoWindowControl -{ -public: - QT7MovieViewOutput(QObject *parent = 0); - ~QT7MovieViewOutput(); - - void setMovie(void *movie); - void updateNaturalSize(const QSize &newSize); - - WId winId() const; - void setWinId(WId id); - - QRect displayRect() const; - void setDisplayRect(const QRect &rect); - - bool isFullScreen() const; - void setFullScreen(bool fullScreen); - - void repaint(); - - QSize nativeSize() const; - - Qt::AspectRatioMode aspectRatioMode() const; - void setAspectRatioMode(Qt::AspectRatioMode mode); - - int brightness() const; - void setBrightness(int brightness); - - int contrast() const; - void setContrast(int contrast); - - int hue() const; - void setHue(int hue); - - int saturation() const; - void setSaturation(int saturation); - -private: - void setupVideoOutput(); - - void *m_movie; - void *m_movieView; - bool m_layouted; - - WId m_winId; - QRect m_displayRect; - bool m_fullscreen; - QSize m_nativeSize; - Qt::AspectRatioMode m_aspectRatioMode; - int m_brightness; - int m_contrast; - int m_hue; - int m_saturation; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/qt7/qt7movieviewoutput.mm b/src/plugins/qt7/qt7movieviewoutput.mm deleted file mode 100644 index eebb32f..0000000 --- a/src/plugins/qt7/qt7movieviewoutput.mm +++ /dev/null @@ -1,339 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#import <QTKit/QTkit.h> - -#include "qt7backend.h" - -#include "qt7playercontrol.h" -#include "qt7movieviewoutput.h" -#include "qt7playersession.h" -#include <QtCore/qdebug.h> - -#include <QuartzCore/CIFilter.h> -#include <QuartzCore/CIVector.h> - -QT_USE_NAMESPACE - -#define VIDEO_TRANSPARENT(m) -(void)m:(NSEvent *)e{[[self superview] m:e];} - -@interface TransparentQTMovieView : QTMovieView -{ -@private - QRect *m_drawRect; - qreal m_brightness, m_contrast, m_saturation, m_hue; -} - -- (TransparentQTMovieView *) init; -- (void) setDrawRect:(QRect &)rect; -- (CIImage *) view:(QTMovieView *)view willDisplayImage:(CIImage *)img; -- (void) setContrast:(qreal) contrast; -@end - -@implementation TransparentQTMovieView - -- (TransparentQTMovieView *) init -{ - self = [super initWithFrame:NSZeroRect]; - if (self) { - [self setControllerVisible:NO]; - [self setContrast:1.0]; - [self setDelegate:self]; - } - return self; -} - -- (void) dealloc -{ - [super dealloc]; -} - -- (void) setContrast:(qreal) contrast -{ - m_hue = 0.0; - m_brightness = 0.0; - m_contrast = contrast; - m_saturation = 1.0; -} - - -- (void) setDrawRect:(QRect &)rect -{ - *m_drawRect = rect; - - NSRect nsrect; - nsrect.origin.x = m_drawRect->x(); - nsrect.origin.y = m_drawRect->y(); - nsrect.size.width = m_drawRect->width(); - nsrect.size.height = m_drawRect->height(); - [self setFrame:nsrect]; -} - -- (CIImage *) view:(QTMovieView *)view willDisplayImage:(CIImage *)img -{ - // This method is called from QTMovieView just - // before the image will be drawn. - Q_UNUSED(view); - - if ( !qFuzzyCompare(m_brightness, 0.0) || - !qFuzzyCompare(m_contrast, 1.0) || - !qFuzzyCompare(m_saturation, 1.0)){ - CIFilter *colorFilter = [CIFilter filterWithName:@"CIColorControls"]; - [colorFilter setValue:[NSNumber numberWithFloat:m_brightness] forKey:@"inputBrightness"]; - [colorFilter setValue:[NSNumber numberWithFloat:(m_contrast < 1) ? m_contrast : 1 + ((m_contrast-1)*3)] forKey:@"inputContrast"]; - [colorFilter setValue:[NSNumber numberWithFloat:m_saturation] forKey:@"inputSaturation"]; - [colorFilter setValue:img forKey:@"inputImage"]; - img = [colorFilter valueForKey:@"outputImage"]; - } - - /*if (m_hue){ - CIFilter *colorFilter = [CIFilter filterWithName:@"CIHueAdjust"]; - [colorFilter setValue:[NSNumber numberWithFloat:(m_hue * 3.14)] forKey:@"inputAngle"]; - [colorFilter setValue:img forKey:@"inputImage"]; - img = [colorFilter valueForKey:@"outputImage"]; - }*/ - - return img; -} - - -VIDEO_TRANSPARENT(mouseDown); -VIDEO_TRANSPARENT(mouseDragged); -VIDEO_TRANSPARENT(mouseUp); -VIDEO_TRANSPARENT(mouseMoved); -VIDEO_TRANSPARENT(mouseEntered); -VIDEO_TRANSPARENT(mouseExited); -VIDEO_TRANSPARENT(rightMouseDown); -VIDEO_TRANSPARENT(rightMouseDragged); -VIDEO_TRANSPARENT(rightMouseUp); -VIDEO_TRANSPARENT(otherMouseDown); -VIDEO_TRANSPARENT(otherMouseDragged); -VIDEO_TRANSPARENT(otherMouseUp); -VIDEO_TRANSPARENT(keyDown); -VIDEO_TRANSPARENT(keyUp); -VIDEO_TRANSPARENT(scrollWheel) - -@end - - -QT7MovieViewOutput::QT7MovieViewOutput(QObject *parent) - :QT7VideoWindowControl(parent), - m_movie(0), - m_movieView(0), - m_layouted(false), - m_winId(0), - m_fullscreen(false), - m_aspectRatioMode(Qt::KeepAspectRatio), - m_brightness(0), - m_contrast(0), - m_hue(0), - m_saturation(0) -{ -} - -QT7MovieViewOutput::~QT7MovieViewOutput() -{ - [(QTMovieView*)m_movieView release]; - [(QTMovie*)m_movie release]; -} - -void QT7MovieViewOutput::setupVideoOutput() -{ - AutoReleasePool pool; - -#ifdef QT_DEBUG_QT7 - qDebug() << "QT7MovieViewOutput::setupVideoOutput" << m_movie << m_winId; -#endif - if (m_movie == 0 || m_winId <= 0) - return; - - NSSize size = [[(QTMovie*)m_movie attributeForKey:@"QTMovieNaturalSizeAttribute"] sizeValue]; - m_nativeSize = QSize(size.width, size.height); - - if (!m_movieView) - m_movieView = [[TransparentQTMovieView alloc] init]; - - [(QTMovieView*)m_movieView setControllerVisible:NO]; - [(QTMovieView*)m_movieView setMovie:(QTMovie*)m_movie]; - - [(NSView *)m_winId addSubview:(QTMovieView*)m_movieView]; - m_layouted = true; - - setDisplayRect(m_displayRect); -} - -void QT7MovieViewOutput::setMovie(void *movie) -{ - if (m_movie != movie) { - if (m_movie) { - if (m_movieView) - [(QTMovieView*)m_movieView setMovie:nil]; - - [(QTMovie*)m_movie release]; - } - - m_movie = movie; - - if (m_movie) - [(QTMovie*)m_movie retain]; - - setupVideoOutput(); - } -} - -void QT7MovieViewOutput::updateNaturalSize(const QSize &newSize) -{ - if (m_nativeSize != newSize) { - m_nativeSize = newSize; - emit nativeSizeChanged(); - } -} - -WId QT7MovieViewOutput::winId() const -{ - return m_winId; -} - -void QT7MovieViewOutput::setWinId(WId id) -{ - if (m_winId != id) { - if (m_movieView && m_layouted) { - [(QTMovieView*)m_movieView removeFromSuperview]; - m_layouted = false; - } - - m_winId = id; - setupVideoOutput(); - } -} - -QRect QT7MovieViewOutput::displayRect() const -{ - return m_displayRect; -} - -void QT7MovieViewOutput::setDisplayRect(const QRect &rect) -{ - m_displayRect = rect; - - if (m_movieView) { - AutoReleasePool pool; - [(QTMovieView*)m_movieView setPreservesAspectRatio:(m_aspectRatioMode == Qt::KeepAspectRatio ? YES : NO)]; - [(QTMovieView*)m_movieView setFrame:NSMakeRect(m_displayRect.x(), - m_displayRect.y(), - m_displayRect.width(), - m_displayRect.height())]; - } - -} - -bool QT7MovieViewOutput::isFullScreen() const -{ - return m_fullscreen; -} - -void QT7MovieViewOutput::setFullScreen(bool fullScreen) -{ - m_fullscreen = fullScreen; - setDisplayRect(m_displayRect); -} - -void QT7MovieViewOutput::repaint() -{ -} - -QSize QT7MovieViewOutput::nativeSize() const -{ - return m_nativeSize; -} - -Qt::AspectRatioMode QT7MovieViewOutput::aspectRatioMode() const -{ - return m_aspectRatioMode; -} - -void QT7MovieViewOutput::setAspectRatioMode(Qt::AspectRatioMode mode) -{ - m_aspectRatioMode = mode; - setDisplayRect(m_displayRect); -} - -int QT7MovieViewOutput::brightness() const -{ - return m_brightness; -} - -void QT7MovieViewOutput::setBrightness(int brightness) -{ - m_brightness = brightness; -} - -int QT7MovieViewOutput::contrast() const -{ - return m_contrast; -} - -void QT7MovieViewOutput::setContrast(int contrast) -{ - m_contrast = contrast; - [(TransparentQTMovieView*)m_movieView setContrast:(contrast/100.0+1.0)]; -} - -int QT7MovieViewOutput::hue() const -{ - return m_hue; -} - -void QT7MovieViewOutput::setHue(int hue) -{ - m_hue = hue; -} - -int QT7MovieViewOutput::saturation() const -{ - return m_saturation; -} - -void QT7MovieViewOutput::setSaturation(int saturation) -{ - m_saturation = saturation; -} - diff --git a/src/plugins/qt7/qt7movieviewrenderer.h b/src/plugins/qt7/qt7movieviewrenderer.h deleted file mode 100644 index 6d5cef7..0000000 --- a/src/plugins/qt7/qt7movieviewrenderer.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT7MOVIEVIEWRENDERER_H -#define QT7MOVIEVIEWRENDERER_H - -#include <QtCore/qobject.h> -#include <QtCore/qmutex.h> - -#include <qvideowindowcontrol.h> -#include <qmediaplayer.h> - -#include <QtWidgets/qmacdefines_mac.h> -#include "qt7videooutput.h" -#include <qvideoframe.h> - -QT_BEGIN_NAMESPACE - -class QVideoFrame; - -class QT7PlayerSession; -class QT7PlayerService; - -class QT7MovieViewRenderer : public QT7VideoRendererControl -{ -public: - QT7MovieViewRenderer(QObject *parent = 0); - ~QT7MovieViewRenderer(); - - void setMovie(void *movie); - void updateNaturalSize(const QSize &newSize); - - QAbstractVideoSurface *surface() const; - void setSurface(QAbstractVideoSurface *surface); - - void renderFrame(const QVideoFrame &); - -protected: - bool event(QEvent *event); - -private: - void setupVideoOutput(); - - void *m_movie; - void *m_movieView; - QSize m_nativeSize; - QAbstractVideoSurface *m_surface; - QVideoFrame m_currentFrame; - bool m_pendingRenderEvent; - QMutex m_mutex; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/qt7/qt7movieviewrenderer.mm b/src/plugins/qt7/qt7movieviewrenderer.mm deleted file mode 100644 index dbc17d2..0000000 --- a/src/plugins/qt7/qt7movieviewrenderer.mm +++ /dev/null @@ -1,373 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#import <QTKit/QTKit.h> - -#include "qt7backend.h" - -#include "qt7playercontrol.h" -#include "qt7movieviewrenderer.h" -#include "qt7playersession.h" -#include "qt7ciimagevideobuffer.h" -#include <QtCore/qdebug.h> -#include <QtCore/qcoreevent.h> -#include <QtCore/qcoreapplication.h> - -#include <QtCore/qreadwritelock.h> - -#include <qabstractvideobuffer.h> -#include <qabstractvideosurface.h> -#include <qvideosurfaceformat.h> - -#include <QuartzCore/CIFilter.h> -#include <QuartzCore/CIVector.h> - -QT_USE_NAMESPACE - -class NSBitmapVideoBuffer : public QAbstractVideoBuffer -{ -public: - NSBitmapVideoBuffer(NSBitmapImageRep *buffer) - : QAbstractVideoBuffer(NoHandle) - , m_buffer(buffer) - , m_mode(NotMapped) - { - [m_buffer retain]; - } - - virtual ~NSBitmapVideoBuffer() - { - [m_buffer release]; - } - - MapMode mapMode() const { return m_mode; } - - uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) - { - if (mode != NotMapped && m_mode == NotMapped) { - if (numBytes) - *numBytes = [m_buffer bytesPerPlane]; - - if (bytesPerLine) - *bytesPerLine = [m_buffer bytesPerRow]; - - m_mode = mode; - - return [m_buffer bitmapData]; - } else { - return 0; - } - } - - void unmap() { m_mode = NotMapped; } - -private: - NSBitmapImageRep *m_buffer; - MapMode m_mode; -}; - - -#define VIDEO_TRANSPARENT(m) -(void)m:(NSEvent *)e{[[self superview] m:e];} - -@interface HiddenQTMovieView : QTMovieView -{ -@private - QWidget *m_window; - QT7MovieViewRenderer *m_renderer; - QReadWriteLock m_rendererLock; -} - -- (HiddenQTMovieView *) initWithRenderer:(QT7MovieViewRenderer *)renderer; -- (void) setRenderer:(QT7MovieViewRenderer *)renderer; -- (void) setDrawRect:(const QRect &)rect; -- (CIImage *) view:(QTMovieView *)view willDisplayImage:(CIImage *)img; -@end - -@implementation HiddenQTMovieView - -- (HiddenQTMovieView *) initWithRenderer:(QT7MovieViewRenderer *)renderer -{ - self = [super initWithFrame:NSZeroRect]; - if (self) { - [self setControllerVisible:NO]; - [self setDelegate:self]; - - QWriteLocker lock(&self->m_rendererLock); - self->m_renderer = renderer; - - self->m_window = new QWidget; - self->m_window->setWindowOpacity(0.0); - self->m_window->show(); - self->m_window->hide(); - - [(NSView *)(self->m_window->winId()) addSubview:self]; - [self setDrawRect:QRect(0,0,1,1)]; - } - return self; -} - -- (void) dealloc -{ - [super dealloc]; -} - -- (void) setRenderer:(QT7MovieViewRenderer *)renderer -{ - QWriteLocker lock(&m_rendererLock); - m_renderer = renderer; -} - -- (void) setDrawRect:(const QRect &)rect -{ - NSRect nsrect; - nsrect.origin.x = rect.x(); - nsrect.origin.y = rect.y(); - nsrect.size.width = rect.width(); - nsrect.size.height = rect.height(); - [self setFrame:nsrect]; -} - -- (CIImage *) view:(QTMovieView *)view willDisplayImage:(CIImage *)img -{ - // This method is called from QTMovieView just - // before the image will be drawn. - Q_UNUSED(view); - QReadLocker lock(&m_rendererLock); - - if (m_renderer) { - CGRect bounds = [img extent]; - int w = bounds.size.width; - int h = bounds.size.height; - - QVideoFrame frame; - - QAbstractVideoSurface *surface = m_renderer->surface(); - if (!surface || !surface->isActive()) - return img; - - if (surface->surfaceFormat().handleType() == QAbstractVideoBuffer::CoreImageHandle) { - //surface supports rendering of opengl based CIImage - frame = QVideoFrame(new QT7CIImageVideoBuffer(img), QSize(w,h), QVideoFrame::Format_RGB32 ); - } else { - //Swap R and B colors - CIFilter *colorSwapFilter = [CIFilter filterWithName: @"CIColorMatrix" keysAndValues: - @"inputImage", img, - @"inputRVector", [CIVector vectorWithX: 0 Y: 0 Z: 1 W: 0], - @"inputGVector", [CIVector vectorWithX: 0 Y: 1 Z: 0 W: 0], - @"inputBVector", [CIVector vectorWithX: 1 Y: 0 Z: 0 W: 0], - @"inputAVector", [CIVector vectorWithX: 0 Y: 0 Z: 0 W: 1], - @"inputBiasVector", [CIVector vectorWithX: 0 Y: 0 Z: 0 W: 0], - nil]; - CIImage *img = [colorSwapFilter valueForKey: @"outputImage"]; - NSBitmapImageRep *bitmap =[[NSBitmapImageRep alloc] initWithCIImage:img]; - //requesting the bitmap data is slow, - //but it's better to do it here to avoid blocking the main thread for a long. - [bitmap bitmapData]; - frame = QVideoFrame(new NSBitmapVideoBuffer(bitmap), QSize(w,h), QVideoFrame::Format_RGB32 ); - [bitmap release]; - } - - m_renderer->renderFrame(frame); - } - - return img; -} - -// Override this method so that the movie doesn't stop if -// the window becomes invisible -- (void)viewWillMoveToWindow:(NSWindow *)newWindow -{ - Q_UNUSED(newWindow); -} - - -VIDEO_TRANSPARENT(mouseDown); -VIDEO_TRANSPARENT(mouseDragged); -VIDEO_TRANSPARENT(mouseUp); -VIDEO_TRANSPARENT(mouseMoved); -VIDEO_TRANSPARENT(mouseEntered); -VIDEO_TRANSPARENT(mouseExited); -VIDEO_TRANSPARENT(rightMouseDown); -VIDEO_TRANSPARENT(rightMouseDragged); -VIDEO_TRANSPARENT(rightMouseUp); -VIDEO_TRANSPARENT(otherMouseDown); -VIDEO_TRANSPARENT(otherMouseDragged); -VIDEO_TRANSPARENT(otherMouseUp); -VIDEO_TRANSPARENT(keyDown); -VIDEO_TRANSPARENT(keyUp); -VIDEO_TRANSPARENT(scrollWheel) - -@end - - -QT7MovieViewRenderer::QT7MovieViewRenderer(QObject *parent) - :QT7VideoRendererControl(parent), - m_movie(0), - m_movieView(0), - m_surface(0), - m_pendingRenderEvent(false) -{ -} - -QT7MovieViewRenderer::~QT7MovieViewRenderer() -{ - [(HiddenQTMovieView*)m_movieView setRenderer:0]; - - QMutexLocker locker(&m_mutex); - m_currentFrame = QVideoFrame(); - [(HiddenQTMovieView*)m_movieView release]; -} - -void QT7MovieViewRenderer::setupVideoOutput() -{ - AutoReleasePool pool; - -#ifdef QT_DEBUG_QT7 - qDebug() << "QT7MovieViewRenderer::setupVideoOutput" << m_movie << m_surface; -#endif - - HiddenQTMovieView *movieView = (HiddenQTMovieView*)m_movieView; - - if (movieView && !m_movie) { - [movieView setMovie:nil]; - } - - if (m_movie) { - NSSize size = [[(QTMovie*)m_movie attributeForKey:@"QTMovieNaturalSizeAttribute"] sizeValue]; - - m_nativeSize = QSize(size.width, size.height); - - if (!movieView) { - movieView = [[HiddenQTMovieView alloc] initWithRenderer:this]; - m_movieView = movieView; - [movieView setControllerVisible:NO]; - } - - [movieView setMovie:(QTMovie*)m_movie]; - [movieView setDrawRect:QRect(QPoint(0,0), m_nativeSize)]; - } else { - m_nativeSize = QSize(); - } - - if (m_surface && !m_nativeSize.isEmpty()) { - bool coreImageFrameSupported = !m_surface->supportedPixelFormats(QAbstractVideoBuffer::CoreImageHandle).isEmpty() && - !m_surface->supportedPixelFormats(QAbstractVideoBuffer::GLTextureHandle).isEmpty(); - - QVideoSurfaceFormat format(m_nativeSize, QVideoFrame::Format_RGB32, - coreImageFrameSupported ? QAbstractVideoBuffer::CoreImageHandle : QAbstractVideoBuffer::NoHandle); - - if (m_surface->isActive() && m_surface->surfaceFormat() != format) { -#ifdef QT_DEBUG_QT7 - qDebug() << "Surface format was changed, stop the surface."; -#endif - m_surface->stop(); - } - - if (!m_surface->isActive()) { -#ifdef QT_DEBUG_QT7 - qDebug() << "Starting the surface with format" << format; -#endif - if (!m_surface->start(format)) - qWarning() << "failed to start video surface" << m_surface->error(); - } - } -} - -void QT7MovieViewRenderer::setMovie(void *movie) -{ - if (movie == m_movie) - return; - - QMutexLocker locker(&m_mutex); - m_movie = movie; - setupVideoOutput(); -} - -void QT7MovieViewRenderer::updateNaturalSize(const QSize &newSize) -{ - if (m_nativeSize != newSize) { - m_nativeSize = newSize; - setupVideoOutput(); - } -} - -QAbstractVideoSurface *QT7MovieViewRenderer::surface() const -{ - return m_surface; -} - -void QT7MovieViewRenderer::setSurface(QAbstractVideoSurface *surface) -{ - if (surface == m_surface) - return; - - QMutexLocker locker(&m_mutex); - - if (m_surface && m_surface->isActive()) - m_surface->stop(); - - m_surface = surface; - setupVideoOutput(); -} - -void QT7MovieViewRenderer::renderFrame(const QVideoFrame &frame) -{ - - QMutexLocker locker(&m_mutex); - m_currentFrame = frame; - - if (!m_pendingRenderEvent) - qApp->postEvent(this, new QEvent(QEvent::User), Qt::HighEventPriority); - - m_pendingRenderEvent = true; -} - -bool QT7MovieViewRenderer::event(QEvent *event) -{ - if (event->type() == QEvent::User) { - QMutexLocker locker(&m_mutex); - m_pendingRenderEvent = false; - if (m_surface->isActive()) - m_surface->present(m_currentFrame); - } - - return QT7VideoRendererControl::event(event); -} diff --git a/src/plugins/qt7/qt7serviceplugin.h b/src/plugins/qt7/qt7serviceplugin.h deleted file mode 100644 index 7ff1249..0000000 --- a/src/plugins/qt7/qt7serviceplugin.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QT7SERVICEPLUGIN_H -#define QT7SERVICEPLUGIN_H - -#include <qmediaserviceproviderplugin.h> - -QT_BEGIN_NAMESPACE - -class QT7ServicePlugin - : public QMediaServiceProviderPlugin - , public QMediaServiceSupportedFormatsInterface - , public QMediaServiceFeaturesInterface -{ - Q_INTERFACES(QMediaServiceFeaturesInterface) -public: - QT7ServicePlugin(); - - QStringList keys() const; - QMediaService* create(QString const& key); - void release(QMediaService *service); - - QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const; - QtMultimedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const; - QStringList supportedMimeTypes() const; - -private: - void buildSupportedTypes(); - - QStringList m_supportedMimeTypes; -}; - -QT_END_NAMESPACE - -#endif // QGSTREAMERSERVICEPLUGIN_H diff --git a/src/plugins/qt7/qt7serviceplugin.mm b/src/plugins/qt7/qt7serviceplugin.mm deleted file mode 100644 index 843ab41..0000000 --- a/src/plugins/qt7/qt7serviceplugin.mm +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#import <Foundation/Foundation.h> -#import <QTKit/QTKit.h> - -#include <QtCore/qstring.h> -#include <QtCore/qdebug.h> - -#include "qt7backend.h" -#include "qt7serviceplugin.h" -#include "qt7playerservice.h" - -#include <qmediaserviceprovider.h> - -QT_BEGIN_NAMESPACE - - -QT7ServicePlugin::QT7ServicePlugin() -{ - buildSupportedTypes(); -} - -QStringList QT7ServicePlugin::keys() const -{ - return QStringList() -#ifdef QMEDIA_QT7_PLAYER - << QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER) -#endif - ; -} - -QMediaService* QT7ServicePlugin::create(QString const& key) -{ -#ifdef QT_DEBUG_QT7 - qDebug() << "QT7ServicePlugin::create" << key; -#endif -#ifdef QMEDIA_QT7_PLAYER - if (key == QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER)) - return new QT7PlayerService; -#endif - qWarning() << "unsupported key:" << key; - - return 0; -} - -void QT7ServicePlugin::release(QMediaService *service) -{ - delete service; -} - -QMediaServiceProviderHint::Features QT7ServicePlugin::supportedFeatures( - const QByteArray &service) const -{ - if (service == Q_MEDIASERVICE_MEDIAPLAYER) - return QMediaServiceProviderHint::VideoSurface; - else - return QMediaServiceProviderHint::Features(); -} - -QtMultimedia::SupportEstimate QT7ServicePlugin::hasSupport(const QString &mimeType, const QStringList& codecs) const -{ - Q_UNUSED(codecs); - - if (m_supportedMimeTypes.contains(mimeType)) - return QtMultimedia::ProbablySupported; - - return QtMultimedia::MaybeSupported; -} - -QStringList QT7ServicePlugin::supportedMimeTypes() const -{ - return m_supportedMimeTypes; -} - -void QT7ServicePlugin::buildSupportedTypes() -{ - AutoReleasePool pool; - NSArray *utis = [QTMovie movieTypesWithOptions:QTIncludeCommonTypes]; - for (NSString *uti in utis) { - NSString* mimeType = (NSString*)UTTypeCopyPreferredTagWithClass((CFStringRef)uti, kUTTagClassMIMEType); - if (mimeType != 0) { - m_supportedMimeTypes.append(QString::fromUtf8([mimeType UTF8String])); - [mimeType release]; - } - } -} - -Q_EXPORT_PLUGIN2(qtmedia_qt7engine, QT7ServicePlugin); - -QT_END_NAMESPACE diff --git a/src/plugins/qt7/qt7videooutput.h b/src/plugins/qt7/qt7videooutput.h deleted file mode 100644 index 15b93c9..0000000 --- a/src/plugins/qt7/qt7videooutput.h +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT7VIDEOOUTPUTCONTROL_H -#define QT7VIDEOOUTPUTCONTROL_H - -#include <QtCore/qobject.h> -#include <QtCore/qsize.h> - -#include <qvideowindowcontrol.h> -#include <qvideowidgetcontrol.h> -#include <qvideorenderercontrol.h> -#include <qmediaplayer.h> - -#include <QtWidgets/qmacdefines_mac.h> - - -QT_BEGIN_NAMESPACE - -class QMediaPlaylist; -class QMediaPlaylistNavigator; -class QT7PlayerSession; -class QT7PlayerService; - - -class QT7VideoOutput { -public: - virtual ~QT7VideoOutput() {} - virtual void setMovie(void *movie) = 0; - virtual void updateNaturalSize(const QSize &newSize) = 0; -}; - -#define QT7VideoOutput_iid \ - "com.nokia.Qt.QT7VideoOutput/1.0" -Q_DECLARE_INTERFACE(QT7VideoOutput, QT7VideoOutput_iid) - -class QT7VideoWindowControl : public QVideoWindowControl, public QT7VideoOutput -{ -Q_OBJECT -Q_INTERFACES(QT7VideoOutput) -public: - virtual ~QT7VideoWindowControl() {} - -protected: - QT7VideoWindowControl(QObject *parent) - :QVideoWindowControl(parent) - {} -}; - -class QT7VideoRendererControl : public QVideoRendererControl, public QT7VideoOutput -{ -Q_OBJECT -Q_INTERFACES(QT7VideoOutput) -public: - virtual ~QT7VideoRendererControl() {} - -protected: - QT7VideoRendererControl(QObject *parent) - :QVideoRendererControl(parent) - {} -}; - -class QT7VideoWidgetControl : public QVideoWidgetControl, public QT7VideoOutput -{ -Q_OBJECT -Q_INTERFACES(QT7VideoOutput) -public: - virtual ~QT7VideoWidgetControl() {} - -protected: - QT7VideoWidgetControl(QObject *parent) - :QVideoWidgetControl(parent) - {} -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/qt7/qt7videooutput.mm b/src/plugins/qt7/qt7videooutput.mm deleted file mode 100644 index cf629a6..0000000 --- a/src/plugins/qt7/qt7videooutput.mm +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qt7playercontrol.h" -#include "qt7playersession.h" -#include <QtCore/qdebug.h> - -QT_USE_NAMESPACE - -/* -QT7VideoOutputControl::QT7VideoOutputControl(QObject *parent) - :QVideoOutputControl(parent), - m_session(0), - m_output(QVideoOutputControl::NoOutput) -{ -} - -QT7VideoOutputControl::~QT7VideoOutputControl() -{ -} - -void QT7VideoOutputControl::setSession(QT7PlayerSession *session) -{ - m_session = session; -} - -QList<QVideoOutputControl::Output> QT7VideoOutputControl::availableOutputs() const -{ - return m_outputs; -} - -void QT7VideoOutputControl::enableOutput(QVideoOutputControl::Output output) -{ - if (!m_outputs.contains(output)) - m_outputs.append(output); -} - -QVideoOutputControl::Output QT7VideoOutputControl::output() const -{ - return m_output; -} - -void QT7VideoOutputControl::setOutput(Output output) -{ - if (m_output != output) { - m_output = output; - emit videoOutputChanged(m_output); - } -} - -#include "moc_qt7videooutputcontrol.cpp" - -*/ diff --git a/src/plugins/simulator/camera/simulatorcamera.pri b/src/plugins/simulator/camera/simulatorcamera.pri deleted file mode 100644 index 867fc4b..0000000 --- a/src/plugins/simulator/camera/simulatorcamera.pri +++ /dev/null @@ -1,25 +0,0 @@ -INCLUDEPATH += $$PWD \ - $${SOURCE_DIR}/src/multimedia - -INCLUDEPATH += camera - -HEADERS += \ - $$PWD/simulatorcameraservice.h \ - $$PWD/simulatorcamerasession.h \ - $$PWD/simulatorcameracontrol.h \ - $$PWD/simulatorvideorenderercontrol.h \ - $$PWD/simulatorvideoinputdevicecontrol.h \ - $$PWD/simulatorcameraimagecapturecontrol.h \ - $$PWD/simulatorcameraexposurecontrol.h \ - $$PWD/simulatorcamerasettings.h - -SOURCES += \ - $$PWD/simulatorcameraservice.cpp \ - $$PWD/simulatorcamerasession.cpp \ - $$PWD/simulatorcameracontrol.cpp \ - $$PWD/simulatorvideorenderercontrol.cpp \ - $$PWD/simulatorvideoinputdevicecontrol.cpp \ - $$PWD/simulatorcameraimagecapturecontrol.cpp \ - $$PWD/simulatorcameraexposurecontrol.cpp \ - $$PWD/simulatorcamerasettings.cpp - diff --git a/src/plugins/simulator/camera/simulatorcameracontrol.cpp b/src/plugins/simulator/camera/simulatorcameracontrol.cpp deleted file mode 100644 index cf2db58..0000000 --- a/src/plugins/simulator/camera/simulatorcameracontrol.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "simulatorcameracontrol.h" - -#include <QtCore/qfile.h> - -SimulatorCameraControl::SimulatorCameraControl(SimulatorCameraSession *session) - :QCameraControl(session), - m_session(session), - mState(QCamera::UnloadedState), - mStatus(QCamera::UnloadedStatus) -{ -} - -SimulatorCameraControl::~SimulatorCameraControl() -{ -} - -QCamera::CaptureMode SimulatorCameraControl::captureMode() const -{ - return m_session->captureMode(); -} - -void SimulatorCameraControl::setCaptureMode(QCamera::CaptureMode mode) -{ - if (m_session->captureMode() != mode) { - m_session->setCaptureMode(mode); - emit captureModeChanged(mode); - } -} - -void SimulatorCameraControl::setState(QCamera::State state) -{ - if (mState == state) { - return; - } - - // Simulator only supports these status - Q_ASSERT(mStatus == QCamera::UnloadedStatus || mStatus == QCamera::LoadedStatus - || mStatus == QCamera::ActiveStatus); - - switch (state) { - case QCamera::UnloadedState: // To UnloadedState - Release resources - switch (mStatus) { - case QCamera::LoadedStatus: - // Unload - break; - case QCamera::ActiveStatus: - // Stop and Unload - emit stopCamera(); - break; - default: - // Unrecognized internal state (Status) - return; - } - mStatus = QCamera::UnloadedStatus; - emit statusChanged(mStatus); - break; - - case QCamera::LoadedState: // To LoadedState - Reserve resources OR Stop ViewFinder and Cancel Capture - switch (mStatus) { - case QCamera::UnloadedStatus: - // Load - mStatus = QCamera::LoadingStatus; - emit statusChanged(mStatus); - break; - case QCamera::ActiveStatus: - // Stop - emit stopCamera(); - break; - - default: - // Unregocnized internal state (Status) - return; - } - mStatus = QCamera::LoadedStatus; - emit statusChanged(mStatus); - break; - - case QCamera::ActiveState: // To ActiveState - (Reserve Resources and) Start ViewFinder - switch (mStatus) { - case QCamera::UnloadedStatus: - // Load and Start (setting state handles starting) - mStatus = QCamera::LoadingStatus; - emit statusChanged(mStatus); - mStatus = QCamera::LoadedStatus; - emit statusChanged(mStatus); - mStatus = QCamera::StartingStatus; - emit statusChanged(mStatus); - emit startCamera(); - break; - case QCamera::LoadedStatus: - // Start - mStatus = QCamera::StartingStatus; - emit statusChanged(mStatus); - emit startCamera(); - break; - default: - // Unregocnized internal state (Status) - return; - } - mStatus = QCamera::ActiveStatus; - emit statusChanged(mStatus); - break; - - default: - return; - } - - mState = state; - emit stateChanged(mState); -} - -QCamera::State SimulatorCameraControl::state() const -{ - return mState; -} - -bool SimulatorCameraControl::canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const -{ - Q_UNUSED(status); - - switch (changeType) { - case QCameraControl::CaptureMode: - case QCameraControl::Viewfinder: - return true; - default: - return false; - } -} - -bool SimulatorCameraControl::isCaptureModeSupported(QCamera::CaptureMode mode) const -{ - return mode == QCamera::CaptureStillImage; -} - -QCamera::Status SimulatorCameraControl::status() const -{ - return mStatus; -} diff --git a/src/plugins/simulator/camera/simulatorcameracontrol.h b/src/plugins/simulator/camera/simulatorcameracontrol.h deleted file mode 100644 index e2f2408..0000000 --- a/src/plugins/simulator/camera/simulatorcameracontrol.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef SIMULATORCAMERACONTROL_H -#define SIMULATORCAMERACONTROL_H - -#include <QHash> -#include <qcameracontrol.h> -#include "simulatorcamerasession.h" - -QT_USE_NAMESPACE -QT_USE_NAMESPACE - -class SimulatorCameraControl : public QCameraControl -{ - Q_OBJECT -public: - SimulatorCameraControl(SimulatorCameraSession *session ); - virtual ~SimulatorCameraControl(); - - bool isValid() const { return true; } - - QCamera::State state() const; - void setState(QCamera::State state); - - QCamera::Status status() const; - - QCamera::CaptureMode captureMode() const; - void setCaptureMode(QCamera::CaptureMode mode); - - bool isCaptureModeSupported(QCamera::CaptureMode mode) const; - - bool canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const; - -signals: - void startCamera(); - void stopCamera(); - -private: - void updateSupportedResolutions(const QString &device); - - SimulatorCameraSession *m_session; - QCamera::State mState; - QCamera::Status mStatus; - bool m_reloadPending; -}; - -#endif // CAMERACONTROL_H diff --git a/src/plugins/simulator/camera/simulatorcameraexposurecontrol.cpp b/src/plugins/simulator/camera/simulatorcameraexposurecontrol.cpp deleted file mode 100644 index 1ee820d..0000000 --- a/src/plugins/simulator/camera/simulatorcameraexposurecontrol.cpp +++ /dev/null @@ -1,502 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qstring.h> - -#include "simulatorcameraexposurecontrol.h" -#include "simulatorcamerasession.h" - -SimulatorCameraExposureControl::SimulatorCameraExposureControl(SimulatorCameraSession *session, QObject *parent) : - QCameraExposureControl(parent), - mExposureMode(QCameraExposure::ExposureAuto), - mMeteringMode(QCameraExposure::MeteringAverage), - mSession(session), - mSettings(0) -{ - mSettings = mSession->settings(); - - connect(mSettings, SIGNAL(apertureChanged()), this, SLOT(apertureChanged())); - connect(mSettings, SIGNAL(apertureRangeChanged()), this, SLOT(apertureRangeChanged())); - connect(mSettings, SIGNAL(shutterSpeedChanged()), this, SLOT(shutterSpeedChanged())); - connect(mSettings, SIGNAL(isoSensitivityChanged()), this, SLOT(isoSensitivityChanged())); -} - -SimulatorCameraExposureControl::~SimulatorCameraExposureControl() -{ -} - -void SimulatorCameraExposureControl::apertureChanged() -{ - emit exposureParameterChanged(QCameraExposureControl::Aperture); -} - -void SimulatorCameraExposureControl::apertureRangeChanged() -{ - emit exposureParameterRangeChanged(QCameraExposureControl::Aperture); -} - -void SimulatorCameraExposureControl::shutterSpeedChanged() -{ - emit exposureParameterChanged(QCameraExposureControl::ShutterSpeed); -} - -void SimulatorCameraExposureControl::isoSensitivityChanged() -{ - emit exposureParameterChanged(QCameraExposureControl::ISO); -} - -QCameraExposure::ExposureMode SimulatorCameraExposureControl::exposureMode() const -{ - return mExposureMode; -} - -void SimulatorCameraExposureControl::setExposureMode(QCameraExposure::ExposureMode mode) -{ - if (isExposureModeSupported(mode)) - mExposureMode = mode; -} - -bool SimulatorCameraExposureControl::isExposureModeSupported(QCameraExposure::ExposureMode mode) const -{ - switch (mode) { - case QCameraExposure::ExposureAuto: - case QCameraExposure::ExposureManual: - return true; - default: - return false; - } - - return false; -} - -QCameraExposure::MeteringMode SimulatorCameraExposureControl::meteringMode() const -{ - return mMeteringMode; -} - -void SimulatorCameraExposureControl::setMeteringMode(QCameraExposure::MeteringMode mode) -{ - if (isMeteringModeSupported(mode)) - mMeteringMode = mode; -} - -bool SimulatorCameraExposureControl::isMeteringModeSupported(QCameraExposure::MeteringMode mode) const -{ - switch (mode) { - case QCameraExposure::MeteringAverage: - case QCameraExposure::MeteringSpot: - case QCameraExposure::MeteringMatrix: - return true; - default: - return false; - } - return false; -} - -bool SimulatorCameraExposureControl::isParameterSupported(ExposureParameter parameter) const -{ - switch (parameter) { - case QCameraExposureControl::ISO: - case QCameraExposureControl::Aperture: - case QCameraExposureControl::ShutterSpeed: - case QCameraExposureControl::ExposureCompensation: - return true; - case QCameraExposureControl::FlashPower: - case QCameraExposureControl::FlashCompensation: - return false; - - default: - return false; - } - - return false; -} - -QVariant SimulatorCameraExposureControl::exposureParameter(ExposureParameter parameter) const -{ - switch (parameter) { - case QCameraExposureControl::ISO: - return QVariant(isoSensitivity()); - case QCameraExposureControl::Aperture: - return QVariant(aperture()); - case QCameraExposureControl::ShutterSpeed: - return QVariant(shutterSpeed()); - case QCameraExposureControl::ExposureCompensation: - return QVariant(exposureCompensation()); - case QCameraExposureControl::FlashPower: - case QCameraExposureControl::FlashCompensation: - // Not supported - return QVariant(); - - default: - // Not supported - return QVariant(); - } -} - -QCameraExposureControl::ParameterFlags SimulatorCameraExposureControl::exposureParameterFlags(ExposureParameter parameter) const -{ - QCameraExposureControl::ParameterFlags flags; - - /* - * ISO, Aperture, ShutterSpeed: - * - Automatic/Manual - * - Read/Write - * - Discrete range - * - * ExposureCompensation: - * - Automatic/Manual - * - Read/Write - * - Continuous range - * - * FlashPower, FlashCompensation: - * - Not supported - */ - switch (parameter) { - case QCameraExposureControl::ISO: - case QCameraExposureControl::Aperture: - case QCameraExposureControl::ShutterSpeed: - flags |= QCameraExposureControl::AutomaticValue; - break; - case QCameraExposureControl::ExposureCompensation: - flags |= QCameraExposureControl::AutomaticValue; - flags |= QCameraExposureControl::ContinuousRange; - break; - case QCameraExposureControl::FlashPower: - case QCameraExposureControl::FlashCompensation: - // Do nothing - no flags - break; - - default: - // Do nothing - no flags - break; - } - - return flags; -} - -QVariantList SimulatorCameraExposureControl::supportedParameterRange(ExposureParameter parameter) const -{ - QVariantList valueList; - switch (parameter) { - case QCameraExposureControl::ISO: { - QList<int> exposureValues = mSettings->supportedIsoSensitivities(); - for (int i = 0; i < exposureValues.count(); ++i) { - valueList.append(QVariant(exposureValues[i])); - } - break; - } - case QCameraExposureControl::Aperture: { - QList<qreal> apertureValues = mSettings->supportedApertures(); - for (int i = 0; i < apertureValues.count(); ++i) { - valueList.append(QVariant(apertureValues[i])); - } - break; - } - case QCameraExposureControl::ShutterSpeed: { - QList<qreal> shutterSpeedValues = mSettings->supportedShutterSpeeds(); - for (int i = 0; i < shutterSpeedValues.count(); ++i) { - valueList.append(QVariant(shutterSpeedValues[i])); - } - break; - } - case QCameraExposureControl::ExposureCompensation: { - QList<qreal> evValues = mSettings->supportedExposureCompensationValues(); - for (int i = 0; i < evValues.count(); ++i) { - valueList.append(QVariant(evValues[i])); - } - break; - } - case QCameraExposureControl::FlashPower: - case QCameraExposureControl::FlashCompensation: - // Not supported - break; - - default: - // Not supported - return QVariantList(); - } - - return valueList; -} - -bool SimulatorCameraExposureControl::setExposureParameter(ExposureParameter parameter, const QVariant& value) -{ - bool useDefaultValue = false; - - if (value.isNull()) - useDefaultValue = true; - - switch (parameter) { - case QCameraExposureControl::ISO: - if (useDefaultValue) { - setAutoIsoSensitivity(); - return false; - } - else - return setManualIsoSensitivity(value.toInt()); - - case QCameraExposureControl::Aperture: - if (useDefaultValue) { - setAutoAperture(); - return false; - } - else - return setManualAperture(value.toReal()); - - case QCameraExposureControl::ShutterSpeed: - if (useDefaultValue) { - setAutoShutterSpeed(); - return false; - } - else - return setManualShutterSpeed(value.toReal()); - - case QCameraExposureControl::ExposureCompensation: - if (useDefaultValue) { - setAutoExposureCompensation(); - return false; - } - else - return setManualExposureCompensation(value.toReal()); - - case QCameraExposureControl::FlashPower: - return false; - case QCameraExposureControl::FlashCompensation: - return false; - - default: - // Not supported - return false; - } -} - -QString SimulatorCameraExposureControl::extendedParameterName(ExposureParameter parameter) -{ - switch (parameter) { - case QCameraExposureControl::ISO: - return QString("ISO Sensitivity"); - case QCameraExposureControl::Aperture: - return QString("Aperture"); - case QCameraExposureControl::ShutterSpeed: - return QString("Shutter Speed"); - case QCameraExposureControl::ExposureCompensation: - return QString("Exposure Compensation"); - case QCameraExposureControl::FlashPower: - return QString("Flash Power"); - case QCameraExposureControl::FlashCompensation: - return QString("Flash Compensation"); - - default: - return QString(); - } -} - -int SimulatorCameraExposureControl::isoSensitivity() const -{ - return mSettings->isoSensitivity(); -} - -bool SimulatorCameraExposureControl::isIsoSensitivitySupported(const int iso) const -{ - return mSettings->supportedIsoSensitivities().contains(iso); -} - -bool SimulatorCameraExposureControl::setManualIsoSensitivity(int iso) -{ - if (isIsoSensitivitySupported(iso)) { - mSettings->setManualIsoSensitivity(iso); - return true; - } else { - QList<int> supportedIsoValues = mSettings->supportedIsoSensitivities(); - int minIso = supportedIsoValues.first(); - int maxIso = supportedIsoValues.last(); - - if (iso < minIso) { // Smaller than minimum - iso = minIso; - } else if (iso > maxIso) { // Bigger than maximum - iso = maxIso; - } else { // Find closest - int indexOfClosest = 0; - int smallestDiff = 10000000; // Sensible max diff - for(int i = 0; i < supportedIsoValues.count(); ++i) { - int currentDiff = qAbs(iso - supportedIsoValues[i]); - if(currentDiff < smallestDiff) { - smallestDiff = currentDiff; - indexOfClosest = i; - } - } - iso = supportedIsoValues[indexOfClosest]; - } - mSettings->setManualIsoSensitivity(iso); - } - - return false; -} - -void SimulatorCameraExposureControl::setAutoIsoSensitivity() -{ - mSettings->setAutoIsoSensitivity(); -} - - -qreal SimulatorCameraExposureControl::aperture() const -{ - return mSettings->aperture(); -} - -bool SimulatorCameraExposureControl::isApertureSupported(const qreal aperture) const -{ - return mSettings->supportedApertures().contains(aperture); -} - -bool SimulatorCameraExposureControl::setManualAperture(qreal aperture) -{ - if (isApertureSupported(aperture)) { - mSettings->setManualAperture(aperture); - return true; - } else { - QList<qreal> supportedApertureValues = mSettings->supportedApertures(); - qreal minAperture = supportedApertureValues.first(); - qreal maxAperture = supportedApertureValues.last(); - - if (aperture < minAperture) { // Smaller than minimum - aperture = minAperture; - } else if (aperture > maxAperture) { // Bigger than maximum - aperture = maxAperture; - } else { // Find closest - int indexOfClosest = 0; - qreal smallestDiff = 100000000; // Sensible max diff - for(int i = 0; i < supportedApertureValues.count(); ++i) { - qreal currentDiff = qAbs(aperture - supportedApertureValues[i]); - if(currentDiff < smallestDiff) { - smallestDiff = currentDiff; - indexOfClosest = i; - } - } - aperture = supportedApertureValues[indexOfClosest]; - } - mSettings->setManualAperture(aperture); - } - - return false; -} - -void SimulatorCameraExposureControl::setAutoAperture() -{ - mSettings->setAutoAperture(); -} - -qreal SimulatorCameraExposureControl::shutterSpeed() const -{ - return mSettings->shutterSpeed(); -} - -bool SimulatorCameraExposureControl::isShutterSpeedSupported(const qreal seconds) const -{ - return mSettings->supportedShutterSpeeds().contains(seconds); -} - -bool SimulatorCameraExposureControl::setManualShutterSpeed(qreal seconds) -{ - if (isShutterSpeedSupported(seconds)) { - mSettings->setManualShutterSpeed(seconds); - return true; - } else { - QList<qreal> supportedShutterSpeeds = mSettings->supportedShutterSpeeds(); - - qreal minShutterSpeed = supportedShutterSpeeds.first(); - qreal maxShutterSpeed = supportedShutterSpeeds.last(); - - if (seconds < minShutterSpeed) { // Smaller than minimum - seconds = minShutterSpeed; - } else if (seconds > maxShutterSpeed) { // Bigger than maximum - seconds = maxShutterSpeed; - } else { // Find closest - int indexOfClosest = 0; - qreal smallestDiff = 100000000; // Sensible max diff - for(int i = 0; i < supportedShutterSpeeds.count(); ++i) { - qreal currentDiff = qAbs(seconds - supportedShutterSpeeds[i]); - if(currentDiff < smallestDiff) { - smallestDiff = currentDiff; - indexOfClosest = i; - } - } - seconds = supportedShutterSpeeds[indexOfClosest]; - } - mSettings->setManualShutterSpeed(seconds); - } - - return false; -} - -void SimulatorCameraExposureControl::setAutoShutterSpeed() -{ - mSettings->setAutoShutterSpeed(); -} - -qreal SimulatorCameraExposureControl::exposureCompensation() const -{ - return mSettings->exposureCompensation(); -} - -bool SimulatorCameraExposureControl::isExposureCompensationSupported(const qreal ev) const -{ - QList<qreal> supportedValues = mSettings->supportedExposureCompensationValues(); - return (ev >= supportedValues.first() && ev <= supportedValues.last()); -} - -bool SimulatorCameraExposureControl::setManualExposureCompensation(qreal ev) -{ - if (isExposureCompensationSupported(ev)) { - mSettings->setExposureCompensation(ev); - return true; - } - - return false; -} - -void SimulatorCameraExposureControl::setAutoExposureCompensation() -{ - mSettings->setAutoExposureCompensation(); -} - -// End of file diff --git a/src/plugins/simulator/camera/simulatorcameraexposurecontrol.h b/src/plugins/simulator/camera/simulatorcameraexposurecontrol.h deleted file mode 100644 index 5e00a6d..0000000 --- a/src/plugins/simulator/camera/simulatorcameraexposurecontrol.h +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SIMULATORCAMERAEXPOSURECONTROL_H -#define SIMULATORCAMERAEXPOSURECONTROL_H - -#include <qcameraexposurecontrol.h> - -#include "simulatorcamerasettings.h" - -QT_BEGIN_NAMESPACE - -class SimulatorCameraSession; - -/* - * Control for exposure related camera operation. - */ -class SimulatorCameraExposureControl : public QCameraExposureControl -{ - Q_OBJECT - -public: - - SimulatorCameraExposureControl(SimulatorCameraSession *session, QObject *parent = 0); - ~SimulatorCameraExposureControl(); - - // QCameraExposureControl - // Exposure Mode - QCameraExposure::ExposureMode exposureMode() const; - void setExposureMode(QCameraExposure::ExposureMode mode); - bool isExposureModeSupported(QCameraExposure::ExposureMode mode) const; - - // Metering Mode - QCameraExposure::MeteringMode meteringMode() const; - void setMeteringMode(QCameraExposure::MeteringMode mode); - bool isMeteringModeSupported(QCameraExposure::MeteringMode mode) const; - - // Exposure Parameter - bool isParameterSupported(ExposureParameter parameter) const; - QVariant exposureParameter(ExposureParameter parameter) const; - QCameraExposureControl::ParameterFlags exposureParameterFlags(ExposureParameter parameter) const; - QVariantList supportedParameterRange(ExposureParameter parameter) const; - bool setExposureParameter(ExposureParameter parameter, const QVariant& value); - - QString extendedParameterName(ExposureParameter parameter); - -private Q_SLOTS: // Internal Slots - void apertureChanged(); - void apertureRangeChanged(); - void shutterSpeedChanged(); - void isoSensitivityChanged(); - -private: // Internal - Implementing ExposureParameter - // ISO Sensitivity - int isoSensitivity() const; - bool setManualIsoSensitivity(int iso); - void setAutoIsoSensitivity(); - bool isIsoSensitivitySupported(const int iso) const; - - // Aperture - qreal aperture() const; - bool setManualAperture(qreal aperture); - void setAutoAperture(); - bool isApertureSupported(const qreal aperture) const; - - // Shutter Speed - qreal shutterSpeed() const; - bool setManualShutterSpeed(qreal seconds); - void setAutoShutterSpeed(); - bool isShutterSpeedSupported(const qreal seconds) const; - - // Exposure Compensation - qreal exposureCompensation() const; - bool setManualExposureCompensation(qreal ev); - void setAutoExposureCompensation(); - bool isExposureCompensationSupported(const qreal ev) const; - -private: // Data - QCameraExposure::ExposureMode mExposureMode; - QCameraExposure::MeteringMode mMeteringMode; - SimulatorCameraSession *mSession; - SimulatorCameraSettings *mSettings; -}; - -QT_END_NAMESPACE - -#endif // SIMULATORCAMERAEXPOSURECONTROL_H diff --git a/src/plugins/simulator/camera/simulatorcameraimagecapturecontrol.cpp b/src/plugins/simulator/camera/simulatorcameraimagecapturecontrol.cpp deleted file mode 100644 index 2fe5070..0000000 --- a/src/plugins/simulator/camera/simulatorcameraimagecapturecontrol.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qstring.h> - -#include "simulatorcameraimagecapturecontrol.h" -#include "simulatorcameraservice.h" -#include "simulatorcamerasession.h" -#include "simulatorcameracontrol.h" - -SimulatorCameraImageCaptureControl::SimulatorCameraImageCaptureControl(SimulatorCameraSession *session, SimulatorCameraService *service) : - QCameraImageCaptureControl(service), - mReadyForCapture(true), - m_driveMode(QCameraImageCapture::SingleImageCapture) // Default DriveMode -{ - m_session = session; - - m_service = service; - m_cameraControl = qobject_cast<SimulatorCameraControl *>(m_service->requestControl(QCameraControl_iid)); - - // Chain these signals from session class - connect(m_session, SIGNAL(imageCaptured(const int, QImage)), - this, SIGNAL(imageCaptured(const int, QImage))); - connect(m_session, SIGNAL(imageSaved(const int, const QString&)), - this, SIGNAL(imageSaved(const int, const QString&))); - connect(m_session, SIGNAL(imageExposed(int)), - this, SIGNAL(imageExposed(int))); - connect(m_session, SIGNAL(captureError(int, int, const QString&)), - this, SIGNAL(error(int, int, const QString&))); -} - -SimulatorCameraImageCaptureControl::~SimulatorCameraImageCaptureControl() -{ -} - -bool SimulatorCameraImageCaptureControl::isReadyForCapture() const -{ - if (m_cameraControl && m_cameraControl->captureMode() != QCamera::CaptureStillImage) { - return false; - } - - return mReadyForCapture; -} - -QCameraImageCapture::DriveMode SimulatorCameraImageCaptureControl::driveMode() const -{ - return m_driveMode; -} - -void SimulatorCameraImageCaptureControl::setDriveMode(QCameraImageCapture::DriveMode mode) -{ - if (mode != QCameraImageCapture::SingleImageCapture) { - emit error(0, QCamera::NotSupportedFeatureError, tr("DriveMode not supported.")); - return; - } - - m_driveMode = mode; -} - -int SimulatorCameraImageCaptureControl::capture(const QString &fileName) -{ - if (m_cameraControl && m_cameraControl->captureMode() != QCamera::CaptureStillImage) { - emit error(0, QCameraImageCapture::NotReadyError, tr("Incorrect CaptureMode.")); - return 0; - } - updateReadyForCapture(false); - int imageId = m_session->captureImage(fileName); - updateReadyForCapture(true); - return imageId; -} - -void SimulatorCameraImageCaptureControl::cancelCapture() -{ -} - -void SimulatorCameraImageCaptureControl::updateReadyForCapture(bool ready) -{ - mReadyForCapture = ready; - emit readyForCaptureChanged(mReadyForCapture); -} - -// End of file diff --git a/src/plugins/simulator/camera/simulatorcameraimagecapturecontrol.h b/src/plugins/simulator/camera/simulatorcameraimagecapturecontrol.h deleted file mode 100644 index f300c5d..0000000 --- a/src/plugins/simulator/camera/simulatorcameraimagecapturecontrol.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SIMULATORCAMERAIMAGECAPTURECONTROL_H -#define SIMULATORCAMERAIMAGECAPTURECONTROL_H - -#include "qcameraimagecapturecontrol.h" - -QT_USE_NAMESPACE - -class SimulatorCameraService; -class SimulatorCameraSession; -class SimulatorCameraControl; - -/* - * Control for image capture operations. - */ -class SimulatorCameraImageCaptureControl : public QCameraImageCaptureControl -{ - Q_OBJECT - -public: // Contructors & Destrcutor - - SimulatorCameraImageCaptureControl(SimulatorCameraSession *session, SimulatorCameraService *service); - ~SimulatorCameraImageCaptureControl(); - -public: // QCameraImageCaptureControl - - bool isReadyForCapture() const; - - // Drive Mode - QCameraImageCapture::DriveMode driveMode() const; - void setDriveMode(QCameraImageCapture::DriveMode mode); - - // Capture - int capture(const QString &fileName); - void cancelCapture(); - -private: - void updateReadyForCapture(bool ready); - - bool mReadyForCapture; - SimulatorCameraSession *m_session; - SimulatorCameraService *m_service; - SimulatorCameraControl *m_cameraControl; - QCameraImageCapture::DriveMode m_driveMode; -}; - -#endif // SIMULATORCAMERAIMAGECAPTURECONTROL_H diff --git a/src/plugins/simulator/camera/simulatorcameraservice.cpp b/src/plugins/simulator/camera/simulatorcameraservice.cpp deleted file mode 100644 index 5348fa5..0000000 --- a/src/plugins/simulator/camera/simulatorcameraservice.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "simulatorcameraservice.h" -#include "simulatorcamerasession.h" -#include "simulatorcameracontrol.h" -#include "simulatorcameraimagecapturecontrol.h" -#include "simulatorcameraexposurecontrol.h" - -#include "simulatorvideoinputdevicecontrol.h" -#include "simulatorvideorenderercontrol.h" -#include "../qsimulatormultimediaconnection_p.h" - -#include <qmediaserviceprovider.h> -#include <QtCore/QDebug> - -QTM_USE_NAMESPACE; -using namespace Simulator; - -SimulatorCameraService::SimulatorCameraService(const QString &service, MultimediaConnection *multimediaConnection, - QObject *parent): - QMediaService(parent) -{ - Q_UNUSED(service) - mCaptureSession = new SimulatorCameraSession(this); - mCameraControl = new SimulatorCameraControl(mCaptureSession); - mVideoInputDeviceControl = new QSimulatorVideoInputDeviceControl(mCaptureSession); - mVideoInputDeviceControl->updateDeviceList(get_qtCameraData()); - mVideoRendererControl = new SimulatorVideoRendererControl(mCaptureSession, this); - mImageCaptureControl = new SimulatorCameraImageCaptureControl(mCaptureSession, this); - mExposureControl = new SimulatorCameraExposureControl(mCaptureSession, this); - - connect(multimediaConnection, SIGNAL(cameraDataChanged(QtMobility::QCameraData)), - SLOT(updateCameraData(QtMobility::QCameraData))); - connect(multimediaConnection, SIGNAL(cameraAdded(QString,QtMobility::QCameraData::QCameraDetails)), - mVideoInputDeviceControl, SLOT(addDevice(QString,QtMobility::QCameraData::QCameraDetails))); - connect(multimediaConnection, SIGNAL(cameraRemoved(QString)), - mVideoInputDeviceControl, SLOT(removeDevice(QString))); - connect(multimediaConnection, SIGNAL(cameraChanged(QString,QtMobility::QCameraData::QCameraDetails)), - mVideoInputDeviceControl, SLOT(changeDevice(QString,QtMobility::QCameraData::QCameraDetails))); - connect(multimediaConnection, SIGNAL(cameraChanged(QString,QtMobility::QCameraData::QCameraDetails)), - SLOT(changeCamera(QString,QtMobility::QCameraData::QCameraDetails))); - connect(mCameraControl, SIGNAL(startCamera()), - mVideoRendererControl, SLOT(showImage())); - connect(mCameraControl, SIGNAL(stopCamera()), - mVideoRendererControl, SLOT(stop())); - connect(mVideoInputDeviceControl, SIGNAL(selectedDeviceChanged(QString)), - SLOT(updateCameraPicture(QString))); - connect(mCaptureSession->settings(), SIGNAL(isoSensitivityChanged()), mVideoRendererControl, SLOT(showImage())); - connect(mCaptureSession->settings(), SIGNAL(apertureChanged()), mVideoRendererControl, SLOT(showImage())); - connect(mCaptureSession->settings(), SIGNAL(shutterSpeedChanged()), mVideoRendererControl, SLOT(showImage())); - connect(mCaptureSession->settings(), SIGNAL(exposureCompensationChanged()), mVideoRendererControl, SLOT(showImage())); - mCaptureSession->setImage(mVideoRendererControl->image()); - mVideoInputDeviceControl->setSelectedDevice(mVideoInputDeviceControl->defaultDevice()); -} - -SimulatorCameraService::~SimulatorCameraService() -{ -} - -QMediaControl *SimulatorCameraService::requestControl(const char *name) -{ - if (!mCaptureSession) - return 0; - - if (qstrcmp(name,QCameraControl_iid) == 0) - return mCameraControl; - - if (qstrcmp(name,QVideoDeviceControl_iid) == 0) - return mVideoInputDeviceControl; - - if (qstrcmp(name, QVideoRendererControl_iid) == 0) - return mVideoRendererControl; - - if (qstrcmp(name, QCameraImageCaptureControl_iid) == 0) - return mImageCaptureControl; - - if (qstrcmp(name, QCameraExposureControl_iid) == 0) - return mExposureControl; - - return 0; -} - -void SimulatorCameraService::releaseControl(QMediaControl *control) -{ - Q_UNUSED(control) -} - -void SimulatorCameraService::updateCameraData(const QtMobility::QCameraData &data) -{ - mVideoInputDeviceControl->updateDeviceList(data); - QString currentDevice = mVideoInputDeviceControl->deviceName(mVideoInputDeviceControl->selectedDevice()); - if (!data.cameras.contains(currentDevice)) - return; - - updateCurrentDeviceImage(data.cameras.value(currentDevice).imagePath); -} - -void SimulatorCameraService::changeCamera(const QString &name, const QtMobility::QCameraData::QCameraDetails &details) -{ - QString currentDevice = mVideoInputDeviceControl->deviceName(mVideoInputDeviceControl->selectedDevice()); - if (currentDevice != name) - return; - - updateCurrentDeviceImage(details.imagePath); -} - -void SimulatorCameraService::updateCameraPicture(const QString &name) -{ - QtMobility::QCameraData data = QtMobility::get_qtCameraData(); - if (!data.cameras.contains(name)) - return; - - updateCurrentDeviceImage(data.cameras.value(name).imagePath); -} - -void SimulatorCameraService::updateCurrentDeviceImage(const QString &imagePath) -{ - mVideoRendererControl->setImagePath(imagePath); - mCaptureSession->setImage(mVideoRendererControl->image()); -} - -#include "moc_simulatorcameraservice.cpp" diff --git a/src/plugins/simulator/camera/simulatorcameraservice.h b/src/plugins/simulator/camera/simulatorcameraservice.h deleted file mode 100644 index d2ad037..0000000 --- a/src/plugins/simulator/camera/simulatorcameraservice.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SIMULATORCAMERACAPTURESERVICE_H -#define SIMULATORCAMERACAPTURESERVICE_H - -#include <qmediaservice.h> - -#include "../qsimulatormultimediaconnection_p.h" - -QTM_BEGIN_NAMESPACE -namespace Simulator { -class MultimediaConnection; -} -QTM_END_NAMESPACE -class SimulatorCameraSession; -class SimulatorCameraControl; -class SimulatorCameraImageCaptureControl; -class SimulatorCameraExposureControl; -class SimulatorVideoRendererControl; -class QSimulatorVideoInputDeviceControl; - -class SimulatorCameraService : public QMediaService -{ - Q_OBJECT - -public: - SimulatorCameraService(const QString &service, QTM_PREPEND_NAMESPACE(Simulator::MultimediaConnection) *cameraConnection, - QObject *parent = 0); - virtual ~SimulatorCameraService(); - - QMediaControl *requestControl(const char *name); - void releaseControl(QMediaControl *); - -private slots: - void updateCameraData(const QtMobility::QCameraData &data); - void changeCamera(const QString &name, const QtMobility::QCameraData::QCameraDetails &details); - void updateCameraPicture(const QString &name); - -private: - void updateCurrentDeviceImage(const QString &imagePath); - SimulatorCameraSession *mCaptureSession; - SimulatorCameraControl *mCameraControl; - SimulatorCameraImageCaptureControl *mImageCaptureControl; - SimulatorCameraExposureControl *mExposureControl; - - QSimulatorVideoInputDeviceControl *mVideoInputDeviceControl; - - QMediaControl *mVideoOutput; - - SimulatorVideoRendererControl *mVideoRendererControl; -}; - -#endif // CAMERACAPTURESERVICE_H diff --git a/src/plugins/simulator/camera/simulatorcamerasession.cpp b/src/plugins/simulator/camera/simulatorcamerasession.cpp deleted file mode 100644 index d40582b..0000000 --- a/src/plugins/simulator/camera/simulatorcamerasession.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "simulatorcamerasession.h" -#include "simulatorcamerasettings.h" -#include "../qsimulatormultimediaconnection_p.h" -#include <qmediarecorder.h> -#include <qcameraimagecapture.h> - -#include <QtCore/qdebug.h> -#include <QCoreApplication> -#include <QtCore/qmetaobject.h> - -#include <QtGui/qimage.h> - -//#define CAMERA_DEBUG 1 - -SimulatorCameraSession::SimulatorCameraSession(QObject *parent) - :QObject(parent), - mViewfinder(0), - mImage(0), - mRequestId(0) -{ - mSettings = new SimulatorCameraSettings(this); -} - -SimulatorCameraSession::~SimulatorCameraSession() -{ -} - -int SimulatorCameraSession::captureImage(const QString &fileName) -{ - QTM_USE_NAMESPACE; - ++mRequestId; - emit imageExposed(mRequestId); - - QString actualFileName = fileName; - if (actualFileName.isEmpty()) { - actualFileName = generateFileName("img_", defaultDir(QCamera::CaptureStillImage), "jpg"); - } - - emit imageCaptured(mRequestId, *mImage); - - if (!mImage->save(actualFileName)) { - emit captureError(mRequestId, QCameraImageCapture::ResourceError, "Could not save file"); - return mRequestId; - } - emit imageSaved(mRequestId, actualFileName); - return mRequestId; -} - -void SimulatorCameraSession::setCaptureMode(QCamera::CaptureMode mode) -{ - mCaptureMode = mode; -} - -QDir SimulatorCameraSession::defaultDir(QCamera::CaptureMode) const -{ - const QString temp = QDir::tempPath(); - if (QFileInfo(temp).isWritable()) - return QDir(temp); - - return QDir(); -} - -QString SimulatorCameraSession::generateFileName(const QString &prefix, const QDir &dir, const QString &ext) const -{ - int lastClip = 0; - foreach(QString fileName, dir.entryList(QStringList() << QString("%1*.%2").arg(prefix).arg(ext))) { - int imgNumber = fileName.mid(prefix.length(), fileName.size()-prefix.length()-ext.length()-1).toInt(); - lastClip = qMax(lastClip, imgNumber); - } - - QString name = QString("%1%2.%3").arg(prefix) - .arg(lastClip+1, - 4, //fieldWidth - 10, - QLatin1Char('0')) - .arg(ext); - - return dir.absoluteFilePath(name); -} - -void SimulatorCameraSession::setViewfinder(QObject *viewfinder) -{ - if (mViewfinder != viewfinder) { - mViewfinder = viewfinder; - emit viewfinderChanged(); - } -} - -QCamera::CaptureMode SimulatorCameraSession::captureMode() -{ - return mCaptureMode; -} - -void SimulatorCameraSession::setImage(const QImage *image) -{ - mImage = image; -} - -QObject *SimulatorCameraSession::viewfinder() const -{ - return mViewfinder; -} - -SimulatorCameraSettings *SimulatorCameraSession::settings() const -{ - return mSettings; -} diff --git a/src/plugins/simulator/camera/simulatorcamerasession.h b/src/plugins/simulator/camera/simulatorcamerasession.h deleted file mode 100644 index d081d0c..0000000 --- a/src/plugins/simulator/camera/simulatorcamerasession.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SIMULATORCAMERACAPTURESESSION_H -#define SIMULATORCAMERACAPTURESESSION_H - -#include <qmediarecordercontrol.h> - -#include <QtCore/qurl.h> -#include <QtCore/qdir.h> - -#include "qcamera.h" - -class SimulatorCameraSettings; - -class SimulatorCameraSession : public QObject -{ - Q_OBJECT -public: - SimulatorCameraSession(QObject *parent); - ~SimulatorCameraSession(); - - QCamera::CaptureMode captureMode(); - void setCaptureMode(QCamera::CaptureMode mode); - - QDir defaultDir(QCamera::CaptureMode mode) const; - QString generateFileName(const QString &prefix, const QDir &dir, const QString &ext) const; - - void setImage(const QImage *image); - QObject *viewfinder() const; - void setViewfinder(QObject *viewfinder); - - int captureImage(const QString &fileName); - - SimulatorCameraSettings *settings() const; - -signals: - void stateChanged(QCamera::State state); - void captureError(int id, int error, const QString &errorString); - void error(int error, const QString &errorString); - void imageExposed(int requestId); - void imageCaptured(int requestId, const QImage &img); - void imageSaved(int requestId, const QString &fileName); - void viewfinderChanged(); - -private: - QCamera::CaptureMode mCaptureMode; - - QObject *mViewfinder; - const QImage *mImage; - - SimulatorCameraSettings *mSettings; - -public: - int mRequestId; -}; - -#endif // SIMULATORCAMERACAPTURESESSION_H diff --git a/src/plugins/simulator/camera/simulatorcamerasettings.cpp b/src/plugins/simulator/camera/simulatorcamerasettings.cpp deleted file mode 100644 index 592aa84..0000000 --- a/src/plugins/simulator/camera/simulatorcamerasettings.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "simulatorcamerasettings.h" - -SimulatorCameraSettings::SimulatorCameraSettings(QObject *parent) - : QObject(parent) - , mIsoSensitivity(400) - , mAperture(4) - , mShutterSpeed(0.008) - , mExposureCompensation(0) -{ - mSupportedIsoSensitivities << 50 << 100 << 200 << 400 << 800; - mSupportedApertures << 1.8 << 2.8 << 4 << 5.6 << 8; - mSupportedShutterSpeeds << 0.002 << 0.004 << 0.008 << 1./60 << 1./30; - mSupportedExposureCompensations << -2 << 2; -} - -SimulatorCameraSettings::~SimulatorCameraSettings() -{ -} - -int SimulatorCameraSettings::isoSensitivity() const -{ - return mIsoSensitivity; -} - -QList<int> SimulatorCameraSettings::supportedIsoSensitivities() const -{ - return mSupportedIsoSensitivities; -} - -void SimulatorCameraSettings::setManualIsoSensitivity(int iso) -{ - if (iso != mIsoSensitivity && supportedIsoSensitivities().contains(iso)) { - mIsoSensitivity = iso; - emit isoSensitivityChanged(); - } -} - -void SimulatorCameraSettings::setAutoIsoSensitivity() -{ - setManualIsoSensitivity(defaultIsoSensitivity()); -} - -qreal SimulatorCameraSettings::aperture() const -{ - return mAperture; -} - -QList<qreal> SimulatorCameraSettings::supportedApertures() const -{ - return mSupportedApertures; -} - -void SimulatorCameraSettings::setManualAperture(qreal aperture) -{ - if (aperture != mAperture && supportedApertures().contains(aperture)) { - mAperture = aperture; - emit apertureChanged(); - } -} - -void SimulatorCameraSettings::setAutoAperture() -{ - setManualAperture(defaultAperture()); -} - -qreal SimulatorCameraSettings::shutterSpeed() const -{ - return mShutterSpeed; -} - -QList<qreal> SimulatorCameraSettings::supportedShutterSpeeds() const -{ - return mSupportedShutterSpeeds; -} - -void SimulatorCameraSettings::setManualShutterSpeed(qreal speed) -{ - if (speed != mShutterSpeed && supportedShutterSpeeds().contains(speed)) { - mShutterSpeed = speed; - emit shutterSpeedChanged(); - } -} - -void SimulatorCameraSettings::setAutoShutterSpeed() -{ - setManualShutterSpeed(defaultShutterSpeed()); -} - -void SimulatorCameraSettings::setExposureCompensation(qreal ev) -{ - if (ev != mExposureCompensation && ev >= mSupportedExposureCompensations.first() - && ev <= mSupportedExposureCompensations.last()) { - mExposureCompensation = ev; - emit exposureCompensationChanged(); - } -} - -qreal SimulatorCameraSettings::exposureCompensation() const -{ - return mExposureCompensation; -} - -QList<qreal> SimulatorCameraSettings::supportedExposureCompensationValues() const -{ - return mSupportedExposureCompensations; -} - -void SimulatorCameraSettings::setAutoExposureCompensation() -{ - setExposureCompensation(defaultExposureCompensation()); -} - -int SimulatorCameraSettings::defaultIsoSensitivity() const -{ - return 400; -} - -qreal SimulatorCameraSettings::defaultAperture() const -{ - return 4; -} - -qreal SimulatorCameraSettings::defaultShutterSpeed() const -{ - return 0.008; -} - -qreal SimulatorCameraSettings::defaultExposureCompensation() const -{ - return 0; -} - -// End of file diff --git a/src/plugins/simulator/camera/simulatorcamerasettings.h b/src/plugins/simulator/camera/simulatorcamerasettings.h deleted file mode 100644 index 30aa44e..0000000 --- a/src/plugins/simulator/camera/simulatorcamerasettings.h +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SIMULATORCAMERASETTINGS_H -#define SIMULATORCAMERASETTINGS_H - -#include "qcamera.h" - -QT_BEGIN_NAMESPACE - -class SimulatorCameraSettings : public QObject -{ - Q_OBJECT - -public: - SimulatorCameraSettings(QObject *parent); - ~SimulatorCameraSettings(); - - // ISO Sensitivity - int isoSensitivity() const; - int defaultIsoSensitivity() const; - void setManualIsoSensitivity(int iso); - void setAutoIsoSensitivity(); - QList<int> supportedIsoSensitivities() const; - - // Aperture - qreal aperture() const; - qreal defaultAperture() const; - void setManualAperture(qreal aperture); - void setAutoAperture(); - QList<qreal> supportedApertures() const; - - // Shutter Speed - qreal shutterSpeed() const; - qreal defaultShutterSpeed() const; - void setManualShutterSpeed(qreal speed); - void setAutoShutterSpeed(); - QList<qreal> supportedShutterSpeeds() const; - - // ExposureCompensation - qreal exposureCompensation() const; - qreal defaultExposureCompensation() const; - void setExposureCompensation(qreal ev); - void setAutoExposureCompensation(); - QList<qreal> supportedExposureCompensationValues() const; - -Q_SIGNALS: // Notifications - // For QCameraExposureControl - void flashReady(bool ready); - void apertureChanged(); - void apertureRangeChanged(); - void shutterSpeedChanged(); - void isoSensitivityChanged(); - void exposureCompensationChanged(); - - // Errors - void error(int, const QString&); - -private: // Data - int mIsoSensitivity; - QList<int> mSupportedIsoSensitivities; - qreal mAperture; - QList<qreal> mSupportedApertures; - qreal mShutterSpeed; - QList<qreal> mSupportedShutterSpeeds; - qreal mExposureCompensation; - QList<qreal> mSupportedExposureCompensations; -}; - -QT_END_NAMESPACE - -#endif // SIMULATORCAMERASETTINGS_H diff --git a/src/plugins/simulator/camera/simulatorvideoinputdevicecontrol.cpp b/src/plugins/simulator/camera/simulatorvideoinputdevicecontrol.cpp deleted file mode 100644 index 95c4e2d..0000000 --- a/src/plugins/simulator/camera/simulatorvideoinputdevicecontrol.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "simulatorvideoinputdevicecontrol.h" - -#include <QtWidgets/QIcon> -#include <QtCore/QDir> -#include <QtCore/QDebug> -#include <QtCore/QStringList> - -using namespace QTM_NAMESPACE; -QSimulatorVideoInputDeviceControl::QSimulatorVideoInputDeviceControl(QObject *parent) - : QVideoDeviceControl(parent) - , mSelectedDevice(-1) -{ -} - -QSimulatorVideoInputDeviceControl::~QSimulatorVideoInputDeviceControl() -{ -} - -int QSimulatorVideoInputDeviceControl::deviceCount() const -{ - return mDevices.count(); -} - -QString QSimulatorVideoInputDeviceControl::deviceName(int index) const -{ - if (index >= mDevices.count() || index < 0) - return QString(); - return mDevices.at(index); -} - -QString QSimulatorVideoInputDeviceControl::deviceDescription(int index) const -{ - if (index >= mDevices.count() || index < 0) - return QString(); - - return mDescriptions[index]; -} - -QIcon QSimulatorVideoInputDeviceControl::deviceIcon(int index) const -{ - Q_UNUSED(index); - return QIcon(); -} - -int QSimulatorVideoInputDeviceControl::defaultDevice() const -{ - if (mDevices.isEmpty()) - return -1; - return 0; -} - -int QSimulatorVideoInputDeviceControl::selectedDevice() const -{ - return mSelectedDevice; -} - - -void QSimulatorVideoInputDeviceControl::setSelectedDevice(int index) -{ - if (index != mSelectedDevice) { - mSelectedDevice = index; - emit selectedDeviceChanged(index); - emit selectedDeviceChanged(deviceName(index)); - } -} - -void QSimulatorVideoInputDeviceControl::updateDeviceList(const QtMobility::QCameraData &data) -{ - mDevices.clear(); - mDescriptions.clear(); - QHashIterator<QString, QCameraData::QCameraDetails> iter(data.cameras); - while(iter.hasNext()) { - iter.next(); - mDevices.append(iter.key()); - mDescriptions.append(iter.value().description); - } - emit devicesChanged(); -} - -void QSimulatorVideoInputDeviceControl::addDevice(const QString &name, const QtMobility::QCameraData::QCameraDetails &details) -{ - if (mDevices.contains(name)) - return; - - mDevices.append(name); - mDescriptions.append(details.description); - emit devicesChanged(); -} - -void QSimulatorVideoInputDeviceControl::removeDevice(const QString &name) -{ - int index = mDevices.indexOf(name); - if (index == -1) - return; - - mDevices.removeAt(index); - mDescriptions.removeAt(index); - if (index == mSelectedDevice) - setSelectedDevice(defaultDevice()); - emit devicesChanged(); -} - -void QSimulatorVideoInputDeviceControl::changeDevice(const QString &name, const QtMobility::QCameraData::QCameraDetails &details) -{ - int index = mDevices.indexOf(name); - if (index == -1) - return; - - if (mDescriptions.at(index) != details.description) - mDescriptions[index] = details.description; -} diff --git a/src/plugins/simulator/camera/simulatorvideoinputdevicecontrol.h b/src/plugins/simulator/camera/simulatorvideoinputdevicecontrol.h deleted file mode 100644 index 2d3ddd0..0000000 --- a/src/plugins/simulator/camera/simulatorvideoinputdevicecontrol.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSIMULATORVIDEOINPUTDEVICECONTROL_H -#define QSIMULATORVIDEOINPUTDEVICECONTROL_H - -#include <qvideodevicecontrol.h> -#include <QtCore/qstring.h> -#include <QtCore/qhash.h> - -#include "../qsimulatormultimediaconnection_p.h" - -QT_USE_NAMESPACE - -class QSimulatorVideoInputDeviceControl : public QVideoDeviceControl -{ -Q_OBJECT -public: - QSimulatorVideoInputDeviceControl(QObject *parent); - ~QSimulatorVideoInputDeviceControl(); - - int deviceCount() const; - - QString deviceName(int index) const; - QString deviceDescription(int index) const; - QIcon deviceIcon(int index) const; - - int defaultDevice() const; - int selectedDevice() const; - - void updateDeviceList(const QtMobility::QCameraData &data); - -public Q_SLOTS: - void setSelectedDevice(int index); - void addDevice(const QString &name, const QtMobility::QCameraData::QCameraDetails &details); - void removeDevice(const QString &name); - void changeDevice(const QString &name, const QtMobility::QCameraData::QCameraDetails &details); - -private: - int mSelectedDevice; - QList<QString> mDevices; - QList<QString> mDescriptions; -}; - -#endif // QSIMULATORVIDEOINPUTDEVICECONTROL_H diff --git a/src/plugins/simulator/camera/simulatorvideorenderercontrol.cpp b/src/plugins/simulator/camera/simulatorvideorenderercontrol.cpp deleted file mode 100644 index 422d4b8..0000000 --- a/src/plugins/simulator/camera/simulatorvideorenderercontrol.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "simulatorvideorenderercontrol.h" -#include "simulatorcamerasettings.h" -#include "simulatorcamerasession.h" -#include <qabstractvideosurface.h> -#include <qvideoframe.h> -#include <qvideosurfaceformat.h> -#include <QFile> -#include <QColor> -#include <QPainter> - -SimulatorVideoRendererControl::SimulatorVideoRendererControl(SimulatorCameraSession *session, QObject *parent) : - QVideoRendererControl(parent) - , mSession(session) - , mSurface(0) - , mRunning(false) -{ -} - -SimulatorVideoRendererControl::~SimulatorVideoRendererControl() -{ -} - -QAbstractVideoSurface *SimulatorVideoRendererControl::surface() const -{ - return mSurface; -} - -void SimulatorVideoRendererControl::setSurface(QAbstractVideoSurface *surface) -{ - mSurface = surface; -} - -void SimulatorVideoRendererControl::setImagePath(const QString &imagePath) -{ - if (QFile::exists(imagePath)) { - mImage = QImage(imagePath); - } else { - mImage = QImage(800, 600, QImage::Format_RGB32); - mImage.fill(qRgb(200, 50, 50)); - QPainter painter(&mImage); - painter.drawText(0, 0, 800, 600, Qt::AlignCenter, imagePath); - } - if (mRunning) - showImage(); -} - -void SimulatorVideoRendererControl::showImage() -{ - if (!mSurface) - return; - stop(); - mShownImage = mImage; - SimulatorCameraSettings *settings = mSession->settings(); - qreal colorDiff = .0; - colorDiff += settings->aperture() - settings->defaultAperture(); - colorDiff += (settings->shutterSpeed() - settings->defaultShutterSpeed()) * 400; - colorDiff += ((qreal)settings->isoSensitivity() - settings->defaultIsoSensitivity()) / 100; - colorDiff += settings->exposureCompensation(); - int diffToApply = qAbs(colorDiff * 20); - QPainter painter(&mShownImage); - if (colorDiff < 0) - painter.fillRect(mShownImage.rect(), QColor(0, 0, 0, qMin(diffToApply, 255))); - else - painter.fillRect(mShownImage.rect(), QColor(255, 255, 255, qMin(diffToApply, 255))); - QVideoFrame::PixelFormat pixelFormat = QVideoFrame::pixelFormatFromImageFormat(mShownImage.format()); - if (pixelFormat == QVideoFrame::Format_Invalid) { - mShownImage = mShownImage.convertToFormat(QImage::Format_RGB32); - pixelFormat = QVideoFrame::Format_RGB32; - } - QVideoSurfaceFormat format(mShownImage.size(), pixelFormat); - mSurface->start(format); - mSurface->present(mShownImage); - mRunning = true; -} - -void SimulatorVideoRendererControl::stop() -{ - if (!mSurface) - return; - - if (mSurface->isActive()) - mSurface->stop(); - mRunning = false; -} - -const QImage * SimulatorVideoRendererControl::image() const -{ - return &mShownImage; -} diff --git a/src/plugins/simulator/camera/simulatorvideorenderercontrol.h b/src/plugins/simulator/camera/simulatorvideorenderercontrol.h deleted file mode 100644 index ba14e1e..0000000 --- a/src/plugins/simulator/camera/simulatorvideorenderercontrol.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSIMULATORVIDEORENDERERCONTROL_H -#define QSIMULATORVIDEORENDERERCONTROL_H - -#include <qvideorenderercontrol.h> -#include <QtGui/QImage> - - -class SimulatorCameraSession; -/* - * Control for QGraphicsVideoItem. Viewfinder frames are streamed to a surface - * which is drawn to the display by the Qt Graphics Vide Framework. - */ -class SimulatorVideoRendererControl : public QVideoRendererControl -{ - Q_OBJECT - -public: - SimulatorVideoRendererControl(SimulatorCameraSession *session, QObject *parent = 0); - virtual ~SimulatorVideoRendererControl(); - - QAbstractVideoSurface *surface() const; - void setSurface(QAbstractVideoSurface *surface); - - void setImagePath(const QString &imagePath); - const QImage *image() const; - -public slots: - void showImage(); - -private slots: - void stop(); - -private: - SimulatorCameraSession *mSession; - QAbstractVideoSurface *mSurface; - QImage mImage; - QImage mShownImage; - bool mRunning; -}; - -#endif // QSIMULATORVIDEORENDERERCONTROL_H diff --git a/src/plugins/simulator/qsimulatormultimediaconnection.cpp b/src/plugins/simulator/qsimulatormultimediaconnection.cpp deleted file mode 100644 index 40fd70d..0000000 --- a/src/plugins/simulator/qsimulatormultimediaconnection.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "../qsimulatormultimediaconnection_p.h" -#include "mobilitysimulatorglobal.h" -#include <mobilityconnection_p.h> - -#include <private/qsimulatordata_p.h> - -#include <QtNetwork/QLocalSocket> - -QTM_BEGIN_NAMESPACE - -using namespace QtSimulatorPrivate; - -Q_GLOBAL_STATIC(QCameraData, qtCameraData) - -namespace Simulator -{ - MultimediaConnection::MultimediaConnection(MobilityConnection *mobilityCon) - : QObject(mobilityCon) - , mConnection(mobilityCon) - , mInitialDataReceived(false) - { - qt_registerCameraTypes(); - mobilityCon->addMessageHandler(this); - } - - void MultimediaConnection::getInitialData() - { - RemoteMetacall<void>::call(mConnection->sendSocket(), NoSync, "setRequestsCameras"); - - while (!mInitialDataReceived) - mConnection->receiveSocket()->waitForReadyRead(100); - } - - void MultimediaConnection::initialCameraDataSent() - { - mInitialDataReceived = true; - } - - void MultimediaConnection::setCameraData(const QCameraData &data) - { - *qtCameraData() = data; - emit cameraDataChanged(data); - } - - void MultimediaConnection::addCamera(const QString &name, const QCameraData::QCameraDetails &details) - { - if (qtCameraData()->cameras.contains(name)) - return; - - qtCameraData()->cameras.insert(name, details); - emit cameraAdded(name, details); - } - - void MultimediaConnection::removeCamera(const QString &name) - { - if (!qtCameraData()->cameras.contains(name)) - return; - - qtCameraData()->cameras.remove(name); - emit cameraRemoved(name); - } - - void MultimediaConnection::changeCamera(const QString &name, const QCameraData::QCameraDetails &details) - { - if (!qtCameraData()->cameras.contains(name)) - return; - - qtCameraData()->cameras[name] = details; - emit cameraChanged(name, details); - } - -} // namespace - -QCameraData get_qtCameraData() -{ - return *qtCameraData(); -} - -#include "moc_qsimulatormultimediaconnection_p.cpp" - -QTM_END_NAMESPACE diff --git a/src/plugins/simulator/qsimulatormultimediaconnection_p.h b/src/plugins/simulator/qsimulatormultimediaconnection_p.h deleted file mode 100644 index e760f39..0000000 --- a/src/plugins/simulator/qsimulatormultimediaconnection_p.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SIMULATORMULTIMEDIACONNECTION_H -#define SIMULATORMULTIMEDIACONNECTION_H - -#include "qsimulatormultimediadata_p.h" - -QT_BEGIN_HEADER - -QTM_BEGIN_NAMESPACE - -namespace Simulator -{ - class MobilityConnection; - - class MultimediaConnection : public QObject - { - Q_OBJECT - public: - MultimediaConnection (MobilityConnection *mobilityCon); - virtual ~MultimediaConnection () {} - - void getInitialData(); - - private slots: - void setCameraData(const QtMobility::QCameraData &); - void addCamera(const QString &, const QtMobility::QCameraData::QCameraDetails &); - void removeCamera(const QString &); - void changeCamera(const QString &, const QtMobility::QCameraData::QCameraDetails &); - void initialCameraDataSent(); - - private: - MobilityConnection *mConnection; - bool mInitialDataReceived; - - signals: - void cameraDataChanged(const QtMobility::QCameraData &data); - void cameraAdded(const QString &name, const QtMobility::QCameraData::QCameraDetails &details); - void cameraRemoved(const QString &name); - void cameraChanged(const QString &name, const QtMobility::QCameraData::QCameraDetails &details); - }; -} // end namespace Simulator - -QCameraData get_qtCameraData(); - -QTM_END_NAMESPACE -QT_END_HEADER - -#endif - diff --git a/src/plugins/simulator/qsimulatormultimediadata.cpp b/src/plugins/simulator/qsimulatormultimediadata.cpp deleted file mode 100644 index 494f0a6..0000000 --- a/src/plugins/simulator/qsimulatormultimediadata.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsimulatormultimediadata_p.h" - -#include <QtCore/QDataStream> - -QTM_BEGIN_NAMESPACE - -void qt_registerCameraTypes() -{ - qRegisterMetaTypeStreamOperators<QCameraData::QCameraDetails>("QtMobility::QCameraData::QCameraDetails"); - qRegisterMetaTypeStreamOperators<QCameraData>("QtMobility::QCameraData"); -} - -QDataStream &operator<<(QDataStream &out, const QCameraData &s) -{ - out << s.cameras; - return out; -} - -QDataStream &operator>>(QDataStream &in, QCameraData &s) -{ - in >> s.cameras; - return in; -} - -QDataStream &operator<<(QDataStream &out, const QCameraData::QCameraDetails &s) -{ - out << s.description << s.imagePath; - return out; -} - -QDataStream &operator>>(QDataStream &in, QCameraData::QCameraDetails &s) -{ - in >> s.description >> s.imagePath; - return in; -} - -QTM_END_NAMESPACE diff --git a/src/plugins/simulator/qsimulatormultimediadata_p.h b/src/plugins/simulator/qsimulatormultimediadata_p.h deleted file mode 100644 index b814f5c..0000000 --- a/src/plugins/simulator/qsimulatormultimediadata_p.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSIMULATORMULTIMEDIADATA_P_H -#define QSIMULATORMULTIMEDIADATA_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qtmultimediadefs.h" -#include <QtCore/QMetaType> -#include <QtCore/QDateTime> -#include <qcamera.h> - -QT_BEGIN_HEADER -QTM_BEGIN_NAMESPACE - -struct QCameraData { - struct QCameraDetails { - QString description; - QString imagePath; - }; - QHash<QString, QCameraDetails> cameras; -}; - -void qt_registerCameraTypes(); - -QTM_END_NAMESPACE - -Q_DECLARE_METATYPE(QtMobility::QCameraData) -Q_DECLARE_METATYPE(QtMobility::QCameraData::QCameraDetails) - -QT_END_HEADER - -#endif // QMULTIMEDIADATA_SIMULATOR_P_H diff --git a/src/plugins/simulator/qsimulatorserviceplugin.cpp b/src/plugins/simulator/qsimulatorserviceplugin.cpp deleted file mode 100644 index e0e6d12..0000000 --- a/src/plugins/simulator/qsimulatorserviceplugin.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qstring.h> -#include <QtCore/qdebug.h> -#include <QtWidgets/QIcon> -#include <QtCore/QDir> -#include <QtCore/QDebug> - -#include "qsimulatorserviceplugin.h" -#include <mobilityconnection_p.h> - -#include "simulatorcameraservice.h" - -#include <qmediaserviceprovider.h> - -#include <fcntl.h> -#include <errno.h> -#include <string.h> -#include <stdlib.h> - -QTM_USE_NAMESPACE - -Simulator::MultimediaConnection *QSimulatorServicePlugin::mMultimediaConnection = 0; - -QSimulatorServicePlugin::QSimulatorServicePlugin() -{ - ensureSimulatorConnection(); -} - -QStringList QSimulatorServicePlugin::keys() const -{ - QStringList retList; - retList << QLatin1String(Q_MEDIASERVICE_CAMERA); - return retList; -} - -QMediaService* QSimulatorServicePlugin::create(const QString &key) -{ - if (key == QLatin1String(Q_MEDIASERVICE_CAMERA)) - return new SimulatorCameraService(key, mMultimediaConnection); - - qWarning() << "Simulator service plugin: unsupported key:" << key; - return 0; -} - -void QSimulatorServicePlugin::release(QMediaService *service) -{ - delete service; -} - -QList<QByteArray> QSimulatorServicePlugin::devices(const QByteArray &service) const -{ - if (service == Q_MEDIASERVICE_CAMERA) { - QCameraData cams = get_qtCameraData(); - QList<QByteArray> returnList; - foreach(const QString &key, cams.cameras.keys()) - returnList.append(key.toAscii()); - return returnList; - } - - return QList<QByteArray>(); -} - -QString QSimulatorServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device) -{ - if (service == Q_MEDIASERVICE_CAMERA) { - QCameraData cams = get_qtCameraData(); - return cams.cameras.value(device).description; - } - - return QString(); -} - -void QSimulatorServicePlugin::ensureSimulatorConnection() -{ - using namespace QtMobility::Simulator; - - static bool connected = false; - if (connected) - return; - - connected = true; - MobilityConnection *connection = MobilityConnection::instance(); - mMultimediaConnection = new MultimediaConnection(connection); - mMultimediaConnection->getInitialData(); -} - -Q_EXPORT_PLUGIN2(qtmedia_simulatorengine, QSimulatorServicePlugin); diff --git a/src/plugins/simulator/qsimulatorserviceplugin.h b/src/plugins/simulator/qsimulatorserviceplugin.h deleted file mode 100644 index 75c6aa2..0000000 --- a/src/plugins/simulator/qsimulatorserviceplugin.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QSIMULATORSERVICEPLUGIN_H -#define QSIMULATORSERVICEPLUGIN_H - -#include <qmediaserviceproviderplugin.h> -#include "qsimulatormultimediaconnection_p.h" - -QT_USE_NAMESPACE - -class QSimulatorServicePlugin : public QMediaServiceProviderPlugin, public QMediaServiceSupportedDevicesInterface -{ - Q_OBJECT - Q_INTERFACES(QMediaServiceSupportedDevicesInterface) -public: - QSimulatorServicePlugin(); - - // QMediaServiceProviderPlugin - QStringList keys() const; - QMediaService* create(QString const& key); - void release(QMediaService *service); - - // QMediaServiceSupportedDevicesInterface - QList<QByteArray> devices(const QByteArray &service) const; - QString deviceDescription(const QByteArray &service, const QByteArray &device); - -private: - static void ensureSimulatorConnection(); - static QTM_PREPEND_NAMESPACE(Simulator::MultimediaConnection) *mMultimediaConnection; - -signals: - void cameraDataChanged(); -}; - -#endif // QSIMULATORSERVICEPLUGIN_H diff --git a/src/plugins/simulator/simulator.pro b/src/plugins/simulator/simulator.pro deleted file mode 100644 index 81117ca..0000000 --- a/src/plugins/simulator/simulator.pro +++ /dev/null @@ -1,28 +0,0 @@ -TEMPLATE = lib -CONFIG += plugin -TARGET = $$qtLibraryTarget(qsimulatorengine) -PLUGIN_TYPE=mediaservice - -include(../../../common.pri) -INCLUDEPATH+=$${SOURCE_DIR}/src/multimedia \ - $${SOURCE_DIR}/src/multimedia/video \ - $${SOURCE_DIR}/src/multimedia/audio \ - $${SOURCE_DIR}/src/mobilitysimulator - -CONFIG += mobility -MOBILITY = multimedia - -DEPENDPATH += . - -# Input -HEADERS += \ - qsimulatormultimediaconnection_p.h \ - qsimulatormultimediadata_p.h \ - qsimulatorserviceplugin.h - -SOURCES += \ - qsimulatormultimediaconnection.cpp \ - qsimulatormultimediadata.cpp \ - qsimulatorserviceplugin.cpp \ - -include(camera/simulatorcamera.pri) diff --git a/src/plugins/v4l/radio/radio.pri b/src/plugins/v4l/radio/radio.pri deleted file mode 100644 index b8a9f75..0000000 --- a/src/plugins/v4l/radio/radio.pri +++ /dev/null @@ -1,9 +0,0 @@ -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/v4lradiocontrol.h \ - $$PWD/v4lradioservice.h - -SOURCES += \ - $$PWD/v4lradiocontrol.cpp \ - $$PWD/v4lradioservice.cpp diff --git a/src/plugins/v4l/radio/v4lradiocontrol.cpp b/src/plugins/v4l/radio/v4lradiocontrol.cpp deleted file mode 100644 index 49182d5..0000000 --- a/src/plugins/v4l/radio/v4lradiocontrol.cpp +++ /dev/null @@ -1,538 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "v4lradiocontrol.h" -#include "v4lradioservice.h" - -#include <QtCore/qdebug.h> - -#include <fcntl.h> - -#include <sys/ioctl.h> -#include "linux/videodev2.h" - -#include <sys/soundcard.h> -#include <stdio.h> -#include <sys/types.h> -#include <sys/ioctl.h> -#include <fcntl.h> -#include <unistd.h> - -V4LRadioControl::V4LRadioControl(QObject *parent) - :QRadioTunerControl(parent) -{ - fd = -1; - initRadio(); - muted = false; - stereo = false; - m_error = false; - sig = 0; - currentBand = QRadioTuner::FM; - step = 100000; - scanning = false; - playTime.restart(); - timer = new QTimer(this); - timer->setInterval(200); - connect(timer,SIGNAL(timeout()),this,SLOT(search())); - timer->start(); -} - -V4LRadioControl::~V4LRadioControl() -{ - timer->stop(); - - if(fd > 0) - ::close(fd); -} - -bool V4LRadioControl::isAvailable() const -{ - return available; -} - -QtMultimedia::AvailabilityError V4LRadioControl::availabilityError() const -{ - if (fd > 0) - return QtMultimedia::NoError; - else - return QtMultimedia::ResourceError; -} - -QRadioTuner::State V4LRadioControl::state() const -{ - return fd > 0 ? QRadioTuner::ActiveState : QRadioTuner::StoppedState; -} - -QRadioTuner::Band V4LRadioControl::band() const -{ - return currentBand; -} - -bool V4LRadioControl::isBandSupported(QRadioTuner::Band b) const -{ - QRadioTuner::Band bnd = (QRadioTuner::Band)b; - switch(bnd) { - case QRadioTuner::FM: - if(freqMin <= 87500000 && freqMax >= 108000000) - return true; - break; - case QRadioTuner::LW: - if(freqMin <= 148500 && freqMax >= 283500) - return true; - case QRadioTuner::AM: - if(freqMin <= 520000 && freqMax >= 1610000) - return true; - default: - if(freqMin <= 1711000 && freqMax >= 30000000) - return true; - } - - return false; -} - -void V4LRadioControl::setBand(QRadioTuner::Band b) -{ - if(freqMin <= 87500000 && freqMax >= 108000000 && b == QRadioTuner::FM) { - // FM 87.5 to 108.0 MHz, except Japan 76-90 MHz - currentBand = (QRadioTuner::Band)b; - step = 100000; // 100kHz steps - emit bandChanged(currentBand); - - } else if(freqMin <= 148500 && freqMax >= 283500 && b == QRadioTuner::LW) { - // LW 148.5 to 283.5 kHz, 9kHz channel spacing (Europe, Africa, Asia) - currentBand = (QRadioTuner::Band)b; - step = 1000; // 1kHz steps - emit bandChanged(currentBand); - - } else if(freqMin <= 520000 && freqMax >= 1610000 && b == QRadioTuner::AM) { - // AM 520 to 1610 kHz, 9 or 10kHz channel spacing, extended 1610 to 1710 kHz - currentBand = (QRadioTuner::Band)b; - step = 1000; // 1kHz steps - emit bandChanged(currentBand); - - } else if(freqMin <= 1711000 && freqMax >= 30000000 && b == QRadioTuner::SW) { - // SW 1.711 to 30.0 MHz, divided into 15 bands. 5kHz channel spacing - currentBand = (QRadioTuner::Band)b; - step = 500; // 500Hz steps - emit bandChanged(currentBand); - } - playTime.restart(); -} - -int V4LRadioControl::frequency() const -{ - return currentFreq; -} - -int V4LRadioControl::frequencyStep(QRadioTuner::Band b) const -{ - int step = 0; - - if(b == QRadioTuner::FM) - step = 100000; // 100kHz steps - else if(b == QRadioTuner::LW) - step = 1000; // 1kHz steps - else if(b == QRadioTuner::AM) - step = 1000; // 1kHz steps - else if(b == QRadioTuner::SW) - step = 500; // 500Hz steps - - return step; -} - -QPair<int,int> V4LRadioControl::frequencyRange(QRadioTuner::Band b) const -{ - if(b == QRadioTuner::AM) - return qMakePair<int,int>(520000,1710000); - else if(b == QRadioTuner::FM) - return qMakePair<int,int>(87500000,108000000); - else if(b == QRadioTuner::SW) - return qMakePair<int,int>(1711111,30000000); - else if(b == QRadioTuner::LW) - return qMakePair<int,int>(148500,283500); - - return qMakePair<int,int>(0,0); -} - -void V4LRadioControl::setFrequency(int frequency) -{ - qint64 f = frequency; - - v4l2_frequency freq; - - if(frequency < freqMin) - f = freqMax; - if(frequency > freqMax) - f = freqMin; - - if(fd > 0) { - memset( &freq, 0, sizeof( freq ) ); - // Use the first tuner - freq.tuner = 0; - if ( ioctl( fd, VIDIOC_G_FREQUENCY, &freq ) >= 0 ) { - if(low) { - // For low, freq in units of 62.5Hz, so convert from Hz to units. - freq.frequency = (int)(f/62.5); - } else { - // For high, freq in units of 62.5kHz, so convert from Hz to units. - freq.frequency = (int)(f/62500); - } - ioctl( fd, VIDIOC_S_FREQUENCY, &freq ); - currentFreq = f; - playTime.restart(); - emit frequencyChanged(currentFreq); - } - } - playTime.restart(); -} - -bool V4LRadioControl::isStereo() const -{ - return stereo; -} - -QRadioTuner::StereoMode V4LRadioControl::stereoMode() const -{ - return QRadioTuner::Auto; -} - -void V4LRadioControl::setStereoMode(QRadioTuner::StereoMode mode) -{ - bool stereo = true; - - if(mode == QRadioTuner::ForceMono) - stereo = false; - - v4l2_tuner tuner; - - memset( &tuner, 0, sizeof( tuner ) ); - - if ( ioctl( fd, VIDIOC_G_TUNER, &tuner ) >= 0 ) { - if(stereo) - tuner.audmode = V4L2_TUNER_MODE_STEREO; - else - tuner.audmode = V4L2_TUNER_MODE_MONO; - - if ( ioctl( fd, VIDIOC_S_TUNER, &tuner ) >= 0 ) { - emit stereoStatusChanged(stereo); - } - } -} - -int V4LRadioControl::signalStrength() const -{ - v4l2_tuner tuner; - - // Return the first tuner founds signal strength. - for ( int index = 0; index < tuners; ++index ) { - memset( &tuner, 0, sizeof( tuner ) ); - tuner.index = index; - if ( ioctl( fd, VIDIOC_G_TUNER, &tuner ) < 0 ) - continue; - if ( tuner.type != V4L2_TUNER_RADIO ) - continue; - // percentage signal strength - return tuner.signal*100/65535; - } - - return 0; -} - -int V4LRadioControl::volume() const -{ - v4l2_queryctrl queryctrl; - - if(fd > 0) { - memset( &queryctrl, 0, sizeof( queryctrl ) ); - queryctrl.id = V4L2_CID_AUDIO_VOLUME; - if ( ioctl( fd, VIDIOC_QUERYCTRL, &queryctrl ) >= 0 ) { - if(queryctrl.maximum == 0) { - return vol; - } else { - // percentage volume returned - return queryctrl.default_value*100/queryctrl.maximum; - } - } - } - return 0; -} - -void V4LRadioControl::setVolume(int volume) -{ - v4l2_queryctrl queryctrl; - - if(fd > 0) { - memset( &queryctrl, 0, sizeof( queryctrl ) ); - queryctrl.id = V4L2_CID_AUDIO_VOLUME; - if ( ioctl( fd, VIDIOC_QUERYCTRL, &queryctrl ) >= 0 ) { - v4l2_control control; - - if(queryctrl.maximum > 0) { - memset( &control, 0, sizeof( control ) ); - control.id = V4L2_CID_AUDIO_VOLUME; - control.value = volume*queryctrl.maximum/100; - ioctl( fd, VIDIOC_S_CTRL, &control ); - } else { - setVol(volume); - } - emit volumeChanged(volume); - } - } -} - -bool V4LRadioControl::isMuted() const -{ - return muted; -} - -void V4LRadioControl::setMuted(bool muted) -{ - v4l2_queryctrl queryctrl; - - if(fd > 0) { - memset( &queryctrl, 0, sizeof( queryctrl ) ); - queryctrl.id = V4L2_CID_AUDIO_MUTE; - if ( ioctl( fd, VIDIOC_QUERYCTRL, &queryctrl ) >= 0 ) { - v4l2_control control; - memset( &control, 0, sizeof( control ) ); - control.id = V4L2_CID_AUDIO_MUTE; - control.value = (muted ? queryctrl.maximum : queryctrl.minimum ); - ioctl( fd, VIDIOC_S_CTRL, &control ); - this->muted = muted; - emit mutedChanged(muted); - } - } -} - -bool V4LRadioControl::isSearching() const -{ - return scanning; -} - -void V4LRadioControl::cancelSearch() -{ - scanning = false; - timer->stop(); -} - -void V4LRadioControl::searchForward() -{ - // Scan up - if(scanning) { - cancelSearch(); - return; - } - scanning = true; - forward = true; - timer->start(); -} - -void V4LRadioControl::searchBackward() -{ - // Scan down - if(scanning) { - cancelSearch(); - return; - } - scanning = true; - forward = false; - timer->start(); -} - -void V4LRadioControl::start() -{ -} - -void V4LRadioControl::stop() -{ -} - -QRadioTuner::Error V4LRadioControl::error() const -{ - if(m_error) - return QRadioTuner::OpenError; - - return QRadioTuner::NoError; -} - -QString V4LRadioControl::errorString() const -{ - return QString(); -} - -void V4LRadioControl::search() -{ - int signal = signalStrength(); - if(sig != signal) { - sig = signal; - emit signalStrengthChanged(sig); - } - - if(!scanning) return; - - if (signal > 25) { - cancelSearch(); - return; - } - - if(forward) { - setFrequency(currentFreq+step); - } else { - setFrequency(currentFreq-step); - } -} - -bool V4LRadioControl::initRadio() -{ - v4l2_tuner tuner; - v4l2_input input; - v4l2_frequency freq; - v4l2_capability cap; - - low = false; - available = false; - freqMin = freqMax = currentFreq = 0; - - fd = ::open("/dev/radio0", O_RDWR); - - if(fd != -1) { - // Capabilities - memset( &cap, 0, sizeof( cap ) ); - if(::ioctl(fd, VIDIOC_QUERYCAP, &cap ) >= 0) { - if(((cap.capabilities & V4L2_CAP_RADIO) == 0) && ((cap.capabilities & V4L2_CAP_AUDIO) == 0)) - available = true; - } - - // Tuners - memset( &input, 0, sizeof( input ) ); - tuners = 0; - for ( ;; ) { - memset( &input, 0, sizeof( input ) ); - input.index = tuners; - if ( ioctl( fd, VIDIOC_ENUMINPUT, &input ) < 0 ) - break; - ++tuners; - } - - // Freq bands - for ( int index = 0; index < tuners; ++index ) { - memset( &tuner, 0, sizeof( tuner ) ); - tuner.index = index; - if ( ioctl( fd, VIDIOC_G_TUNER, &tuner ) < 0 ) - continue; - if ( tuner.type != V4L2_TUNER_RADIO ) - continue; - if ( ( tuner.capability & V4L2_TUNER_CAP_LOW ) != 0 ) { - // Units are 1/16th of a kHz. - low = true; - } - if(low) { - freqMin = tuner.rangelow * 62.5; - freqMax = tuner.rangehigh * 62.5; - } else { - freqMin = tuner.rangelow * 62500; - freqMax = tuner.rangehigh * 62500; - } - } - - // frequency - memset( &freq, 0, sizeof( freq ) ); - if(::ioctl(fd, VIDIOC_G_FREQUENCY, &freq ) >= 0) { - if ( ((int)freq.frequency) != -1 ) { // -1 means not set. - if(low) - currentFreq = freq.frequency * 62.5; - else - currentFreq = freq.frequency * 62500; - } - } - - // stereo - bool stereo = false; - memset( &tuner, 0, sizeof( tuner ) ); - if ( ioctl( fd, VIDIOC_G_TUNER, &tuner ) >= 0 ) { - if((tuner.rxsubchans & V4L2_TUNER_SUB_STEREO) != 0) - stereo = true; - } - - vol = getVol(); - - return true; - } - m_error = true; - emit error(); - - return false; -} - -void V4LRadioControl::setVol(int v) -{ - int fd = ::open( "/dev/mixer", O_RDWR, 0 ); - if ( fd < 0 ) - return; - int volume = v; - if ( volume < 0 ) - volume = 0; - else if ( volume > 100 ) - volume = 100; - vol = volume; - volume += volume << 8; - ::ioctl( fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &volume ); - ::close( fd ); -} - -int V4LRadioControl::getVol() -{ - int fd = ::open( "/dev/mixer", O_RDWR, 0 ); - if ( fd >= 0 ) { - int volume = 0; - ::ioctl( fd, MIXER_READ(SOUND_MIXER_VOLUME), &volume ); - int left = ( volume & 0xFF ); - int right = ( ( volume >> 8 ) & 0xFF ); - if ( left > right ) - vol = left; - else - vol = right; - ::close( fd ); - return vol; - } - return 0; -} - diff --git a/src/plugins/v4l/radio/v4lradiocontrol.h b/src/plugins/v4l/radio/v4lradiocontrol.h deleted file mode 100644 index 4e9f6eb..0000000 --- a/src/plugins/v4l/radio/v4lradiocontrol.h +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef V4LRADIOCONTROL_H -#define V4LRADIOCONTROL_H - -#include <QtCore/qobject.h> -#include <QtCore/qtimer.h> -#include <QtCore/qdatetime.h> - -#include <qradiotunercontrol.h> - -#include <linux/types.h> -#include <sys/time.h> -#include <sys/ioctl.h> -#include <linux/videodev2.h> - -QT_USE_NAMESPACE - -class V4LRadioService; - -class V4LRadioControl : public QRadioTunerControl -{ - Q_OBJECT -public: - V4LRadioControl(QObject *parent = 0); - ~V4LRadioControl(); - - bool isAvailable() const; - QtMultimedia::AvailabilityError availabilityError() const; - - QRadioTuner::State state() const; - - QRadioTuner::Band band() const; - void setBand(QRadioTuner::Band b); - bool isBandSupported(QRadioTuner::Band b) const; - - int frequency() const; - int frequencyStep(QRadioTuner::Band b) const; - QPair<int,int> frequencyRange(QRadioTuner::Band b) const; - void setFrequency(int frequency); - - bool isStereo() const; - QRadioTuner::StereoMode stereoMode() const; - void setStereoMode(QRadioTuner::StereoMode mode); - - int signalStrength() const; - - int volume() const; - void setVolume(int volume); - - bool isMuted() const; - void setMuted(bool muted); - - bool isSearching() const; - void cancelSearch(); - - void searchForward(); - void searchBackward(); - - void start(); - void stop(); - - QRadioTuner::Error error() const; - QString errorString() const; - -private slots: - void search(); - -private: - bool initRadio(); - void setVol(int v); - int getVol(); - - int fd; - - bool m_error; - bool muted; - bool stereo; - bool low; - bool available; - int tuners; - int step; - int vol; - int sig; - bool scanning; - bool forward; - QTimer* timer; - QRadioTuner::Band currentBand; - qint64 freqMin; - qint64 freqMax; - qint64 currentFreq; - QTime playTime; -}; - -#endif diff --git a/src/plugins/v4l/radio/v4lradioservice.cpp b/src/plugins/v4l/radio/v4lradioservice.cpp deleted file mode 100644 index 1d9ad2f..0000000 --- a/src/plugins/v4l/radio/v4lradioservice.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qvariant.h> -#include <QtCore/qdebug.h> -#include <QtCore/qfile.h> -#include <QtWidgets/qwidget.h> - -#include "v4lradioservice.h" -#include "v4lradiocontrol.h" - -V4LRadioService::V4LRadioService(QObject *parent): - QMediaService(parent) -{ - m_control = new V4LRadioControl(this); -} - -V4LRadioService::~V4LRadioService() -{ -} - -QMediaControl *V4LRadioService::requestControl(const char* name) -{ - if (qstrcmp(name,QRadioTunerControl_iid) == 0) - return m_control; - - return 0; -} - - -void V4LRadioService::releaseControl(QMediaControl *) -{ -} diff --git a/src/plugins/v4l/radio/v4lradioservice.h b/src/plugins/v4l/radio/v4lradioservice.h deleted file mode 100644 index 896e587..0000000 --- a/src/plugins/v4l/radio/v4lradioservice.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef V4LRADIOSERVICE_H -#define V4LRADIOSERVICE_H - -#include <QtCore/qobject.h> - -#include <qmediaservice.h> -QT_USE_NAMESPACE - -class V4LRadioControl; - -class V4LRadioService : public QMediaService -{ - Q_OBJECT - -public: - V4LRadioService(QObject *parent = 0); - ~V4LRadioService(); - - QMediaControl *requestControl(const char* name); - void releaseControl(QMediaControl *); - -private: - V4LRadioControl *m_control; -}; - -#endif diff --git a/src/plugins/v4l/v4l.pro b/src/plugins/v4l/v4l.pro deleted file mode 100644 index bc5c3d4..0000000 --- a/src/plugins/v4l/v4l.pro +++ /dev/null @@ -1,16 +0,0 @@ -load(qt_module) - -TARGET = qtmedia_v4lengine -QT += multimedia-private -PLUGIN_TYPE = mediaservice - -load(qt_plugin) -DESTDIR = $$QT.multimedia.plugins/$${PLUGIN_TYPE} - -HEADERS += v4lserviceplugin.h -SOURCES += v4lserviceplugin.cpp - -include(radio/radio.pri) - -target.path += $$[QT_INSTALL_PLUGINS]/$${PLUGIN_TYPE} -INSTALLS += target diff --git a/src/plugins/v4l/v4lserviceplugin.cpp b/src/plugins/v4l/v4lserviceplugin.cpp deleted file mode 100644 index b946836..0000000 --- a/src/plugins/v4l/v4lserviceplugin.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qstring.h> -#include <QtCore/qfile.h> -#include <QtCore/qdebug.h> -#include <QtCore/qdir.h> - -#include "v4lserviceplugin.h" -#include "v4lradioservice.h" - -#include <qmediaserviceprovider.h> - - -QStringList V4LServicePlugin::keys() const -{ - return QStringList() << - QLatin1String(Q_MEDIASERVICE_RADIO); -} - -QMediaService* V4LServicePlugin::create(QString const& key) -{ - if (key == QLatin1String(Q_MEDIASERVICE_RADIO)) - return new V4LRadioService; - - return 0; -} - -void V4LServicePlugin::release(QMediaService *service) -{ - delete service; -} - -QList<QByteArray> V4LServicePlugin::devices(const QByteArray &service) const -{ - return QList<QByteArray>(); -} - -QString V4LServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device) -{ - return QString(); -} - - -Q_EXPORT_PLUGIN2(qtmedia_v4lengine, V4LServicePlugin); - diff --git a/src/plugins/v4l/v4lserviceplugin.h b/src/plugins/v4l/v4lserviceplugin.h deleted file mode 100644 index fb50aba..0000000 --- a/src/plugins/v4l/v4lserviceplugin.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** 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 Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef V4LSERVICEPLUGIN_H -#define V4LSERVICEPLUGIN_H - -#include <qmediaserviceproviderplugin.h> - -QT_USE_NAMESPACE - -class V4LServicePlugin : public QMediaServiceProviderPlugin, public QMediaServiceSupportedDevicesInterface -{ - Q_OBJECT - Q_INTERFACES(QMediaServiceSupportedDevicesInterface) -public: - QStringList keys() const; - QMediaService* create(QString const& key); - void release(QMediaService *service); - - QList<QByteArray> devices(const QByteArray &service) const; - QString deviceDescription(const QByteArray &service, const QByteArray &device); -}; - -#endif // V4LSERVICEPLUGIN_H diff --git a/src/plugins/wmf/player/evr9videowindowcontrol.cpp b/src/plugins/wmf/player/evr9videowindowcontrol.cpp deleted file mode 100644 index e653dd9..0000000 --- a/src/plugins/wmf/player/evr9videowindowcontrol.cpp +++ /dev/null @@ -1,351 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "evr9videowindowcontrol.h" -#include <QtCore/qdebug.h> -#include <QtCore/qglobal.h> - -Evr9VideoWindowControl::Evr9VideoWindowControl(QObject *parent) - : QVideoWindowControl(parent) - , m_windowId(0) - , m_dirtyValues(0) - , m_aspectRatioMode(Qt::KeepAspectRatio) - , m_brightness(0) - , m_contrast(0) - , m_hue(0) - , m_saturation(0) - , m_fullScreen(false) - , m_currentActivate(0) - , m_evrSink(0) - , m_displayControl(0) -{ - if (FAILED(MFCreateVideoRendererActivate(0, &m_currentActivate))) { - qWarning() << "Failed to create evr video renderer activate!"; - return; - } - if (FAILED(m_currentActivate->ActivateObject(IID_IMFMediaSink, (LPVOID*)(&m_evrSink)))) { - qWarning() << "Failed to activate evr media sink!"; - return; - } - if (FAILED(MFGetService(m_evrSink, MR_VIDEO_RENDER_SERVICE, IID_PPV_ARGS(&m_displayControl)))) { - qWarning() << "Failed to get display control from evr media sink!"; - return; - } - if (FAILED(MFGetService(m_evrSink, MR_VIDEO_MIXER_SERVICE, IID_PPV_ARGS(&m_processor)))) { - qWarning() << "Failed to get video processor from evr media sink!"; - return; - } -} - -Evr9VideoWindowControl::~Evr9VideoWindowControl() -{ - if (m_processor) - m_processor->Release(); - if (m_displayControl) - m_displayControl->Release(); - if (m_evrSink) - m_evrSink->Release(); - if (m_currentActivate) { - m_currentActivate->ShutdownObject(); - m_currentActivate->Release(); - } -} - - -WId Evr9VideoWindowControl::winId() const -{ - return m_windowId; -} - -void Evr9VideoWindowControl::setWinId(WId id) -{ - m_windowId = id; - - if (QWidget *widget = QWidget::find(m_windowId)) { - const QColor color = widget->palette().color(QPalette::Window); - - m_windowColor = RGB(color.red(), color.green(), color.blue()); - } - - if (m_displayControl) { - m_displayControl->SetVideoWindow(m_windowId); - } -} - -QRect Evr9VideoWindowControl::displayRect() const -{ - return m_displayRect; -} - -void Evr9VideoWindowControl::setDisplayRect(const QRect &rect) -{ - m_displayRect = rect; - - if (m_displayControl) { - RECT displayRect = { rect.left(), rect.top(), rect.right() + 1, rect.bottom() + 1 }; - QSize sourceSize = nativeSize(); - - RECT sourceRect = { 0, 0, sourceSize.width(), sourceSize.height() }; - - if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) { - QSize clippedSize = rect.size(); - clippedSize.scale(sourceRect.right, sourceRect.bottom, Qt::KeepAspectRatio); - - sourceRect.left = (sourceRect.right - clippedSize.width()) / 2; - sourceRect.top = (sourceRect.bottom - clippedSize.height()) / 2; - sourceRect.right = sourceRect.left + clippedSize.width(); - sourceRect.bottom = sourceRect.top + clippedSize.height(); - } - - if (sourceSize.width() > 0 && sourceSize.height() > 0) { - MFVideoNormalizedRect sourceNormRect; - sourceNormRect.left = float(sourceRect.left) / float(sourceRect.right); - sourceNormRect.top = float(sourceRect.top) / float(sourceRect.bottom); - sourceNormRect.right = float(sourceRect.right) / float(sourceRect.right); - sourceNormRect.bottom = float(sourceRect.bottom) / float(sourceRect.bottom); - m_displayControl->SetVideoPosition(&sourceNormRect, &displayRect); - } else { - m_displayControl->SetVideoPosition(NULL, &displayRect); - } - } -} - -bool Evr9VideoWindowControl::isFullScreen() const -{ - return m_fullScreen; -} - -void Evr9VideoWindowControl::setFullScreen(bool fullScreen) -{ - if (m_fullScreen == fullScreen) - return; - emit fullScreenChanged(m_fullScreen = fullScreen); -} - -void Evr9VideoWindowControl::repaint() -{ - QSize size = nativeSize(); - if (size.width() > 0 && size.height() > 0 - && m_displayControl - && SUCCEEDED(m_displayControl->RepaintVideo())) { - return; - } - - PAINTSTRUCT paint; - if (HDC dc = ::BeginPaint(m_windowId, &paint)) { - HPEN pen = ::CreatePen(PS_SOLID, 1, m_windowColor); - HBRUSH brush = ::CreateSolidBrush(m_windowColor); - ::SelectObject(dc, pen); - ::SelectObject(dc, brush); - - ::Rectangle( - dc, - m_displayRect.left(), - m_displayRect.top(), - m_displayRect.right() + 1, - m_displayRect.bottom() + 1); - - ::DeleteObject(pen); - ::DeleteObject(brush); - ::EndPaint(m_windowId, &paint); - } -} - -QSize Evr9VideoWindowControl::nativeSize() const -{ - QSize size; - if (m_displayControl) { - SIZE sourceSize; - if (SUCCEEDED(m_displayControl->GetNativeVideoSize(&sourceSize, 0))) - size = QSize(sourceSize.cx, sourceSize.cy); - } - return size; -} - -Qt::AspectRatioMode Evr9VideoWindowControl::aspectRatioMode() const -{ - return m_aspectRatioMode; -} - -void Evr9VideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode) -{ - m_aspectRatioMode = mode; - - if (m_displayControl) { - switch (mode) { - case Qt::IgnoreAspectRatio: - //comment from MSDN: Do not maintain the aspect ratio of the video. Stretch the video to fit the output rectangle. - m_displayControl->SetAspectRatioMode(MFVideoARMode_None); - break; - case Qt::KeepAspectRatio: - //comment from MSDN: Preserve the aspect ratio of the video by letterboxing or within the output rectangle. - m_displayControl->SetAspectRatioMode(MFVideoARMode_PreservePicture); - break; - case Qt::KeepAspectRatioByExpanding: - //for this mode, more adjustment will be done in setDisplayRect - m_displayControl->SetAspectRatioMode(MFVideoARMode_PreservePicture); - break; - default: - break; - } - setDisplayRect(m_displayRect); - } -} - -int Evr9VideoWindowControl::brightness() const -{ - return m_brightness; -} - -void Evr9VideoWindowControl::setBrightness(int brightness) -{ - if (m_brightness == brightness) - return; - - m_brightness = brightness; - - m_dirtyValues |= DXVA2_ProcAmp_Brightness; - - setProcAmpValues(); - - emit brightnessChanged(brightness); -} - -int Evr9VideoWindowControl::contrast() const -{ - return m_contrast; -} - -void Evr9VideoWindowControl::setContrast(int contrast) -{ - if (m_contrast == contrast) - return; - - m_contrast = contrast; - - m_dirtyValues |= DXVA2_ProcAmp_Contrast; - - setProcAmpValues(); - - emit contrastChanged(contrast); -} - -int Evr9VideoWindowControl::hue() const -{ - return m_hue; -} - -void Evr9VideoWindowControl::setHue(int hue) -{ - if (m_hue == hue) - return; - - m_hue = hue; - - m_dirtyValues |= DXVA2_ProcAmp_Hue; - - setProcAmpValues(); - - emit hueChanged(hue); -} - -int Evr9VideoWindowControl::saturation() const -{ - return m_saturation; -} - -void Evr9VideoWindowControl::setSaturation(int saturation) -{ - if (m_saturation == saturation) - return; - - m_saturation = saturation; - - m_dirtyValues |= DXVA2_ProcAmp_Saturation; - - setProcAmpValues(); - - emit saturationChanged(saturation); -} - -IMFActivate* Evr9VideoWindowControl::currentActivate() const -{ - return m_currentActivate; -} - -void Evr9VideoWindowControl::setProcAmpValues() -{ - if (m_processor) { - DXVA2_ProcAmpValues values; - if (m_dirtyValues & DXVA2_ProcAmp_Brightness) { - values.Brightness = scaleProcAmpValue(DXVA2_ProcAmp_Brightness, m_brightness); - } - if (m_dirtyValues & DXVA2_ProcAmp_Contrast) { - values.Contrast = scaleProcAmpValue(DXVA2_ProcAmp_Contrast, m_contrast); - } - if (m_dirtyValues & DXVA2_ProcAmp_Hue) { - values.Hue = scaleProcAmpValue(DXVA2_ProcAmp_Hue, m_hue); - } - if (m_dirtyValues & DXVA2_ProcAmp_Saturation) { - values.Saturation = scaleProcAmpValue(DXVA2_ProcAmp_Saturation, m_saturation); - } - - if (SUCCEEDED(m_processor->SetProcAmpValues(0, &values))) { - m_dirtyValues = 0; - } - } -} - -DXVA2_Fixed32 Evr9VideoWindowControl::scaleProcAmpValue(DWORD prop, int value) const -{ - float scaledValue = 0.0; - - DXVA2_ValueRange range; - if (SUCCEEDED(m_processor->GetProcAmpRange(prop, &range))) { - scaledValue = DXVA2FixedToFloat(range.DefaultValue); - if (value > 0) - scaledValue += float(value) * (DXVA2FixedToFloat(range.MaxValue) - DXVA2FixedToFloat(range.DefaultValue)) / 100; - else if (value < 0) - scaledValue -= float(value) * (DXVA2FixedToFloat(range.MinValue) - DXVA2FixedToFloat(range.DefaultValue)) / 100; - } - - return DXVA2FloatToFixed(scaledValue); -} diff --git a/src/plugins/wmf/player/evr9videowindowcontrol.h b/src/plugins/wmf/player/evr9videowindowcontrol.h deleted file mode 100644 index a415243..0000000 --- a/src/plugins/wmf/player/evr9videowindowcontrol.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef EVR9VIDEOWINDOWCONTROL_H -#define EVR9VIDEOWINDOWCONTROL_H - -#include "../../src/multimedia/qvideowindowcontrol.h" - -#include <Mfidl.h> -#include <d3d9.h> -#include <Evr9.h> - -QT_USE_NAMESPACE - -class Evr9VideoWindowControl : public QVideoWindowControl -{ - Q_OBJECT -public: - Evr9VideoWindowControl(QObject *parent = 0); - ~Evr9VideoWindowControl(); - - WId winId() const; - void setWinId(WId id); - - QRect displayRect() const; - void setDisplayRect(const QRect &rect); - - bool isFullScreen() const; - void setFullScreen(bool fullScreen); - - void repaint(); - - QSize nativeSize() const; - - Qt::AspectRatioMode aspectRatioMode() const; - void setAspectRatioMode(Qt::AspectRatioMode mode); - - int brightness() const; - void setBrightness(int brightness); - - int contrast() const; - void setContrast(int contrast); - - int hue() const; - void setHue(int hue); - - int saturation() const; - void setSaturation(int saturation); - - IMFActivate* currentActivate() const; - -private: - void setProcAmpValues(); - DXVA2_Fixed32 scaleProcAmpValue(DWORD prop, int value) const; - - WId m_windowId; - COLORREF m_windowColor; - DWORD m_dirtyValues; - Qt::AspectRatioMode m_aspectRatioMode; - QRect m_displayRect; - int m_brightness; - int m_contrast; - int m_hue; - int m_saturation; - bool m_fullScreen; - - IMFActivate *m_currentActivate; - IMFMediaSink *m_evrSink; - IMFVideoDisplayControl *m_displayControl; - IMFVideoProcessor *m_processor; -}; - -#endif diff --git a/src/plugins/wmf/player/mfaudioendpointcontrol.cpp b/src/plugins/wmf/player/mfaudioendpointcontrol.cpp deleted file mode 100644 index 290afe5..0000000 --- a/src/plugins/wmf/player/mfaudioendpointcontrol.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "QtCore/qdebug.h" -#include "mfaudioendpointcontrol.h" - -MFAudioEndpointControl::MFAudioEndpointControl(QObject *parent) - : QAudioEndpointSelector(parent) - , m_currentActivate(0) -{ - updateEndpoints(); - setActiveEndpoint(m_defaultEndpoint); -} - -MFAudioEndpointControl::~MFAudioEndpointControl() -{ - foreach (LPWSTR wstrID, m_devices) - CoTaskMemFree(wstrID); - - if (m_currentActivate) - m_currentActivate->Release(); -} - -QList<QString> MFAudioEndpointControl::availableEndpoints() const -{ - return m_devices.keys(); -} - -QString MFAudioEndpointControl::endpointDescription(const QString &name) const -{ - return name.section(QLatin1Char('\\'), -1); -} - -QString MFAudioEndpointControl::defaultEndpoint() const -{ - return m_defaultEndpoint; -} - -QString MFAudioEndpointControl::activeEndpoint() const -{ - return m_activeEndpoint; -} - -void MFAudioEndpointControl::setActiveEndpoint(const QString &name) -{ - if (m_activeEndpoint == name) - return; - QMap<QString, LPWSTR>::iterator it = m_devices.find(name); - if (it == m_devices.end()) - return; - - LPWSTR wstrID = *it; - IMFActivate *activate = NULL; - HRESULT hr = MFCreateAudioRendererActivate(&activate); - if (FAILED(hr)) { - qWarning() << "Failed to create audio renderer activate"; - return; - } - - if (wstrID) { - hr = activate->SetString(MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ID, wstrID); - } else { - //This is the default one that has been inserted in updateEndpoints(), - //so give the activate a hint that we want to use the device for multimedia playback - //then the media foundation will choose an appropriate one. - - //from MSDN: - //The ERole enumeration defines constants that indicate the role that the system has assigned to an audio endpoint device. - //eMultimedia: Music, movies, narration, and live music recording. - hr = activate->SetUINT32(MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ROLE, eMultimedia); - } - - if (FAILED(hr)) { - qWarning() << "Failed to set attribute for audio device" << name; - return; - } - - if (m_currentActivate) - m_currentActivate->Release(); - m_currentActivate = activate; - m_activeEndpoint = name; -} - -IMFActivate* MFAudioEndpointControl::currentActivate() const -{ - return m_currentActivate; -} - -void MFAudioEndpointControl::updateEndpoints() -{ - m_defaultEndpoint = QString::fromLatin1("Default"); - m_devices.insert(m_defaultEndpoint, NULL); - - IMMDeviceEnumerator *pEnum = NULL; - HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), - NULL, CLSCTX_ALL, - __uuidof(IMMDeviceEnumerator), - (void**)&pEnum); - if (SUCCEEDED(hr)) { - IMMDeviceCollection *pDevices = NULL; - hr = pEnum->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &pDevices); - if (SUCCEEDED(hr)) { - UINT count; - hr = pDevices->GetCount(&count); - if (SUCCEEDED(hr)) { - for (UINT i = 0; i < count; ++i) { - IMMDevice *pDevice = NULL; - hr = pDevices->Item(i, &pDevice); - if (SUCCEEDED(hr)) { - LPWSTR wstrID = NULL; - hr = pDevice->GetId(&wstrID); - if (SUCCEEDED(hr)) { - QString deviceId = QString::fromWCharArray(wstrID); - m_devices.insert(deviceId, wstrID); - } - pDevice->Release(); - } - } - } - pDevices->Release(); - } - pEnum->Release(); - } -} diff --git a/src/plugins/wmf/player/mfaudioendpointcontrol.h b/src/plugins/wmf/player/mfaudioendpointcontrol.h deleted file mode 100644 index 67f7756..0000000 --- a/src/plugins/wmf/player/mfaudioendpointcontrol.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MFAUDIOENDPOINTCONTROL_H -#define MFAUDIOENDPOINTCONTROL_H - -#include <mfapi.h> -#include <mfidl.h> -#include <mmdeviceapi.h> - -#include "../../src/multimedia/qaudioendpointselector.h" - -class MFPlayerService; - -QT_USE_NAMESPACE - -class MFAudioEndpointControl : public QAudioEndpointSelector -{ - Q_OBJECT -public: - MFAudioEndpointControl(QObject *parent = 0); - ~MFAudioEndpointControl(); - - QList<QString> availableEndpoints() const; - - QString endpointDescription(const QString &name) const; - - QString defaultEndpoint() const; - QString activeEndpoint() const; - - void setActiveEndpoint(const QString& name); - - IMFActivate* currentActivate() const; - -private: - void updateEndpoints(); - - QString m_defaultEndpoint; - QString m_activeEndpoint; - QMap<QString, LPWSTR> m_devices; - IMFActivate *m_currentActivate; - -}; - -#endif - diff --git a/src/plugins/wmf/player/mfmetadatacontrol.cpp b/src/plugins/wmf/player/mfmetadatacontrol.cpp deleted file mode 100644 index 4e62706..0000000 --- a/src/plugins/wmf/player/mfmetadatacontrol.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "mfmetadatacontrol.h" -#include "mfplayerservice.h" -#include "Propkey.h" - -//#define DEBUG_MEDIAFOUNDATION - -MFMetaDataControl::MFMetaDataControl(QObject *parent) - : QMetaDataReaderControl(parent) - , m_metaData(0) - , m_content(0) -{ -} - -MFMetaDataControl::~MFMetaDataControl() -{ - if (m_metaData) - m_metaData->Release(); - if (m_content) - m_content->Release(); -} - -bool MFMetaDataControl::isMetaDataAvailable() const -{ - return m_content || m_metaData; -} - -QVariant MFMetaDataControl::metaData(QtMultimedia::MetaData key) const -{ - QVariant value; - if (!isMetaDataAvailable()) - return value; - - int index = m_availableMetaDatas.indexOf(key); - if (index < 0) - return value; - - PROPVARIANT var; - PropVariantInit(&var); - HRESULT hr = S_FALSE; - if (m_content) - hr = m_content->GetValue(m_commonKeys[index], &var); - else if (m_metaData) - hr = m_metaData->GetProperty(m_commonNames[index].utf16(), &var); - - if (SUCCEEDED(hr)) - value = convertValue(var); - - PropVariantClear(&var); - return value; -} - -QVariant MFMetaDataControl::convertValue(const PROPVARIANT& var) const -{ - QVariant value; - //form MSDN: http://msdn.microsoft.com/en-us/library/ff384862%28v=VS.85%29.aspx - //it seems that those 4 types are enough for media foundation metadata - //add more later if necessary - switch (var.vt) { - case VT_LPWSTR: - value = QString::fromUtf16(var.pwszVal); - break; - case VT_UI4: - value = uint(var.ulVal); - break; - case VT_UI8: - value = qulonglong(var.uhVal.QuadPart); - break; - case VT_BOOL: - value = bool(var.boolVal); - break; - } - return value; -} - -QList<QtMultimedia::MetaData> MFMetaDataControl::availableMetaData() const -{ - return m_availableMetaDatas; -} - -QVariant MFMetaDataControl::extendedMetaData(const QString &key) const -{ - QVariant value; - HRESULT hr = S_FALSE; - PROPVARIANT var; - PropVariantInit(&var); - if (m_content) { - int index = m_extendedMetaDatas.indexOf(key); - if (index >= 0) { - hr = m_content->GetValue(m_extendedKeys[index], &var); - } - } else if (m_metaData) { - hr = m_metaData->GetProperty(key.utf16(), &var); - } - - if (SUCCEEDED(hr)) - value = convertValue(var); - - PropVariantClear(&var); - return value; -} - -QStringList MFMetaDataControl::availableExtendedMetaData() const -{ - return m_extendedMetaDatas; -} - -void MFMetaDataControl::updateSource(IMFPresentationDescriptor* sourcePD, IMFMediaSource* mediaSource) -{ - if (m_metaData) { - m_metaData->Release(); - m_metaData = 0; - } - - if (m_content) { - m_content->Release(); - m_content = 0; - } - - m_availableMetaDatas.clear(); - m_commonKeys.clear(); - m_commonNames.clear(); - m_extendedMetaDatas.clear(); - m_extendedKeys.clear(); - - if (SUCCEEDED(MFGetService(mediaSource, MF_PROPERTY_HANDLER_SERVICE, IID_PPV_ARGS(&m_content)))) { - DWORD cProps; - if (SUCCEEDED(m_content->GetCount(&cProps))) { - for (DWORD i = 0; i < cProps; i++) - { - PROPERTYKEY key; - if (FAILED(m_content->GetAt(i, &key))) - continue; - bool common = true; - if (key == PKEY_Author) { - m_availableMetaDatas.push_back(QtMultimedia::Author); - } else if (key == PKEY_Title) { - m_availableMetaDatas.push_back(QtMultimedia::Title); - } else if (key == PKEY_ParentalRating) { - m_availableMetaDatas.push_back(QtMultimedia::ParentalRating); - } else if (key == PKEY_Comment) { - m_availableMetaDatas.push_back(QtMultimedia::Description); - } else if (key == PKEY_Copyright) { - m_availableMetaDatas.push_back(QtMultimedia::Copyright); - //TODO: add more common keys - } else { - common = false; - //TODO: add more extended keys - } - if (common) - m_commonKeys.push_back(key); - } - } else { - m_content->Release(); - m_content = NULL; - } - } - - if (!m_content) { - //fallback to Vista approach - IMFMetadataProvider *provider = NULL; - if (SUCCEEDED(MFGetService(mediaSource, MF_METADATA_PROVIDER_SERVICE, IID_PPV_ARGS(&provider)))) { - if (SUCCEEDED(provider->GetMFMetadata(sourcePD, 0, 0, &m_metaData))) { - PROPVARIANT varNames; - PropVariantInit(&varNames); - if (SUCCEEDED(m_metaData->GetAllPropertyNames(&varNames)) && varNames.vt == (VT_VECTOR | VT_LPWSTR)) { - ULONG cElements = varNames.calpwstr.cElems; - for (ULONG i = 0; i < cElements; i++) - { - const WCHAR* sName = varNames.calpwstr.pElems[i]; -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "metadata: " << QString::fromUtf16(sName); -#endif - bool common = true; - if (wcscmp(sName, L"Author") == 0) { - m_availableMetaDatas.push_back(QtMultimedia::Author); - } else if (wcscmp(sName, L"Title") == 0) { - m_availableMetaDatas.push_back(QtMultimedia::Title); - } else if (wcscmp(sName, L"Rating") == 0) { - m_availableMetaDatas.push_back(QtMultimedia::ParentalRating); - } else if (wcscmp(sName, L"Description") == 0) { - m_availableMetaDatas.push_back(QtMultimedia::Description); - } else if (wcscmp(sName, L"Copyright") == 0) { - m_availableMetaDatas.push_back(QtMultimedia::Copyright); - //TODO: add more common keys - } else { - common = false; - m_extendedMetaDatas.push_back(QString::fromUtf16(sName)); - } - if (common) - m_commonNames.push_back(QString::fromUtf16(sName)); - } - } - PropVariantClear(&varNames); - } else { - qWarning("Failed to get IMFMetadata"); - } - provider->Release(); - } else { - qWarning("Failed to get IMFMetadataProvider from source"); - } - } - - emit metaDataChanged(); - emit metaDataAvailableChanged(m_metaData || m_content); -} diff --git a/src/plugins/wmf/player/mfmetadatacontrol.h b/src/plugins/wmf/player/mfmetadatacontrol.h deleted file mode 100644 index a73b778..0000000 --- a/src/plugins/wmf/player/mfmetadatacontrol.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MFMETADATACONTROL_H -#define MFMETADATACONTROL_H - -#include <qmetadatareadercontrol.h> -#include "Mfidl.h" - -QT_USE_NAMESPACE - -class MFMetaDataControl : public QMetaDataReaderControl -{ - Q_OBJECT -public: - MFMetaDataControl(QObject *parent = 0); - ~MFMetaDataControl(); - - bool isMetaDataAvailable() const; - - QVariant metaData(QtMultimedia::MetaData key) const; - QList<QtMultimedia::MetaData> availableMetaData() const; - - QVariant extendedMetaData(const QString &key) const; - QStringList availableExtendedMetaData() const; - - void updateSource(IMFPresentationDescriptor* sourcePD, IMFMediaSource* mediaSource); - -private: - QVariant convertValue(const PROPVARIANT& var) const; - IPropertyStore *m_content; //for Windows7 - IMFMetadata *m_metaData; //for Vista - - QList<QtMultimedia::MetaData> m_availableMetaDatas; - QList<PROPERTYKEY> m_commonKeys; //for Windows7 - QStringList m_commonNames; //for Vista - - QStringList m_extendedMetaDatas; - QList<PROPERTYKEY> m_extendedKeys; //for Windows7 -}; - -#endif diff --git a/src/plugins/wmf/player/mfplayercontrol.cpp b/src/plugins/wmf/player/mfplayercontrol.cpp deleted file mode 100644 index e3a3d80..0000000 --- a/src/plugins/wmf/player/mfplayercontrol.cpp +++ /dev/null @@ -1,317 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "mfplayercontrol.h" -#include <qtcore/qdebug.h> - -//#define DEBUG_MEDIAFOUNDATION - -MFPlayerControl::MFPlayerControl(MFPlayerSession *session) -: QMediaPlayerControl(session) -, m_state(QMediaPlayer::StoppedState) -, m_videoAvailable(false) -, m_audioAvailable(false) -, m_duration(-1) -, m_seekable(false) -, m_session(session) -{ - QObject::connect(m_session, SIGNAL(statusChanged()), this, SLOT(handleStatusChanged())); - QObject::connect(m_session, SIGNAL(videoAvailable()), this, SLOT(handleVideoAvailable())); - QObject::connect(m_session, SIGNAL(audioAvailable()), this, SLOT(handleAudioAvailable())); - QObject::connect(m_session, SIGNAL(durationUpdate(qint64)), this, SLOT(handleDurationUpdate(qint64))); - QObject::connect(m_session, SIGNAL(seekableUpdate(bool)), this, SLOT(handleSeekableUpdate(bool))); - QObject::connect(m_session, SIGNAL(error(QMediaPlayer::Error, QString, bool)), this, SLOT(handleError(QMediaPlayer::Error, QString, bool))); - QObject::connect(m_session, SIGNAL(positionChanged(qint64)), this, SIGNAL(positionChanged(qint64))); - QObject::connect(m_session, SIGNAL(volumeChanged(int)), this, SIGNAL(volumeChanged(int))); - QObject::connect(m_session, SIGNAL(mutedChanged(bool)), this, SIGNAL(mutedChanged(bool))); - QObject::connect(m_session, SIGNAL(playbackRateChanged(qreal)), this, SIGNAL(playbackRateChanged(qreal))); - QObject::connect(m_session, SIGNAL(bufferStatusChanged(int)), this, SIGNAL(bufferStatusChanged(int))); -} - -MFPlayerControl::~MFPlayerControl() -{ -} - -void MFPlayerControl::setMedia(const QMediaContent &media, QIODevice *stream) -{ - if (m_state != QMediaPlayer::StoppedState) { - changeState(QMediaPlayer::StoppedState); - m_session->stop(true); - refreshState(); - } - - m_media = media; - m_stream = stream; - resetAudioVideoAvailable(); - handleDurationUpdate(-1); - handleSeekableUpdate(false); - m_session->load(media, stream); - emit mediaChanged(m_media); -} - -void MFPlayerControl::play() -{ - if (m_state == QMediaPlayer::PlayingState) - return; - if (QMediaPlayer::InvalidMedia == m_session->status()) - m_session->load(m_media, m_stream); - - switch (m_session->status()) { - case QMediaPlayer::UnknownMediaStatus: - case QMediaPlayer::NoMedia: - case QMediaPlayer::InvalidMedia: - return; - case QMediaPlayer::LoadedMedia: - case QMediaPlayer::BufferingMedia: - case QMediaPlayer::BufferedMedia: - case QMediaPlayer::EndOfMedia: - changeState(QMediaPlayer::PlayingState); - m_session->start(); - break; - default: //Loading/Stalled - changeState(QMediaPlayer::PlayingState); - break; - } - refreshState(); -} - -void MFPlayerControl::pause() -{ - if (m_state != QMediaPlayer::PlayingState) - return; - changeState(QMediaPlayer::PausedState); - m_session->pause(); - refreshState(); -} - -void MFPlayerControl::stop() -{ - if (m_state == QMediaPlayer::StoppedState) - return; - changeState(QMediaPlayer::StoppedState); - m_session->stop(); - refreshState(); -} - -void MFPlayerControl::changeState(QMediaPlayer::State state) -{ - if (m_state == state) - return; - m_state = state; - m_stateDirty = true; -} - -void MFPlayerControl::refreshState() -{ - if (!m_stateDirty) - return; - m_stateDirty = false; -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "MFPlayerControl::emit stateChanged" << m_state; -#endif - emit stateChanged(m_state); -} - -void MFPlayerControl::handleStatusChanged() -{ - QMediaPlayer::MediaStatus status = m_session->status(); - switch (status) { - case QMediaPlayer::EndOfMedia: - changeState(QMediaPlayer::StoppedState); - break; - case QMediaPlayer::InvalidMedia: - break; - case QMediaPlayer::LoadedMedia: - case QMediaPlayer::BufferingMedia: - case QMediaPlayer::BufferedMedia: - if (m_state == QMediaPlayer::PlayingState) - m_session->start(); - break; - } - emit mediaStatusChanged(m_session->status()); - refreshState(); -} - -void MFPlayerControl::handleVideoAvailable() -{ - if (m_videoAvailable) - return; - m_videoAvailable = true; - emit videoAvailableChanged(m_videoAvailable); -} - -void MFPlayerControl::handleAudioAvailable() -{ - if (m_audioAvailable) - return; - m_audioAvailable = true; - emit audioAvailableChanged(m_audioAvailable); -} - -void MFPlayerControl::resetAudioVideoAvailable() -{ - bool videoDirty = false; - if (m_videoAvailable) { - m_videoAvailable = false; - videoDirty = true; - } - if (m_audioAvailable) { - m_audioAvailable = false; - emit audioAvailableChanged(m_audioAvailable); - } - if (videoDirty) - emit videoAvailableChanged(m_videoAvailable); -} - -void MFPlayerControl::handleDurationUpdate(qint64 duration) -{ - if (m_duration == duration) - return; - m_duration = duration; - emit durationChanged(m_duration); -} - -void MFPlayerControl::handleSeekableUpdate(bool seekable) -{ - if (m_seekable == seekable) - return; - m_seekable = seekable; - emit seekableChanged(m_seekable); -} - -QMediaPlayer::State MFPlayerControl::state() const -{ - return m_state; -} - -QMediaPlayer::MediaStatus MFPlayerControl::mediaStatus() const -{ - return m_session->status(); -} - -qint64 MFPlayerControl::duration() const -{ - return m_duration; -} - -qint64 MFPlayerControl::position() const -{ - return m_session->position(); -} - -void MFPlayerControl::setPosition(qint64 position) -{ - if (!m_seekable || position == m_session->position()) - return; - m_session->setPosition(position); -} - -int MFPlayerControl::volume() const -{ - return m_session->volume(); -} - -void MFPlayerControl::setVolume(int volume) -{ - m_session->setVolume(volume); -} - -bool MFPlayerControl::isMuted() const -{ - return m_session->isMuted(); -} - -void MFPlayerControl::setMuted(bool muted) -{ - m_session->setMuted(muted); -} - -int MFPlayerControl::bufferStatus() const -{ - return m_session->bufferStatus(); -} - -bool MFPlayerControl::isAudioAvailable() const -{ - return m_audioAvailable; -} - -bool MFPlayerControl::isVideoAvailable() const -{ - return m_videoAvailable; -} - -bool MFPlayerControl::isSeekable() const -{ - return m_seekable; -} - -QMediaTimeRange MFPlayerControl::availablePlaybackRanges() const -{ - return m_session->availablePlaybackRanges(); -} - -qreal MFPlayerControl::playbackRate() const -{ - return m_session->playbackRate(); -} - -void MFPlayerControl::setPlaybackRate(qreal rate) -{ - m_session->setPlaybackRate(rate); -} - -QMediaContent MFPlayerControl::media() const -{ - return m_media; -} - -const QIODevice* MFPlayerControl::mediaStream() const -{ - return m_stream; -} - -void MFPlayerControl::handleError(QMediaPlayer::Error errorCode, const QString& errorString, bool isFatal) -{ - if (isFatal) - stop(); - emit error(int(errorCode), errorString); -} diff --git a/src/plugins/wmf/player/mfplayercontrol.h b/src/plugins/wmf/player/mfplayercontrol.h deleted file mode 100644 index 0256b89..0000000 --- a/src/plugins/wmf/player/mfplayercontrol.h +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MFPLAYERCONTROL_H -#define MFPLAYERCONTROL_H - -#include "qmediacontent.h" -#include "qmediaplayercontrol.h" - -#include <QtCore/qcoreevent.h> - -#include "mfplayersession.h" - -QT_USE_NAMESPACE - -class MFPlayerControl : public QMediaPlayerControl -{ - Q_OBJECT -public: - MFPlayerControl(MFPlayerSession *session); - ~MFPlayerControl(); - - QMediaPlayer::State state() const; - - QMediaPlayer::MediaStatus mediaStatus() const; - - qint64 duration() const; - - qint64 position() const; - void setPosition(qint64 position); - - int volume() const; - void setVolume(int volume); - - bool isMuted() const; - void setMuted(bool muted); - - int bufferStatus() const; - - bool isAudioAvailable() const; - bool isVideoAvailable() const; - - bool isSeekable() const; - - QMediaTimeRange availablePlaybackRanges() const; - - qreal playbackRate() const; - void setPlaybackRate(qreal rate); - - QMediaContent media() const; - const QIODevice *mediaStream() const; - void setMedia(const QMediaContent &media, QIODevice *stream); - - void play(); - void pause(); - void stop(); - -private Q_SLOTS: - void handleStatusChanged(); - void handleVideoAvailable(); - void handleAudioAvailable(); - void handleDurationUpdate(qint64 duration); - void handleSeekableUpdate(bool seekable); - void handleError(QMediaPlayer::Error errorCode, const QString& errorString, bool isFatal); - -private: - void changeState(QMediaPlayer::State state); - void resetAudioVideoAvailable(); - void refreshState(); - - QMediaPlayer::State m_state; - bool m_stateDirty; - QMediaPlayer::MediaStatus m_status; - QMediaPlayer::Error m_error; - - bool m_videoAvailable; - bool m_audioAvailable; - qint64 m_duration; - bool m_seekable; - - QIODevice *m_stream; - QMediaContent m_media; - MFPlayerSession *m_session; -}; - -#endif diff --git a/src/plugins/wmf/player/mfplayerservice.cpp b/src/plugins/wmf/player/mfplayerservice.cpp deleted file mode 100644 index bda86a3..0000000 --- a/src/plugins/wmf/player/mfplayerservice.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmediacontent.h" - -#include <QtCore/qdebug.h> - -#include "mfplayercontrol.h" -#ifndef Q_WS_SIMULATOR -#include "evr9videowindowcontrol.h" -#endif -#include "mfvideorenderercontrol.h" -#include "mfaudioendpointcontrol.h" -#include "mfplayerservice.h" -#include "mfplayersession.h" -#include "mfmetadatacontrol.h" - -MFPlayerService::MFPlayerService(QObject *parent) - : QMediaService(parent) - , m_session(0) -#ifndef Q_WS_SIMULATOR - , m_videoWindowControl(0) -#endif - , m_videoRendererControl(0) -{ - CoInitialize(NULL); - MFStartup(MF_VERSION); - m_session = new MFPlayerSession(this); - m_player = new MFPlayerControl(m_session); - m_audioEndpointControl = new MFAudioEndpointControl(this); - m_metaDataControl = new MFMetaDataControl(this); -} - -MFPlayerService::~MFPlayerService() -{ - -#ifndef Q_WS_SIMULATOR - if (m_videoWindowControl) - delete m_videoWindowControl; -#endif - - if (m_videoRendererControl) - delete m_videoRendererControl; - - delete m_session; - - MFShutdown(); - CoUninitialize(); -} - -QMediaControl* MFPlayerService::requestControl(const char *name) -{ - if (qstrcmp(name, QMediaPlayerControl_iid) == 0) { - return m_player; - } else if (qstrcmp(name, QAudioEndpointSelector_iid) == 0) { - return m_audioEndpointControl; - } else if (qstrcmp(name, QMetaDataReaderControl_iid) == 0) { - return m_metaDataControl; - } else if (qstrcmp(name, QVideoRendererControl_iid) == 0) { -#ifndef Q_WS_SIMULATOR - if (!m_videoRendererControl && !m_videoWindowControl) { -#else - if (!m_videoRendererControl) { -#endif - m_videoRendererControl = new MFVideoRendererControl; - return m_videoRendererControl; - } -#ifndef Q_WS_SIMULATOR - } else if (qstrcmp(name, QVideoWindowControl_iid) == 0) { - if (!m_videoRendererControl && !m_videoWindowControl) { - m_videoWindowControl = new Evr9VideoWindowControl; - return m_videoWindowControl; - } -#endif - } - - return 0; -} - -void MFPlayerService::releaseControl(QMediaControl *control) -{ - if (!control) { - qWarning("QMediaService::releaseControl():" - " Attempted release of null control"); - } else if (control == m_videoRendererControl) { - m_videoRendererControl->setSurface(0); - delete m_videoRendererControl; - m_videoRendererControl = 0; -#ifndef Q_WS_SIMULATOR - } else if (control == m_videoWindowControl) { - delete m_videoWindowControl; - m_videoWindowControl = 0; -#endif - } -} - -MFAudioEndpointControl* MFPlayerService::audioEndpointControl() const -{ - return m_audioEndpointControl; -} - -MFVideoRendererControl* MFPlayerService::videoRendererControl() const -{ - return m_videoRendererControl; -} - -#ifndef Q_WS_SIMULATOR -Evr9VideoWindowControl* MFPlayerService::videoWindowControl() const -{ - return m_videoWindowControl; -} -#endif - -MFMetaDataControl* MFPlayerService::metaDataControl() const -{ - return m_metaDataControl; -} diff --git a/src/plugins/wmf/player/mfplayerservice.h b/src/plugins/wmf/player/mfplayerservice.h deleted file mode 100644 index 1e8a617..0000000 --- a/src/plugins/wmf/player/mfplayerservice.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MFPLAYERSERVICE_H -#define MFPLAYERSERVICE_H - -#include <mfapi.h> -#include <mfidl.h> - -#include "qmediaplayer.h" -#include "qmediaresource.h" -#include "qmediaservice.h" -#include "qmediatimerange.h" - -QT_BEGIN_NAMESPACE -class QMediaContent; -QT_END_NAMESPACE - -QT_USE_NAMESPACE - -#ifndef Q_WS_SIMULATOR -class Evr9VideoWindowControl; -#endif -class MFAudioEndpointControl; -class MFVideoRendererControl; -class MFPlayerControl; -class MFMetaDataControl; -class MFPlayerSession; - -class MFPlayerService : public QMediaService -{ - Q_OBJECT -public: - MFPlayerService(QObject *parent = 0); - ~MFPlayerService(); - - QMediaControl* requestControl(const char *name); - void releaseControl(QMediaControl *control); - - MFAudioEndpointControl* audioEndpointControl() const; - MFVideoRendererControl* videoRendererControl() const; -#ifndef Q_WS_SIMULATOR - Evr9VideoWindowControl* videoWindowControl() const; -#endif - MFMetaDataControl* metaDataControl() const; - -private: - MFPlayerSession *m_session; - MFVideoRendererControl *m_videoRendererControl; - MFAudioEndpointControl *m_audioEndpointControl; -#ifndef Q_WS_SIMULATOR - Evr9VideoWindowControl *m_videoWindowControl; -#endif - MFPlayerControl *m_player; - MFMetaDataControl *m_metaDataControl; -}; - -#endif diff --git a/src/plugins/wmf/player/mfplayersession.cpp b/src/plugins/wmf/player/mfplayersession.cpp deleted file mode 100644 index afe91da..0000000 --- a/src/plugins/wmf/player/mfplayersession.cpp +++ /dev/null @@ -1,1393 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmediacontent.h" -#include "qmediaplayercontrol.h" - -#include <QtCore/qcoreapplication.h> -#include <QtCore/qdatetime.h> -#include <QtCore/qthread.h> -#include <QtCore/qvarlengtharray.h> -#include <QtCore/qdebug.h> -#include <QtCore/qfile.h> -#include <QtCore/qbuffer.h> - -#include "mfplayercontrol.h" -#ifndef Q_WS_SIMULATOR -#include "evr9videowindowcontrol.h" -#endif -#include "mfvideorenderercontrol.h" -#include "mfaudioendpointcontrol.h" - -#include "mfplayersession.h" -#include "mfplayerservice.h" -#include "mfmetadatacontrol.h" -#include <Mferror.h> -#include <nserror.h> -#include <sourceresolver.h> - -//#define DEBUG_MEDIAFOUNDATION -//#define TEST_STREAMING - -namespace -{ - //MFStream is added for supporting QIODevice type of media source. - //It is used to delegate invocations from media foundation(through IMFByteStream) to QIODevice. - class MFStream : public QObject, public IMFByteStream - { - Q_OBJECT - public: - MFStream(QIODevice *stream, bool ownStream) - : m_cRef(1) - , m_stream(stream) - , m_ownStream(ownStream) - , m_currentReadResult(0) - { - //Move to the thread of the stream object - //to make sure invocations on stream - //are happened in the same thread of stream object - this->moveToThread(stream->thread()); - connect(stream, SIGNAL(readyRead()), this, SLOT(handleReadyRead())); - } - - ~MFStream() - { - if (m_currentReadResult) - m_currentReadResult->Release(); - if (m_ownStream) - m_stream->deleteLater(); - } - - //from IUnknown - STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject) - { - if (!ppvObject) - return E_POINTER; - if (riid == IID_IMFByteStream) { - *ppvObject = static_cast<IMFByteStream*>(this); - } else if (riid == IID_IUnknown) { - *ppvObject = static_cast<IUnknown*>(this); - } else { - *ppvObject = NULL; - return E_NOINTERFACE; - } - AddRef(); - return S_OK; - } - - STDMETHODIMP_(ULONG) AddRef(void) - { - return InterlockedIncrement(&m_cRef); - } - - STDMETHODIMP_(ULONG) Release(void) - { - LONG cRef = InterlockedDecrement(&m_cRef); - if (cRef == 0) { - this->deleteLater(); - } - return cRef; - } - - - //from IMFByteStream - STDMETHODIMP GetCapabilities(DWORD *pdwCapabilities) - { - if (!pdwCapabilities) - return E_INVALIDARG; - *pdwCapabilities = MFBYTESTREAM_IS_READABLE; - if (!m_stream->isSequential()) - *pdwCapabilities |= MFBYTESTREAM_IS_SEEKABLE; - return S_OK; - } - - STDMETHODIMP GetLength(QWORD *pqwLength) - { - if (!pqwLength) - return E_INVALIDARG; - QMutexLocker locker(&m_mutex); - *pqwLength = QWORD(m_stream->size()); - return S_OK; - } - - STDMETHODIMP SetLength(QWORD) - { - return E_NOTIMPL; - } - - STDMETHODIMP GetCurrentPosition(QWORD *pqwPosition) - { - if (!pqwPosition) - return E_INVALIDARG; - QMutexLocker locker(&m_mutex); - *pqwPosition = m_stream->pos(); - return S_OK; - } - - STDMETHODIMP SetCurrentPosition(QWORD qwPosition) - { - QMutexLocker locker(&m_mutex); - //SetCurrentPosition may happend during the BeginRead/EndRead pair, - //refusing to execute SetCurrentPosition during that time seems to be - //the simplest workable solution - if (m_currentReadResult) - return S_FALSE; - - bool seekOK = m_stream->seek(qint64(qwPosition)); - if (seekOK) - return S_OK; - else - return S_FALSE; - } - - STDMETHODIMP IsEndOfStream(BOOL *pfEndOfStream) - { - if (!pfEndOfStream) - return E_INVALIDARG; - QMutexLocker locker(&m_mutex); - *pfEndOfStream = m_stream->atEnd() ? TRUE : FALSE; - return S_OK; - } - - STDMETHODIMP Read(BYTE *pb, ULONG cb, ULONG *pcbRead) - { - QMutexLocker locker(&m_mutex); - qint64 read = m_stream->read((char*)(pb), qint64(cb)); - if (pcbRead) - *pcbRead = ULONG(read); - return S_OK; - } - - STDMETHODIMP BeginRead(BYTE *pb, ULONG cb, IMFAsyncCallback *pCallback, - IUnknown *punkState) - { - if (!pCallback || !pb) - return E_INVALIDARG; - - Q_ASSERT(m_currentReadResult == NULL); - - AsyncReadState *state = new (std::nothrow) AsyncReadState(pb, cb); - if (state == NULL) - return E_OUTOFMEMORY; - - HRESULT hr = MFCreateAsyncResult(state, pCallback, punkState, &m_currentReadResult); - state->Release(); - if (FAILED(hr)) - return hr; - - QCoreApplication::postEvent(this, new QEvent(QEvent::User)); - return hr; - } - - STDMETHODIMP EndRead(IMFAsyncResult* pResult, ULONG *pcbRead) - { - if (!pcbRead) - return E_INVALIDARG; - IUnknown *pUnk; - pResult->GetObject(&pUnk); - AsyncReadState *state = static_cast<AsyncReadState*>(pUnk); - *pcbRead = state->bytesRead(); - pUnk->Release(); - - m_currentReadResult->Release(); - m_currentReadResult = NULL; - - return S_OK; - } - - STDMETHODIMP Write(const BYTE *, ULONG, ULONG *) - { - return E_NOTIMPL; - } - - STDMETHODIMP BeginWrite(const BYTE *, ULONG , - IMFAsyncCallback *, - IUnknown *) - { - return E_NOTIMPL; - } - - STDMETHODIMP EndWrite(IMFAsyncResult *, - ULONG *) - { - return E_NOTIMPL; - } - - STDMETHODIMP Seek( - MFBYTESTREAM_SEEK_ORIGIN SeekOrigin, - LONGLONG llSeekOffset, - DWORD, - QWORD *pqwCurrentPosition) - { - QMutexLocker locker(&m_mutex); - if (m_currentReadResult) - return S_FALSE; - - qint64 pos = qint64(llSeekOffset); - switch (SeekOrigin) { - case msoCurrent: - pos += m_stream->pos(); - break; - } - bool seekOK = m_stream->seek(pos); - if (*pqwCurrentPosition) - *pqwCurrentPosition = pos; - if (seekOK) - return S_OK; - else - return S_FALSE; - } - - STDMETHODIMP Flush() - { - return E_NOTIMPL; - } - - STDMETHODIMP Close() - { - QMutexLocker locker(&m_mutex); - if (m_ownStream) - m_stream->close(); - return S_OK; - } - - private: - //AsyncReadState is a helper class used in BeginRead for asynchronous operation - //to record some BeginRead parameters, so these parameters could be - //used later when actually executing the read operation in another thread. - class AsyncReadState : public IUnknown - { - public: - AsyncReadState(BYTE *pb, ULONG cb) - : m_cRef(1) - , m_pb(pb) - , m_cb(cb) - , m_cbRead(0) - { - } - - //from IUnknown - STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject) - { - if (!ppvObject) - return E_POINTER; - - if (riid == IID_IUnknown) { - *ppvObject = static_cast<IUnknown*>(this); - } else { - *ppvObject = NULL; - return E_NOINTERFACE; - } - AddRef(); - return S_OK; - } - - STDMETHODIMP_(ULONG) AddRef(void) - { - return InterlockedIncrement(&m_cRef); - } - - STDMETHODIMP_(ULONG) Release(void) - { - LONG cRef = InterlockedDecrement(&m_cRef); - if (cRef == 0) - delete this; - // For thread safety, return a temporary variable. - return cRef; - } - - BYTE* pb() const { return m_pb; } - ULONG cb() const { return m_cb; } - ULONG bytesRead() const { return m_cbRead; } - - void setBytesRead(ULONG cbRead) { m_cbRead = cbRead; } - - private: - long m_cRef; - BYTE *m_pb; - ULONG m_cb; - ULONG m_cbRead; - }; - - long m_cRef; - QIODevice *m_stream; - bool m_ownStream; - DWORD m_workQueueId; - QMutex m_mutex; - - void doRead() - { - bool readDone = true; - IUnknown *pUnk = NULL; - HRESULT hr = m_currentReadResult->GetObject(&pUnk); - if (SUCCEEDED(hr)) { - //do actual read - AsyncReadState *state = static_cast<AsyncReadState*>(pUnk); - ULONG cbRead; - Read(state->pb(), state->cb() - state->bytesRead(), &cbRead); - pUnk->Release(); - - state->setBytesRead(cbRead + state->bytesRead()); - if (state->cb() > state->bytesRead() && !m_stream->atEnd()) { - readDone = false; - } - } - - if (readDone) { - //now inform the original caller - m_currentReadResult->SetStatus(hr); - MFInvokeCallback(m_currentReadResult); - } - } - - - private Q_SLOTS: - void handleReadyRead() - { - doRead(); - } - - protected: - void customEvent(QEvent *event) - { - if (event->type() != QEvent::User) { - QObject::customEvent(event); - return; - } - doRead(); - } - IMFAsyncResult *m_currentReadResult; - }; -} - - -MFPlayerSession::MFPlayerSession(QObject *parent) - : QObject(parent) - , m_session(0) - , m_presentationClock(0) - , m_rateControl(0) - , m_rateSupport(0) - , m_volumeControl(0) - , m_netsourceStatistics(0) - , m_hCloseEvent(0) - , m_pendingRate(1) - , m_volume(1) - , m_muted(false) - , m_status(QMediaPlayer::NoMedia) - , m_scrubbing(false) - , m_restoreRate(1) - , m_mediaTypes(0) -{ - m_hCloseEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - m_sourceResolver = new SourceResolver(this); - QObject::connect(m_sourceResolver, SIGNAL(mediaSourceReady()), this, SLOT(handleMediaSourceReady())); - QObject::connect(m_sourceResolver, SIGNAL(error(long)), this, SLOT(handleSourceError(long))); - QObject::connect(this, SIGNAL(sessionEvent(IMFMediaEvent *)), this, SLOT(handleSessionEvent(IMFMediaEvent *))); - - m_pendingState = NoPending; - ZeroMemory(&m_state, sizeof(m_state)); - m_state.command = CmdStop; - m_state.prevCmd = CmdNone; - m_state.rate = 1.0f; - ZeroMemory(&m_request, sizeof(m_request)); - m_request.command = CmdNone; - m_request.prevCmd = CmdNone; - m_request.rate = 1.0f; - - createSession(); - PropVariantInit(&m_varStart); - m_varStart.vt = VT_I8; - m_varStart.uhVal.QuadPart = 0; -} - -MFPlayerSession::~MFPlayerSession() -{ - m_sourceResolver->Release(); - clear(); - HRESULT hr = S_OK; - if (m_session) { - hr = m_session->Close(); - if (SUCCEEDED(hr)) { - DWORD dwWaitResult = WaitForSingleObject(m_hCloseEvent, 5000); - if (dwWaitResult == WAIT_TIMEOUT) { - qWarning() << "session close time out!"; - } - } - } - - if (SUCCEEDED(hr)) { - m_sourceResolver->shutdown(); - if (m_session) - m_session->Shutdown(); - } - - if (m_session) - m_session->Release(); - - CloseHandle(m_hCloseEvent); -} - - -void MFPlayerSession::load(const QMediaContent &media, QIODevice *stream) -{ -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "load"; -#endif - clear(); - QMediaResourceList resources = media.resources(); - - if (m_status == QMediaPlayer::LoadingMedia) - m_sourceResolver->cancel(); - - if (resources.isEmpty() && !stream) { - changeStatus(QMediaPlayer::NoMedia); - } else if (stream && (!stream->isReadable())) { - changeStatus(QMediaPlayer::InvalidMedia); - emit error(QMediaPlayer::ResourceError, tr("Invalid stream source!"), true); - } else { - changeStatus(QMediaPlayer::LoadingMedia); - m_sourceResolver->load(resources, stream); - } - emit positionChanged(position()); -} - -void MFPlayerSession::handleSourceError(long hr) -{ - QString errorString; - QMediaPlayer::Error errorCode = QMediaPlayer::ResourceError; - switch (hr) { - case QMediaPlayer::FormatError: - errorCode = QMediaPlayer::FormatError; - errorString = tr("Attempting to play invalid Qt resource"); - break; - case NS_E_FILE_NOT_FOUND: - errorString = tr("The system cannot find the file specified."); - break; - case NS_E_SERVER_NOT_FOUND: - errorString = tr("The specified server could not be found."); - break; - default: - errorString = tr("Failed to load source."); - break; - } - changeStatus(QMediaPlayer::InvalidMedia); - emit error(errorCode, errorString, true); -} - -void MFPlayerSession::handleMediaSourceReady() -{ - if (QMediaPlayer::LoadingMedia != m_status) - return; -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "handleMediaSourceReady"; -#endif - HRESULT hr = S_OK; - IMFPresentationDescriptor* sourcePD; - IMFMediaSource* mediaSource = m_sourceResolver->mediaSource(); - hr = mediaSource->CreatePresentationDescriptor(&sourcePD); - if (SUCCEEDED(hr)) { - m_duration = 0; - static_cast<MFPlayerService*>(this->parent())->metaDataControl()->updateSource(sourcePD, mediaSource); - sourcePD->GetUINT64(MF_PD_DURATION, &m_duration); - //convert from 100 nanosecond to milisecond - emit durationUpdate(qint64(m_duration / 10000)); - setupPlaybackTopology(mediaSource, sourcePD); - } else { - changeStatus(QMediaPlayer::InvalidMedia); - emit error(QMediaPlayer::ResourceError, tr("Can't create presentation descriptor!"), true); - } -} - -void MFPlayerSession::setupPlaybackTopology(IMFMediaSource *source, IMFPresentationDescriptor *sourcePD) -{ - HRESULT hr = S_OK; - // Get the number of streams in the media source. - DWORD cSourceStreams = 0; - hr = sourcePD->GetStreamDescriptorCount(&cSourceStreams); - if (FAILED(hr)) { - changeStatus(QMediaPlayer::UnknownMediaStatus); - emit error(QMediaPlayer::ResourceError, tr("Failed to get stream count"), true); - return; - } - - IMFTopology *topology; - hr = MFCreateTopology(&topology); - if (FAILED(hr)) { - changeStatus(QMediaPlayer::UnknownMediaStatus); - emit error(QMediaPlayer::ResourceError, tr("Failed to create topology!"), true); - return; - } - - // For each stream, create the topology nodes and add them to the topology. - DWORD succeededCount = 0; - for (DWORD i = 0; i < cSourceStreams; i++) - { - BOOL fSelected = FALSE; - IMFStreamDescriptor *streamDesc = NULL; - - HRESULT hr = sourcePD->GetStreamDescriptorByIndex(i, &fSelected, &streamDesc); - if (SUCCEEDED(hr)) { - MediaType mediaType = Unknown; - IMFTopologyNode *sourceNode = addSourceNode(topology, source, sourcePD, streamDesc); - if (sourceNode) { - IMFTopologyNode *outputNode = addOutputNode(streamDesc, mediaType, topology, 0); - if (outputNode) { - hr = sourceNode->ConnectOutput(0, outputNode, 0); - if (FAILED(hr)) { - emit error(QMediaPlayer::FormatError, tr("Unable to play some stream"), false); - } - else { - succeededCount++; - m_mediaTypes |= mediaType; - switch (mediaType) { - case Audio: - emit audioAvailable(); - break; - case Video: - emit videoAvailable(); - break; - } - } - } - sourceNode->Release(); - } - streamDesc->Release(); - } - } - - if (succeededCount == 0) { - changeStatus(QMediaPlayer::InvalidMedia); - emit error(QMediaPlayer::ResourceError, tr("Unable to play"), true); - } else { - hr = m_session->SetTopology(MFSESSION_SETTOPOLOGY_IMMEDIATE, topology); - if (FAILED(hr)) { - changeStatus(QMediaPlayer::UnknownMediaStatus); - emit error(QMediaPlayer::ResourceError, tr("Failed to set topology!"), true); - } - } - topology->Release(); -} - -IMFTopologyNode* MFPlayerSession::addSourceNode(IMFTopology* topology, IMFMediaSource* source, - IMFPresentationDescriptor* presentationDesc, IMFStreamDescriptor *streamDesc) -{ - IMFTopologyNode *node = NULL; - HRESULT hr = MFCreateTopologyNode(MF_TOPOLOGY_SOURCESTREAM_NODE, &node); - if (SUCCEEDED(hr)) { - hr = node->SetUnknown(MF_TOPONODE_SOURCE, source); - if (SUCCEEDED(hr)) { - hr = node->SetUnknown(MF_TOPONODE_PRESENTATION_DESCRIPTOR, presentationDesc); - if (SUCCEEDED(hr)) { - hr = node->SetUnknown(MF_TOPONODE_STREAM_DESCRIPTOR, streamDesc); - if (SUCCEEDED(hr)) { - hr = topology->AddNode(node); - if (SUCCEEDED(hr)) - return node; - } - } - } - node->Release(); - } - return NULL; -} - -IMFTopologyNode* MFPlayerSession::addOutputNode(IMFStreamDescriptor *streamDesc, MediaType& mediaType, IMFTopology* topology, DWORD sinkID) -{ - IMFTopologyNode *node = NULL; - HRESULT hr = MFCreateTopologyNode(MF_TOPOLOGY_OUTPUT_NODE, &node); - if (FAILED(hr)) - return NULL; - node->SetUINT32(MF_TOPONODE_NOSHUTDOWN_ON_REMOVE, FALSE); - - mediaType = Unknown; - IMFMediaTypeHandler *handler = NULL; - hr = streamDesc->GetMediaTypeHandler(&handler); - if (SUCCEEDED(hr)) { - GUID guidMajorType; - hr = handler->GetMajorType(&guidMajorType); - if (SUCCEEDED(hr)) { - IMFActivate *activate = NULL; - MFPlayerService *service = static_cast<MFPlayerService*>(this->parent()); - if (MFMediaType_Audio == guidMajorType) { - mediaType = Audio; - activate = service->audioEndpointControl()->currentActivate(); - } else if (MFMediaType_Video == guidMajorType) { - mediaType = Video; - if (service->videoRendererControl()) { - activate = service->videoRendererControl()->currentActivate(); -#ifndef Q_WS_SIMULATOR - } else if (service->videoWindowControl()) { - activate = service->videoWindowControl()->currentActivate(); -#endif - } else { - qWarning() << "no videoWindowControl or videoRendererControl, unable to add output node for video data"; - } - } else { - // Unknown stream type. - emit error(QMediaPlayer::FormatError, tr("Unknown stream type"), false); - } - - if (activate) { - hr = node->SetObject(activate); - if (SUCCEEDED(hr)) { - hr = node->SetUINT32(MF_TOPONODE_STREAMID, sinkID); - if (SUCCEEDED(hr)) { - if (SUCCEEDED(topology->AddNode(node))) - return node; - } - } - } - } - } - node->Release(); - return NULL; -} - -void MFPlayerSession::stop(bool immediate) -{ -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "stop"; -#endif - if (!immediate && m_pendingState != NoPending) { - m_request.setCommand(CmdStop); - } else { - if (m_state.command == CmdStop) - return; - - if (m_scrubbing) - scrub(false); - - if (SUCCEEDED(m_session->Stop())) { - m_state.setCommand(CmdStop); - m_pendingState = CmdPending; - if (m_status != QMediaPlayer::EndOfMedia) { - m_varStart.vt = VT_I8; - m_varStart.hVal.QuadPart = 0; - } - } else { - emit error(QMediaPlayer::ResourceError, tr("failed to stop"), true); - } - } -} - -void MFPlayerSession::start() -{ - switch (m_status) { - case QMediaPlayer::EndOfMedia: - m_varStart.hVal.QuadPart = 0; - //since it must be loaded already, just fallthrough - case QMediaPlayer::LoadedMedia: - changeStatus(QMediaPlayer::BufferedMedia); - return; - } - -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "start"; -#endif - - if (m_pendingState != NoPending) { - m_request.setCommand(CmdStart); - } else { - if (m_state.command == CmdStart) - return; - - if (m_scrubbing) - scrub(false); - - if (SUCCEEDED(m_session->Start(&GUID_NULL, &m_varStart))) { - m_state.setCommand(CmdStart); - m_pendingState = CmdPending; - PropVariantInit(&m_varStart); - } else { - emit error(QMediaPlayer::ResourceError, tr("failed to start playback"), true); - } - } -} - -void MFPlayerSession::pause() -{ -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "pause"; -#endif - if (m_pendingState != NoPending) { - m_request.setCommand(CmdPause); - } else { - if (m_state.command == CmdPause) - return; - if (SUCCEEDED(m_session->Pause())) { - m_state.setCommand(CmdPause); - m_pendingState = CmdPending; - } else { - emit error(QMediaPlayer::ResourceError, tr("failed to pause"), false); - } - } -} - -void MFPlayerSession::changeStatus(QMediaPlayer::MediaStatus newStatus) -{ - if (m_status == newStatus) - return; -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "MFPlayerSession::changeStatus" << newStatus; -#endif - m_status = newStatus; - emit statusChanged(); -} - -QMediaPlayer::MediaStatus MFPlayerSession::status() const -{ - return m_status; -} - -void MFPlayerSession::createSession() -{ - Q_ASSERT(m_session == NULL); - HRESULT hr = MFCreateMediaSession(NULL, &m_session); - if (FAILED(hr)) { - changeStatus(QMediaPlayer::UnknownMediaStatus); - emit error(QMediaPlayer::ResourceError, tr("Unable to create mediasession"), true); - } - - hr = m_session->BeginGetEvent(this, m_session); - - if (FAILED(hr)) { - changeStatus(QMediaPlayer::UnknownMediaStatus); - emit error(QMediaPlayer::ResourceError, tr("Unable to pulling session events"), false); - } -} - -qint64 MFPlayerSession::position() -{ - if (m_request.command == CmdSeek || m_request.command == CmdSeekResume) - return m_request.start; - - if (m_pendingState == SeekPending) - return m_state.start; - - if (m_state.command == CmdStop) - return qint64(m_varStart.hVal.QuadPart / 10000); - - if (m_presentationClock) { - MFTIME time, sysTime; - if (FAILED(m_presentationClock->GetCorrelatedTime(0, &time, &sysTime))) - return 0; - return qint64(time / 10000); - } - return 0; -} - -void MFPlayerSession::setPosition(qint64 position) -{ -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "setPosition"; -#endif - if (m_pendingState != NoPending) { - m_request.setCommand(CmdSeek); - m_request.start = position; - } else { - setPositionInternal(position, CmdNone); - } -} - -void MFPlayerSession::setPositionInternal(qint64 position, Command requestCmd) -{ - if (m_status == QMediaPlayer::EndOfMedia) - changeStatus(QMediaPlayer::LoadedMedia); - if (m_state.command == CmdStop && requestCmd != CmdSeekResume) { - m_varStart.vt = VT_I8; - m_varStart.hVal.QuadPart = LONGLONG(position * 10000); - return; - } - - if (m_state.command == CmdPause) - scrub(true); - -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "setPositionInternal"; -#endif - - PROPVARIANT varStart; - varStart.vt = VT_I8; - varStart.hVal.QuadPart = LONGLONG(position * 10000); - if (SUCCEEDED(m_session->Start(NULL, &varStart))) - { - PropVariantInit(&m_varStart); - // Store the pending state. - m_state.setCommand(CmdStart); - m_state.start = position; - m_pendingState = SeekPending; - } else { - emit error(QMediaPlayer::ResourceError, tr("failed to seek"), true); - } -} - -qreal MFPlayerSession::playbackRate() const -{ - if (m_pendingState != NoPending) - return m_request.rate; - return m_state.rate; -} - -void MFPlayerSession::setPlaybackRate(qreal rate) -{ - if (m_scrubbing) { - m_restoreRate = rate; - return; - } - setPlaybackRateInternal(rate); -} - -void MFPlayerSession::setPlaybackRateInternal(qreal rate) -{ - if (rate == m_request.rate) - return; - - m_pendingRate = rate; - if (!m_rateSupport) - return; - -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "setPlaybackRate"; -#endif - BOOL isThin = FALSE; - - //from MSDN http://msdn.microsoft.com/en-us/library/aa965220%28v=vs.85%29.aspx - //Thinning applies primarily to video streams. - //In thinned mode, the source drops delta frames and deliver only key frames. - //At very high playback rates, the source might skip some key frames (for example, deliver every other key frame). - - if (FAILED(m_rateSupport->IsRateSupported(FALSE, rate, NULL))) { - isThin = TRUE; - if (FAILED(m_rateSupport->IsRateSupported(isThin, rate, NULL))) { - qWarning() << "unable to set playbackrate = " << rate; - } - } - if (m_pendingState != NoPending) { - m_request.rate = rate; - m_request.isThin = isThin; - // Remember the current transport state (play, paused, etc), so that we - // can restore it after the rate change, if necessary. However, if - // anothercommand is already pending, that one takes precedent. - if (m_request.command == CmdNone) - m_request.setCommand(m_state.command); - } else { - //No pending operation. Commit the new rate. - commitRateChange(rate, isThin); - } -} - -void MFPlayerSession::commitRateChange(qreal rate, BOOL isThin) -{ -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "commitRateChange"; -#endif - Q_ASSERT(m_pendingState == NoPending); - MFTIME hnsSystemTime = 0; - MFTIME hnsClockTime = 0; - Command cmdNow = m_state.command; - // Allowed rate transitions: - // Positive <-> negative: Stopped - // Negative <-> zero: Stopped - // Postive <-> zero: Paused or stopped - if ((rate > 0 && m_state.rate <= 0) || (rate < 0 && m_state.rate >= 0)) { - // Transition to stopped. - if (cmdNow == CmdStart) { - // Get the current clock position. This will be the restart time. - m_presentationClock->GetCorrelatedTime(0, &hnsClockTime, &hnsSystemTime); - Q_ASSERT(hnsSystemTime != 0); - - // Stop and set the rate - stop(); - - //Cache Request: Restart from stop. - m_request.setCommand(CmdSeekResume); - m_request.start = hnsClockTime / 10000; - } else if (cmdNow == CmdPause) { - // The current state is paused. - // For this rate change, the session must be stopped. However, the - // session cannot transition back from stopped to paused. - // Therefore, this rate transition is not supported while paused. - if (rate < 0 || m_state.rate < 0) { - qWarning() << "Unable to change rate from positive to negative or vice versa in paused state"; - return; - } - } - } else if (rate == 0 && m_state.rate != 0) { - if (cmdNow != CmdPause) { - // Transition to paused. - // This transisition requires the paused state. - // Pause and set the rate. - pause(); - - // Request: Switch back to current state. - m_request.setCommand(cmdNow); - } - } - - // Set the rate. - if (FAILED(m_rateControl->SetRate(isThin, rate))) { - qWarning() << "failed to set playbackrate = " << rate; - return; - } - - // Adjust our current rate and requested rate. - m_pendingRate = m_request.rate = m_state.rate = rate; - -} - -void MFPlayerSession::scrub(bool enableScrub) -{ - if (m_scrubbing == enableScrub) - return; - - m_scrubbing = enableScrub; - - if (!canScrub()) { - if (!enableScrub) - m_pendingRate = m_restoreRate; - return; - } - - if (enableScrub) { - // Enter scrubbing mode. Cache the rate. - m_restoreRate = m_request.rate; - setPlaybackRateInternal(0.0f); - } else { - // Leaving scrubbing mode. Restore the old rate. - setPlaybackRateInternal(m_restoreRate); - } -} - -int MFPlayerSession::volume() const -{ - return m_volume; -} - -void MFPlayerSession::setVolume(int volume) -{ - if (m_volume == volume) - return; - m_volume = volume; - if (m_volumeControl) - m_volumeControl->SetMasterVolume(m_volume * 0.01f); - emit volumeChanged(m_volume); -} - -bool MFPlayerSession::isMuted() const -{ - return m_muted; -} - -void MFPlayerSession::setMuted(bool muted) -{ - if (m_muted == muted) - return; - m_muted = muted; - if (m_volumeControl) - m_volumeControl->SetMute(BOOL(m_muted)); - emit mutedChanged(m_muted); -} - -int MFPlayerSession::bufferStatus() -{ - if (!m_netsourceStatistics) - return 0; - PROPVARIANT var; - PROPERTYKEY key; - key.fmtid = MFNETSOURCE_STATISTICS; - key.pid = MFNETSOURCE_BUFFERPROGRESS_ID; - int progress = -1; - if (SUCCEEDED(m_netsourceStatistics->GetValue(key, &var))) { - progress = var.lVal; - } - PropVariantClear(&var); - -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "bufferStatus: progress = " << progress; -#endif - - return progress; -} - -QMediaTimeRange MFPlayerSession::availablePlaybackRanges() -{ - if (!m_netsourceStatistics) - return QMediaTimeRange(); - - qint64 start = 0, end = 0; - PROPVARIANT var; - PROPERTYKEY key; - key.fmtid = MFNETSOURCE_STATISTICS; - key.pid = MFNETSOURCE_SEEKRANGESTART_ID; - if (SUCCEEDED(m_netsourceStatistics->GetValue(key, &var))) { - start = qint64(var.uhVal.QuadPart / 10000); - key.pid = MFNETSOURCE_SEEKRANGEEND_ID; - if (SUCCEEDED(m_netsourceStatistics->GetValue(key, &var))) { - end = qint64(var.uhVal.QuadPart / 10000); - } - } - PropVariantClear(&var); - return QMediaTimeRange(start, end); -} - -HRESULT MFPlayerSession::QueryInterface(REFIID riid, void** ppvObject) -{ - if (!ppvObject) - return E_POINTER; - if (riid == IID_IMFAsyncCallback) { - *ppvObject = static_cast<IMFAsyncCallback*>(this); - } else if (riid == IID_IUnknown) { - *ppvObject = static_cast<IUnknown*>(this); - } else { - *ppvObject = NULL; - return E_NOINTERFACE; - } - return S_OK; -} - -ULONG MFPlayerSession::AddRef(void) -{ - return 1; -} - -ULONG MFPlayerSession::Release(void) -{ - return 1; -} - -HRESULT MFPlayerSession::Invoke(IMFAsyncResult *pResult) -{ - if (pResult->GetStateNoAddRef() != m_session) - return S_OK; - - IMFMediaEvent *pEvent = NULL; - // Get the event from the event queue. - HRESULT hr = m_session->EndGetEvent(pResult, &pEvent); - if (FAILED(hr)) { - return S_OK; - } - - MediaEventType meType = MEUnknown; - hr = pEvent->GetType(&meType); - if (FAILED(hr)) { - pEvent->Release(); - return S_OK; - } - - if (meType == MESessionClosed) { - SetEvent(m_hCloseEvent); - return S_OK; - } else { - hr = m_session->BeginGetEvent(this, m_session); - if (FAILED(hr)) { - pEvent->Release(); - return S_OK; - } - } - - emit sessionEvent(pEvent); - return S_OK; -} - -void MFPlayerSession::handleSessionEvent(IMFMediaEvent *sessionEvent) -{ - HRESULT hrStatus = S_OK; - HRESULT hr = sessionEvent->GetStatus(&hrStatus); - if (FAILED(hr)) { - sessionEvent->Release(); - return; - } - - MediaEventType meType = MEUnknown; - hr = sessionEvent->GetType(&meType); - -#ifdef DEBUG_MEDIAFOUNDATION - if (FAILED(hrStatus)) - qDebug() << "handleSessionEvent: MediaEventType = " << meType << "Failed"; - else - qDebug() << "handleSessionEvent: MediaEventType = " << meType; -#endif - - switch (meType) { - case MENonFatalError: { - PROPVARIANT var; - PropVariantInit(&var); - sessionEvent->GetValue(&var); - qWarning() << "handleSessionEvent: non fatal error = " << var.ulVal; - PropVariantClear(&var); - emit error(QMediaPlayer::ResourceError, tr("media session non-fatal error!"), false); - } - break; - case MESourceUnknown: - changeStatus(QMediaPlayer::InvalidMedia); - case MEError: - qWarning() << "handleSessionEvent: serious error = " << hrStatus; - emit error(QMediaPlayer::ResourceError, tr("media session serious error!"), true); - break; - case MESessionRateChanged: - // If the rate change succeeded, we've already got the rate - // cached. If it failed, try to get the actual rate. - if (FAILED(hrStatus)) { - PROPVARIANT var; - PropVariantInit(&var); - if (SUCCEEDED(sessionEvent->GetValue(&var)) && (var.vt == VT_R4)) { - m_state.rate = var.fltVal; - } - emit playbackRateChanged(playbackRate()); - } - break; - case MESessionScrubSampleComplete : - if (m_scrubbing) - updatePendingCommands(CmdStart); - break; - case MESessionStarted: - if (!m_scrubbing) - updatePendingCommands(CmdStart); - break; - case MESessionStopped: - if (m_status != QMediaPlayer::EndOfMedia) { - m_varStart.vt = VT_I8; - m_varStart.hVal.QuadPart = 0; - - //only change to loadedMedia when not loading a new media source - if (m_status != QMediaPlayer::LoadingMedia) { - changeStatus(QMediaPlayer::LoadedMedia); - } - } - updatePendingCommands(CmdStop); - break; - case MESessionPaused: - updatePendingCommands(CmdPause); - break; - case MEReconnectStart: -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "MEReconnectStart" << ((hrStatus == S_OK) ? "OK" : "Failed"); -#endif - break; - case MEReconnectEnd: -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "MEReconnectEnd" << ((hrStatus == S_OK) ? "OK" : "Failed"); -#endif - break; - } - - if (FAILED(hrStatus)) { - sessionEvent->Release(); - return; - } - - switch (meType) { - case MEBufferingStarted: - changeStatus(QMediaPlayer::StalledMedia); - emit bufferStatusChanged(bufferStatus()); - break; - case MEBufferingStopped: - changeStatus(QMediaPlayer::BufferedMedia); - emit bufferStatusChanged(bufferStatus()); - break; - case MEEndOfPresentation: - stop(); - changeStatus(QMediaPlayer::EndOfMedia); - m_varStart.vt = VT_I8; - //keep reporting the final position after end of media - m_varStart.hVal.QuadPart = m_duration; - break; - case MESessionEnded: - m_pendingState = NoPending; - m_state.command = CmdStop; - m_state.prevCmd = CmdNone; - m_request.command = CmdNone; - m_request.prevCmd = CmdNone; - break; - case MEEndOfPresentationSegment: - break; - case MEAudioSessionVolumeChanged: - if (m_volumeControl) { - float currentVolume = 1; - if (SUCCEEDED(m_volumeControl->GetMasterVolume(¤tVolume))) { - if (currentVolume != m_volume) { - m_volume = currentVolume; - emit volumeChanged(int(m_volume * 100)); - } - } - BOOL currentMuted = FALSE; - if (SUCCEEDED(m_volumeControl->GetMute(¤tMuted))) { - if (currentMuted != BOOL(m_muted)) { - m_muted = bool(currentMuted); - emit mutedChanged(m_muted); - } - } - } - break; - case MESessionTopologySet: { - if (SUCCEEDED(MFGetService(m_session, MR_POLICY_VOLUME_SERVICE, IID_PPV_ARGS(&m_volumeControl)))) { - m_volumeControl->SetMasterVolume(m_volume); - m_volumeControl->SetMute(m_muted); - } - DWORD dwCharacteristics = 0; - m_sourceResolver->mediaSource()->GetCharacteristics(&dwCharacteristics); - emit seekableUpdate(MFMEDIASOURCE_CAN_SEEK & dwCharacteristics); - changeStatus(QMediaPlayer::LoadedMedia); - } - break; - case MESessionTopologyStatus: { - UINT32 status; - if (SUCCEEDED(sessionEvent->GetUINT32(MF_EVENT_TOPOLOGY_STATUS, &status))) { - if (status == MF_TOPOSTATUS_READY) { - IMFClock* clock; - if (SUCCEEDED(m_session->GetClock(&clock))) { - clock->QueryInterface(IID_IMFPresentationClock, (void**)(&m_presentationClock)); - clock->Release(); - } - - if (SUCCEEDED(MFGetService(m_session, MF_RATE_CONTROL_SERVICE, IID_PPV_ARGS(&m_rateControl)))) { - if (SUCCEEDED(MFGetService(m_session, MF_RATE_CONTROL_SERVICE, IID_PPV_ARGS(&m_rateSupport)))) { - if ((m_mediaTypes & Video) == Video - && SUCCEEDED(m_rateSupport->IsRateSupported(TRUE, 0, NULL))) - m_canScrub = true; - } - BOOL isThin = FALSE; - float rate = 1; - if (SUCCEEDED(m_rateControl->GetRate(&isThin, &rate))) { - if (m_pendingRate != rate) { - m_state.rate = m_request.rate = rate; - setPlaybackRate(m_pendingRate); - } - } - } - MFGetService(m_session, MFNETSOURCE_STATISTICS_SERVICE, IID_PPV_ARGS(&m_netsourceStatistics)); - } - } - } - break; - } - - sessionEvent->Release(); -} - -void MFPlayerSession::updatePendingCommands(Command command) -{ - emit positionChanged(position()); - if (m_state.command != command || m_pendingState == NoPending) - return; - - // The current pending command has completed. - if (m_pendingState == SeekPending && m_state.prevCmd == CmdPause) { - m_pendingState = NoPending; - //if we have pending seek request, - //then we just keep current state to paused and continue the seek request, - //otherwise we will restore to pause state - if (m_request.command == CmdSeek) { - m_state.setCommand(CmdPause); - } else { - pause(); - return; - } - } - - m_pendingState = NoPending; - - //First look for rate changes. - if (m_request.rate != m_state.rate) { - commitRateChange(m_request.rate, m_request.isThin); - } - - // Now look for new requests. - if (m_pendingState == NoPending) { - switch (m_request.command) { - case CmdStart: - start(); - break; - case CmdPause: - pause(); - break; - case CmdStop: - stop(); - break; - case CmdSeek: - case CmdSeekResume: - setPositionInternal(m_request.start, m_request.command); - } - m_request.setCommand(CmdNone); - } - -} - -bool MFPlayerSession::canScrub() const -{ - return m_canScrub && m_rateSupport && m_rateControl; -} - -void MFPlayerSession::clear() -{ -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "MFPlayerSession::clear"; -#endif - m_mediaTypes = 0; - m_canScrub = false; - - m_pendingState = NoPending; - m_state.command = CmdStop; - m_state.prevCmd = CmdNone; - m_request.command = CmdNone; - m_request.prevCmd = CmdNone; - - if (m_presentationClock) { - m_presentationClock->Release(); - m_presentationClock = NULL; - } - if (m_rateControl) { - m_rateControl->Release(); - m_rateControl = NULL; - } - if (m_rateSupport) { - m_rateSupport->Release(); - m_rateSupport = NULL; - } - if (m_volumeControl) { - m_volumeControl->Release(); - m_volumeControl = NULL; - } - if (m_netsourceStatistics) { - m_netsourceStatistics->Release(); - m_netsourceStatistics = NULL; - } -} diff --git a/src/plugins/wmf/player/mfplayersession.h b/src/plugins/wmf/player/mfplayersession.h deleted file mode 100644 index 169a404..0000000 --- a/src/plugins/wmf/player/mfplayersession.h +++ /dev/null @@ -1,212 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MFPLAYERSESSION_H -#define MFPLAYERSESSION_H - -#include <mfapi.h> -#include <mfidl.h> - -#include "qmediaplayer.h" -#include "qmediaresource.h" -#include "qmediaservice.h" -#include "qmediatimerange.h" - -#include <QtCore/qcoreevent.h> -#include <QtCore/qmutex.h> -#include <QtCore/qurl.h> -#include <QtCore/qwaitcondition.h> - -QT_BEGIN_NAMESPACE -class QMediaContent; -QT_END_NAMESPACE - -QT_USE_NAMESPACE - -class SourceResolver; -#ifndef Q_WS_SIMULATOR -class Evr9VideoWindowControl; -#endif -class MFAudioEndpointControl; -class MFVideoRendererControl; -class MFPlayerControl; -class MFMetaDataControl; - -class MFPlayerSession : public QObject, public IMFAsyncCallback -{ - Q_OBJECT - friend class SourceResolver; -public: - MFPlayerSession(QObject *parent = 0); - ~MFPlayerSession(); - - STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject); - - STDMETHODIMP_(ULONG) AddRef(void); - - STDMETHODIMP_(ULONG) Release(void); - - STDMETHODIMP Invoke(IMFAsyncResult *pResult); - - STDMETHODIMP GetParameters(DWORD *pdwFlags, DWORD *pdwQueue) - { - Q_UNUSED(pdwFlags); - Q_UNUSED(pdwQueue); - return E_NOTIMPL; - } - - void load(const QMediaContent &media, QIODevice *stream); - void stop(bool immediate = false); - void start(); - void pause(); - - QMediaPlayer::MediaStatus status() const; - qint64 position(); - void setPosition(qint64 position); - qreal playbackRate() const; - void setPlaybackRate(qreal rate); - int volume() const; - void setVolume(int volume); - bool isMuted() const; - void setMuted(bool muted); - int bufferStatus(); - QMediaTimeRange availablePlaybackRanges(); - - void changeStatus(QMediaPlayer::MediaStatus newStatus); - -Q_SIGNALS: - void error(QMediaPlayer::Error error, QString errorString, bool isFatal); - void sessionEvent(IMFMediaEvent *sessionEvent); - void statusChanged(); - void audioAvailable(); - void videoAvailable(); - void durationUpdate(qint64 duration); - void seekableUpdate(bool seekable); - void positionChanged(qint64 position); - void playbackRateChanged(qreal rate); - void volumeChanged(int volume); - void mutedChanged(bool muted); - void bufferStatusChanged(int percentFilled); - -private Q_SLOTS: - void handleMediaSourceReady(); - void handleSessionEvent(IMFMediaEvent *sessionEvent); - void handleSourceError(long hr); - -private: - IMFMediaSession *m_session; - IMFPresentationClock *m_presentationClock; - IMFRateControl *m_rateControl; - IMFRateSupport *m_rateSupport; - IMFSimpleAudioVolume *m_volumeControl; - IPropertyStore *m_netsourceStatistics; - PROPVARIANT m_varStart; - UINT64 m_duration; - - enum Command - { - CmdNone = 0, - CmdStop, - CmdStart, - CmdPause, - CmdSeek, - CmdSeekResume, - }; - - void clear(); - void setPositionInternal(qint64 position, Command requestCmd); - void setPlaybackRateInternal(qreal rate); - void commitRateChange(qreal rate, BOOL isThin); - bool canScrub() const; - void scrub(bool enableScrub); - bool m_scrubbing; - float m_restoreRate; - - SourceResolver *m_sourceResolver; - HANDLE m_hCloseEvent; - - enum MediaType - { - Unknown = 0, - Audio = 1, - Video = 2, - }; - DWORD m_mediaTypes; - - enum PendingState - { - NoPending = 0, - CmdPending, - SeekPending, - }; - - struct SeekState - { - void setCommand(Command cmd) { - prevCmd = command; - command = cmd; - } - Command command; - Command prevCmd; - float rate; // Playback rate - BOOL isThin; // Thinned playback? - qint64 start; // Start position - }; - SeekState m_state; // Current nominal state. - SeekState m_request; // Pending request. - PendingState m_pendingState; - float m_pendingRate; - void updatePendingCommands(Command command); - - QMediaPlayer::MediaStatus m_status; - bool m_canScrub; - int m_volume; - bool m_muted; - - void createSession(); - void setupPlaybackTopology(IMFMediaSource *source, IMFPresentationDescriptor *sourcePD); - IMFTopologyNode* addSourceNode(IMFTopology* topology, IMFMediaSource* source, - IMFPresentationDescriptor* presentationDesc, IMFStreamDescriptor *streamDesc); - IMFTopologyNode* addOutputNode(IMFStreamDescriptor *streamDesc, MediaType& mediaType, IMFTopology* topology, DWORD sinkID); -}; - - -#endif diff --git a/src/plugins/wmf/player/mfstream.cpp b/src/plugins/wmf/player/mfstream.cpp deleted file mode 100644 index be91175..0000000 --- a/src/plugins/wmf/player/mfstream.cpp +++ /dev/null @@ -1,361 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "mfstream.h" -#include <QtCore/qcoreapplication.h> - -//MFStream is added for supporting QIODevice type of media source. -//It is used to delegate invocations from media foundation(through IMFByteStream) to QIODevice. - -MFStream::MFStream(QIODevice *stream, bool ownStream) - : m_cRef(1) - , m_stream(stream) - , m_ownStream(ownStream) - , m_currentReadResult(0) -{ - //Move to the thread of the stream object - //to make sure invocations on stream - //are happened in the same thread of stream object - this->moveToThread(stream->thread()); - connect(stream, SIGNAL(readyRead()), this, SLOT(handleReadyRead())); -} - -MFStream::~MFStream() -{ - if (m_currentReadResult) - m_currentReadResult->Release(); - if (m_ownStream) - m_stream->deleteLater(); -} - -//from IUnknown -STDMETHODIMP MFStream::QueryInterface(REFIID riid, LPVOID *ppvObject) -{ - if (!ppvObject) - return E_POINTER; - if (riid == IID_IMFByteStream) { - *ppvObject = static_cast<IMFByteStream*>(this); - } else if (riid == IID_IUnknown) { - *ppvObject = static_cast<IUnknown*>(this); - } else { - *ppvObject = NULL; - return E_NOINTERFACE; - } - AddRef(); - return S_OK; -} - -STDMETHODIMP_(ULONG) MFStream::AddRef(void) -{ - return InterlockedIncrement(&m_cRef); -} - -STDMETHODIMP_(ULONG) MFStream::Release(void) -{ - LONG cRef = InterlockedDecrement(&m_cRef); - if (cRef == 0) { - this->deleteLater(); - } - return cRef; -} - - -//from IMFByteStream -STDMETHODIMP MFStream::GetCapabilities(DWORD *pdwCapabilities) -{ - if (!pdwCapabilities) - return E_INVALIDARG; - *pdwCapabilities = MFBYTESTREAM_IS_READABLE; - if (!m_stream->isSequential()) - *pdwCapabilities |= MFBYTESTREAM_IS_SEEKABLE; - return S_OK; -} - -STDMETHODIMP MFStream::GetLength(QWORD *pqwLength) -{ - if (!pqwLength) - return E_INVALIDARG; - QMutexLocker locker(&m_mutex); - *pqwLength = QWORD(m_stream->size()); - return S_OK; -} - -STDMETHODIMP MFStream::SetLength(QWORD) -{ - return E_NOTIMPL; -} - -STDMETHODIMP MFStream::GetCurrentPosition(QWORD *pqwPosition) -{ - if (!pqwPosition) - return E_INVALIDARG; - QMutexLocker locker(&m_mutex); - *pqwPosition = m_stream->pos(); - return S_OK; -} - -STDMETHODIMP MFStream::SetCurrentPosition(QWORD qwPosition) -{ - QMutexLocker locker(&m_mutex); - //SetCurrentPosition may happend during the BeginRead/EndRead pair, - //refusing to execute SetCurrentPosition during that time seems to be - //the simplest workable solution - if (m_currentReadResult) - return S_FALSE; - - bool seekOK = m_stream->seek(qint64(qwPosition)); - if (seekOK) - return S_OK; - else - return S_FALSE; -} - -STDMETHODIMP MFStream::IsEndOfStream(BOOL *pfEndOfStream) -{ - if (!pfEndOfStream) - return E_INVALIDARG; - QMutexLocker locker(&m_mutex); - *pfEndOfStream = m_stream->atEnd() ? TRUE : FALSE; - return S_OK; -} - -STDMETHODIMP MFStream::Read(BYTE *pb, ULONG cb, ULONG *pcbRead) -{ - QMutexLocker locker(&m_mutex); - qint64 read = m_stream->read((char*)(pb), qint64(cb)); - if (pcbRead) - *pcbRead = ULONG(read); - return S_OK; -} - -STDMETHODIMP MFStream::BeginRead(BYTE *pb, ULONG cb, IMFAsyncCallback *pCallback, - IUnknown *punkState) -{ - if (!pCallback || !pb) - return E_INVALIDARG; - - Q_ASSERT(m_currentReadResult == NULL); - - AsyncReadState *state = new (std::nothrow) AsyncReadState(pb, cb); - if (state == NULL) - return E_OUTOFMEMORY; - - HRESULT hr = MFCreateAsyncResult(state, pCallback, punkState, &m_currentReadResult); - state->Release(); - if (FAILED(hr)) - return hr; - - QCoreApplication::postEvent(this, new QEvent(QEvent::User)); - return hr; -} - -STDMETHODIMP MFStream::EndRead(IMFAsyncResult* pResult, ULONG *pcbRead) -{ - if (!pcbRead) - return E_INVALIDARG; - IUnknown *pUnk; - pResult->GetObject(&pUnk); - AsyncReadState *state = static_cast<AsyncReadState*>(pUnk); - *pcbRead = state->bytesRead(); - pUnk->Release(); - - m_currentReadResult->Release(); - m_currentReadResult = NULL; - - return S_OK; -} - -STDMETHODIMP MFStream::Write(const BYTE *, ULONG, ULONG *) -{ - return E_NOTIMPL; -} - -STDMETHODIMP MFStream::BeginWrite(const BYTE *, ULONG , - IMFAsyncCallback *, - IUnknown *) -{ - return E_NOTIMPL; -} - -STDMETHODIMP MFStream::EndWrite(IMFAsyncResult *, - ULONG *) -{ - return E_NOTIMPL; -} - -STDMETHODIMP MFStream::Seek( - MFBYTESTREAM_SEEK_ORIGIN SeekOrigin, - LONGLONG llSeekOffset, - DWORD, - QWORD *pqwCurrentPosition) -{ - QMutexLocker locker(&m_mutex); - if (m_currentReadResult) - return S_FALSE; - - qint64 pos = qint64(llSeekOffset); - switch (SeekOrigin) { - case msoCurrent: - pos += m_stream->pos(); - break; - } - bool seekOK = m_stream->seek(pos); - if (*pqwCurrentPosition) - *pqwCurrentPosition = pos; - if (seekOK) - return S_OK; - else - return S_FALSE; -} - -STDMETHODIMP MFStream::Flush() -{ - return E_NOTIMPL; -} - -STDMETHODIMP MFStream::Close() -{ - QMutexLocker locker(&m_mutex); - if (m_ownStream) - m_stream->close(); - return S_OK; -} - -void MFStream::doRead() -{ - bool readDone = true; - IUnknown *pUnk = NULL; - HRESULT hr = m_currentReadResult->GetObject(&pUnk); - if (SUCCEEDED(hr)) { - //do actual read - AsyncReadState *state = static_cast<AsyncReadState*>(pUnk); - ULONG cbRead; - Read(state->pb(), state->cb() - state->bytesRead(), &cbRead); - pUnk->Release(); - - state->setBytesRead(cbRead + state->bytesRead()); - if (state->cb() > state->bytesRead() && !m_stream->atEnd()) { - readDone = false; - } - } - - if (readDone) { - //now inform the original caller - m_currentReadResult->SetStatus(hr); - MFInvokeCallback(m_currentReadResult); - } -} - - -void MFStream::handleReadyRead() -{ - doRead(); -} - -void MFStream::customEvent(QEvent *event) -{ - if (event->type() != QEvent::User) { - QObject::customEvent(event); - return; - } - doRead(); -} - -//AsyncReadState is a helper class used in BeginRead for asynchronous operation -//to record some BeginRead parameters, so these parameters could be -//used later when actually executing the read operation in another thread. -MFStream::AsyncReadState::AsyncReadState(BYTE *pb, ULONG cb) - : m_cRef(1) - , m_pb(pb) - , m_cb(cb) - , m_cbRead(0) -{ -} - -//from IUnknown -STDMETHODIMP MFStream::AsyncReadState::QueryInterface(REFIID riid, LPVOID *ppvObject) -{ - if (!ppvObject) - return E_POINTER; - - if (riid == IID_IUnknown) { - *ppvObject = static_cast<IUnknown*>(this); - } else { - *ppvObject = NULL; - return E_NOINTERFACE; - } - AddRef(); - return S_OK; -} - -STDMETHODIMP_(ULONG) MFStream::AsyncReadState::AddRef(void) -{ - return InterlockedIncrement(&m_cRef); -} - -STDMETHODIMP_(ULONG) MFStream::AsyncReadState::Release(void) -{ - LONG cRef = InterlockedDecrement(&m_cRef); - if (cRef == 0) - delete this; - // For thread safety, return a temporary variable. - return cRef; -} - -BYTE* MFStream::AsyncReadState::pb() const -{ - return m_pb; -} - -ULONG MFStream::AsyncReadState::cb() const -{ - return m_cb; -} - -ULONG MFStream::AsyncReadState::bytesRead() const -{ - return m_cbRead; -} - -void MFStream::AsyncReadState::setBytesRead(ULONG cbRead) -{ - m_cbRead = cbRead; -} diff --git a/src/plugins/wmf/player/mfstream.h b/src/plugins/wmf/player/mfstream.h deleted file mode 100644 index 226bda9..0000000 --- a/src/plugins/wmf/player/mfstream.h +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MFSTREAM_H -#define MFSTREAM_H - -#include <mfapi.h> -#include <mfidl.h> -#include <QtCore/qmutex.h> -#include <QtCore/qiodevice.h> -#include <QtCore/qcoreevent.h> - -QT_USE_NAMESPACE - -class MFStream : public QObject, public IMFByteStream -{ - Q_OBJECT -public: - MFStream(QIODevice *stream, bool ownStream); - - ~MFStream(); - - //from IUnknown - STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject); - - STDMETHODIMP_(ULONG) AddRef(void); - - STDMETHODIMP_(ULONG) Release(void); - - - //from IMFByteStream - STDMETHODIMP GetCapabilities(DWORD *pdwCapabilities); - - STDMETHODIMP GetLength(QWORD *pqwLength); - - STDMETHODIMP SetLength(QWORD); - - STDMETHODIMP GetCurrentPosition(QWORD *pqwPosition); - - STDMETHODIMP SetCurrentPosition(QWORD qwPosition); - - STDMETHODIMP IsEndOfStream(BOOL *pfEndOfStream); - - STDMETHODIMP Read(BYTE *pb, ULONG cb, ULONG *pcbRead); - - STDMETHODIMP BeginRead(BYTE *pb, ULONG cb, IMFAsyncCallback *pCallback, - IUnknown *punkState); - - STDMETHODIMP EndRead(IMFAsyncResult* pResult, ULONG *pcbRead); - - STDMETHODIMP Write(const BYTE *, ULONG, ULONG *); - - STDMETHODIMP BeginWrite(const BYTE *, ULONG , - IMFAsyncCallback *, - IUnknown *); - - STDMETHODIMP EndWrite(IMFAsyncResult *, - ULONG *); - - STDMETHODIMP Seek( - MFBYTESTREAM_SEEK_ORIGIN SeekOrigin, - LONGLONG llSeekOffset, - DWORD, - QWORD *pqwCurrentPosition); - - STDMETHODIMP Flush(); - - STDMETHODIMP Close(); - -private: - class AsyncReadState : public IUnknown - { - public: - AsyncReadState(BYTE *pb, ULONG cb); - - //from IUnknown - STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject); - - STDMETHODIMP_(ULONG) AddRef(void); - - STDMETHODIMP_(ULONG) Release(void); - - BYTE* pb() const; - ULONG cb() const; - ULONG bytesRead() const; - - void setBytesRead(ULONG cbRead); - - private: - long m_cRef; - BYTE *m_pb; - ULONG m_cb; - ULONG m_cbRead; - }; - - long m_cRef; - QIODevice *m_stream; - bool m_ownStream; - DWORD m_workQueueId; - QMutex m_mutex; - - void doRead(); - -private Q_SLOTS: - void handleReadyRead(); - -protected: - void customEvent(QEvent *event); - IMFAsyncResult *m_currentReadResult; -}; - -#endif diff --git a/src/plugins/wmf/player/mfvideorenderercontrol.cpp b/src/plugins/wmf/player/mfvideorenderercontrol.cpp deleted file mode 100644 index a879d0e..0000000 --- a/src/plugins/wmf/player/mfvideorenderercontrol.cpp +++ /dev/null @@ -1,2200 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "mfvideorenderercontrol.h" -#include <mferror.h> -#include <qabstractvideosurface.h> -#include <qvideosurfaceformat.h> -#include <qtcore/qtimer.h> -#include <qtcore/qmutex.h> -#include <qtcore/qcoreevent.h> -#include <qtcore/qcoreapplication.h> -#include <qtcore/qthread.h> -#include "guiddef.h" -#include <qtcore/qdebug.h> - -//#define DEBUG_MEDIAFOUNDATION -#define PAD_TO_DWORD(x) (((x) + 3) & ~3) - -namespace -{ - class MediaSampleVideoBuffer : public QAbstractVideoBuffer - { - public: - MediaSampleVideoBuffer(IMFMediaBuffer *buffer, int bytesPerLine) - : QAbstractVideoBuffer(NoHandle) - , m_buffer(buffer) - , m_bytesPerLine(bytesPerLine) - , m_mapMode(NotMapped) - { - buffer->AddRef(); - } - - ~MediaSampleVideoBuffer() - { - m_buffer->Release(); - } - - uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) - { - if (m_mapMode == NotMapped && mode != NotMapped) { - BYTE *bytes; - DWORD length; - HRESULT hr = m_buffer->Lock(&bytes, NULL, &length); - if (SUCCEEDED(hr)) { - if (numBytes) - *numBytes = int(length); - - if (bytesPerLine) - *bytesPerLine = m_bytesPerLine; - - m_mapMode = mode; - return reinterpret_cast<uchar *>(bytes); - } else { - qWarning("Faild to lock mf buffer!"); - } - } - return 0; - } - - void unmap() - { - if (m_mapMode == NotMapped) - return; - m_mapMode = NotMapped; - m_buffer->Unlock(); - } - - MapMode mapMode() const - { - return m_mapMode; - } - - private: - IMFMediaBuffer *m_buffer; - int m_bytesPerLine; - MapMode m_mapMode; - }; - - template<class T> - class AsyncCallback : public IMFAsyncCallback - { - public: - typedef HRESULT (T::*InvokeFn)(IMFAsyncResult *pAsyncResult); - - AsyncCallback(T *pParent, InvokeFn fn) : m_pParent(pParent), m_pInvokeFn(fn) - { - } - - // IUnknown - STDMETHODIMP QueryInterface(REFIID iid, void** ppv) - { - if (!ppv) - { - return E_POINTER; - } - if (iid == __uuidof(IUnknown)) - { - *ppv = static_cast<IUnknown*>(static_cast<IMFAsyncCallback*>(this)); - } - else if (iid == __uuidof(IMFAsyncCallback)) - { - *ppv = static_cast<IMFAsyncCallback*>(this); - } - else - { - *ppv = NULL; - return E_NOINTERFACE; - } - AddRef(); - return S_OK; - } - STDMETHODIMP_(ULONG) AddRef() - { - // Delegate to parent class. - return m_pParent->AddRef(); - } - STDMETHODIMP_(ULONG) Release() - { - // Delegate to parent class. - return m_pParent->Release(); - } - - // IMFAsyncCallback methods - STDMETHODIMP GetParameters(DWORD*, DWORD*) - { - // Implementation of this method is optional. - return E_NOTIMPL; - } - - STDMETHODIMP Invoke(IMFAsyncResult* pAsyncResult) - { - return (m_pParent->*m_pInvokeFn)(pAsyncResult); - } - - T *m_pParent; - InvokeFn m_pInvokeFn; - }; - - - // Custom interface for handling IMFStreamSink::PlaceMarker calls asynchronously. - MIDL_INTERFACE("a3ff32de-1031-438a-8b47-82f8acda59b7") - IMarker : public IUnknown - { - virtual STDMETHODIMP GetMarkerType(MFSTREAMSINK_MARKER_TYPE *pType) = 0; - virtual STDMETHODIMP GetMarkerValue(PROPVARIANT *pvar) = 0; - virtual STDMETHODIMP GetContext(PROPVARIANT *pvar) = 0; - }; - - class Marker : public IMarker - { - public: - static HRESULT Create( - MFSTREAMSINK_MARKER_TYPE eMarkerType, - const PROPVARIANT* pvarMarkerValue, // Can be NULL. - const PROPVARIANT* pvarContextValue, // Can be NULL. - IMarker **ppMarker) - { - if (ppMarker == NULL) - return E_POINTER; - - HRESULT hr = S_OK; - Marker *pMarker = new Marker(eMarkerType); - if (pMarker == NULL) - hr = E_OUTOFMEMORY; - - // Copy the marker data. - if (SUCCEEDED(hr) && pvarMarkerValue) - hr = PropVariantCopy(&pMarker->m_varMarkerValue, pvarMarkerValue); - - if (SUCCEEDED(hr) && pvarContextValue) - hr = PropVariantCopy(&pMarker->m_varContextValue, pvarContextValue); - - if (SUCCEEDED(hr)) { - *ppMarker = pMarker; - (*ppMarker)->AddRef(); - } - - if (pMarker) - pMarker->Release(); - - return hr; - } - - // IUnknown methods. - STDMETHODIMP QueryInterface(REFIID iid, void** ppv) - { - if (!ppv) - return E_POINTER; - if (iid == IID_IUnknown) { - *ppv = static_cast<IUnknown*>(this); - } else if (iid == __uuidof(IMarker)) { - *ppv = static_cast<IMarker*>(this); - } else { - *ppv = NULL; - return E_NOINTERFACE; - } - AddRef(); - return S_OK; - } - - STDMETHODIMP_(ULONG) AddRef() - { - return InterlockedIncrement(&m_cRef); - } - - STDMETHODIMP_(ULONG) Release() - { - LONG cRef = InterlockedDecrement(&m_cRef); - if (cRef == 0) - delete this; - // For thread safety, return a temporary variable. - return cRef; - } - - STDMETHODIMP GetMarkerType(MFSTREAMSINK_MARKER_TYPE *pType) - { - if (pType == NULL) - return E_POINTER; - *pType = m_eMarkerType; - return S_OK; - } - - STDMETHODIMP GetMarkerValue(PROPVARIANT *pvar) - { - if (pvar == NULL) - return E_POINTER; - return PropVariantCopy(pvar, &m_varMarkerValue); - } - - STDMETHODIMP GetContext(PROPVARIANT *pvar) - { - if (pvar == NULL) - return E_POINTER; - return PropVariantCopy(pvar, &m_varContextValue); - } - - protected: - MFSTREAMSINK_MARKER_TYPE m_eMarkerType; - PROPVARIANT m_varMarkerValue; - PROPVARIANT m_varContextValue; - - private: - long m_cRef; - - Marker(MFSTREAMSINK_MARKER_TYPE eMarkerType) : m_cRef(1), m_eMarkerType(eMarkerType) - { - PropVariantInit(&m_varMarkerValue); - PropVariantInit(&m_varContextValue); - } - - virtual ~Marker() - { - PropVariantClear(&m_varMarkerValue); - PropVariantClear(&m_varContextValue); - } - }; - - class MediaStream : public QObject, public IMFStreamSink, public IMFMediaTypeHandler - { - Q_OBJECT - friend class MFVideoRendererControl; - public: - static const DWORD DEFAULT_MEDIA_STREAM_ID = 0x0; - - MediaStream(IMFMediaSink *parent, MFVideoRendererControl *rendererControl) - : m_cRef(1) - , m_eventQueue(0) - , m_shutdown(false) - , m_surface(0) - , m_state(State_TypeNotSet) - , m_currentFormatIndex(-1) - , m_bytesPerLine(0) - , m_workQueueId(0) - , m_workQueueCB(this, &MediaStream::onDispatchWorkItem) - , m_finalizeResult(0) - , m_scheduledBuffer(0) - , m_presentationClock(0) - , m_currentMediaType(0) - , m_prerolling(false) - , m_prerollTargetTime(0) - , m_startTime(0) - , m_rendererControl(rendererControl) - { - m_sink = parent; - - if (FAILED(MFCreateEventQueue(&m_eventQueue))) - qWarning("Failed to create mf event queue!"); - if (FAILED(MFAllocateWorkQueue(&m_workQueueId))) - qWarning("Failed to allocated mf work queue!"); - } - - ~MediaStream() - { - Q_ASSERT(m_shutdown); - } - - //from IUnknown - STDMETHODIMP QueryInterface(REFIID riid, void** ppvObject) - { - if (!ppvObject) - return E_POINTER; - if (riid == IID_IMFStreamSink) { - *ppvObject = static_cast<IMFStreamSink*>(this); - } else if (riid == IID_IMFMediaEventGenerator) { - *ppvObject = static_cast<IMFMediaEventGenerator*>(this); - } else if (riid == IID_IMFMediaTypeHandler) { - *ppvObject = static_cast<IMFMediaTypeHandler*>(this); - } else if (riid == IID_IUnknown) { - *ppvObject = static_cast<IUnknown*>(static_cast<IMFStreamSink*>(this)); - } else { - *ppvObject = NULL; - return E_NOINTERFACE; - } - AddRef(); - return S_OK; - } - - STDMETHODIMP_(ULONG) AddRef(void) - { - return InterlockedIncrement(&m_cRef); - } - - STDMETHODIMP_(ULONG) Release(void) - { - LONG cRef = InterlockedDecrement(&m_cRef); - if (cRef == 0) - delete this; - // For thread safety, return a temporary variable. - return cRef; - } - - //from IMFMediaEventGenerator - STDMETHODIMP GetEvent( - DWORD dwFlags, - IMFMediaEvent **ppEvent) - { - // GetEvent can block indefinitely, so we don't hold the lock. - // This requires some juggling with the event queue pointer. - HRESULT hr = S_OK; - IMFMediaEventQueue *queue = NULL; - - m_mutex.lock(); - if (m_shutdown) - hr = MF_E_SHUTDOWN; - if (SUCCEEDED(hr)) { - queue = m_eventQueue; - queue->AddRef(); - } - m_mutex.unlock(); - - // Now get the event. - if (SUCCEEDED(hr)) { - hr = queue->GetEvent(dwFlags, ppEvent); - queue->Release(); - } - - return hr; - } - - STDMETHODIMP BeginGetEvent( - IMFAsyncCallback *pCallback, - IUnknown *punkState) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - return m_eventQueue->BeginGetEvent(pCallback, punkState); - } - - STDMETHODIMP EndGetEvent( - IMFAsyncResult *pResult, - IMFMediaEvent **ppEvent) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - return m_eventQueue->EndGetEvent(pResult, ppEvent); - } - - STDMETHODIMP QueueEvent( - MediaEventType met, - REFGUID guidExtendedType, - HRESULT hrStatus, - const PROPVARIANT *pvValue) - { -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "MediaStream::QueueEvent" << met; -#endif - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - return m_eventQueue->QueueEventParamVar(met, guidExtendedType, hrStatus, pvValue); - } - - //from IMFStreamSink - STDMETHODIMP GetMediaSink( - IMFMediaSink **ppMediaSink) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - else if (!ppMediaSink) - return E_INVALIDARG; - - m_sink->AddRef(); - *ppMediaSink = m_sink; - return S_OK; - } - - STDMETHODIMP GetIdentifier( - DWORD *pdwIdentifier) - { - *pdwIdentifier = MediaStream::DEFAULT_MEDIA_STREAM_ID; - return S_OK; - } - - STDMETHODIMP GetMediaTypeHandler( - IMFMediaTypeHandler **ppHandler) - { - LPVOID handler = NULL; - HRESULT hr = QueryInterface(IID_IMFMediaTypeHandler, &handler); - *ppHandler = (IMFMediaTypeHandler*)(handler); - return hr; - } - - STDMETHODIMP ProcessSample( - IMFSample *pSample) - { - if (pSample == NULL) - return E_INVALIDARG; - HRESULT hr = S_OK; - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - - if (!m_prerolling) { - hr = validateOperation(OpProcessSample); - if (FAILED(hr)) - return hr; - } - - pSample->AddRef(); - m_sampleQueue.push_back(pSample); - - // Unless we are paused, start an async operation to dispatch the next sample. - if (m_state != State_Paused) - hr = queueAsyncOperation(OpProcessSample); - - return hr; - } - - STDMETHODIMP PlaceMarker( - MFSTREAMSINK_MARKER_TYPE eMarkerType, - const PROPVARIANT *pvarMarkerValue, - const PROPVARIANT *pvarContextValue) - { - HRESULT hr = S_OK; - QMutexLocker locker(&m_mutex); - IMarker *pMarker = NULL; - if (m_shutdown) - return MF_E_SHUTDOWN; - - hr = validateOperation(OpPlaceMarker); - if (FAILED(hr)) - return hr; - - // Create a marker object and put it on the sample queue. - hr = Marker::Create(eMarkerType, pvarMarkerValue, pvarContextValue, &pMarker); - if (FAILED(hr)) - return hr; - - m_sampleQueue.push_back(pMarker); - - // Unless we are paused, start an async operation to dispatch the next sample/marker. - if (m_state != State_Paused) - hr = queueAsyncOperation(OpPlaceMarker); // Increments ref count on pOp. - return hr; - } - - STDMETHODIMP Flush( void) - { -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "MediaStream::Flush"; -#endif - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - // Note: Even though we are flushing data, we still need to send - // any marker events that were queued. - clearBufferCache(); - return processSamplesFromQueue(DropSamples); - } - - //from IMFMediaTypeHandler - STDMETHODIMP IsMediaTypeSupported( - IMFMediaType *pMediaType, - IMFMediaType **ppMediaType) - { - if (ppMediaType) - *ppMediaType = NULL; - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - - int index = getMediaTypeIndex(pMediaType); - if (index < 0) { - if (ppMediaType && m_mediaTypes.size() > 0) { - *ppMediaType = m_mediaTypes[0]; - (*ppMediaType)->AddRef(); - } - return MF_E_INVALIDMEDIATYPE; - } - - BOOL compressed = TRUE; - pMediaType->IsCompressedFormat(&compressed); - if (compressed) { - if (ppMediaType && (SUCCEEDED(MFCreateMediaType(ppMediaType)))) { - (*ppMediaType)->CopyAllItems(pMediaType); - (*ppMediaType)->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, TRUE); - (*ppMediaType)->SetUINT32(MF_MT_COMPRESSED, FALSE); - (*ppMediaType)->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE); - } - return MF_E_INVALIDMEDIATYPE; - } - - return S_OK; - } - - STDMETHODIMP GetMediaTypeCount( - DWORD *pdwTypeCount) - { - if (pdwTypeCount == NULL) - return E_INVALIDARG; - QMutexLocker locker(&m_mutex); - *pdwTypeCount = DWORD(m_mediaTypes.size()); - return S_OK; - } - - STDMETHODIMP GetMediaTypeByIndex( - DWORD dwIndex, - IMFMediaType **ppType) - { - if (ppType == NULL) - return E_INVALIDARG; - HRESULT hr = S_OK; - QMutexLocker locker(&m_mutex); - if (m_shutdown) - hr = MF_E_SHUTDOWN; - - if (SUCCEEDED(hr)) { - if (dwIndex >= DWORD(m_mediaTypes.size())) - hr = MF_E_NO_MORE_TYPES; - } - - if (SUCCEEDED(hr)) { - *ppType = m_mediaTypes[dwIndex]; - (*ppType)->AddRef(); - } - return hr; - } - - STDMETHODIMP SetCurrentMediaType( - IMFMediaType *pMediaType) - { - HRESULT hr = S_OK; - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - - DWORD flag = MF_MEDIATYPE_EQUAL_MAJOR_TYPES | - MF_MEDIATYPE_EQUAL_FORMAT_TYPES | - MF_MEDIATYPE_EQUAL_FORMAT_DATA; - - if (m_currentMediaType && (m_currentMediaType->IsEqual(pMediaType, &flag) == S_OK)) - return S_OK; - - hr = validateOperation(OpSetMediaType); - - if (SUCCEEDED(hr)) { - int index = getMediaTypeIndex(pMediaType); - if (index >= 0) { - UINT64 size; - hr = pMediaType->GetUINT64(MF_MT_FRAME_SIZE, &size); - if (SUCCEEDED(hr)) { - m_currentFormatIndex = index; - int width = int(HI32(size)); - int height = int(LO32(size)); - QVideoSurfaceFormat format(QSize(width, height), m_pixelFormats[index]); - m_surfaceFormat = format; - - if (FAILED(pMediaType->GetUINT32(MF_MT_DEFAULT_STRIDE, (UINT32*)&m_bytesPerLine))) { - m_bytesPerLine = getBytesPerLine(format); - } - - m_state = State_Ready; - if (m_currentMediaType) - m_currentMediaType->Release(); - m_currentMediaType = pMediaType; - pMediaType->AddRef(); - } - } else { - hr = MF_E_INVALIDREQUEST; - } - } - return hr; - } - - STDMETHODIMP GetCurrentMediaType( - IMFMediaType **ppMediaType) - { - if (ppMediaType == NULL) - return E_INVALIDARG; - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - if (m_currentFormatIndex < 0) - return MF_E_NOT_INITIALIZED; - *ppMediaType = m_currentMediaType; - (*ppMediaType)->AddRef(); - return S_OK; - } - - STDMETHODIMP GetMajorType( - GUID *pguidMajorType) - { - if (pguidMajorType == NULL) - return E_INVALIDARG; - *pguidMajorType = MFMediaType_Video; - return S_OK; - } - - // - void setSurface(QAbstractVideoSurface *surface) - { - m_mutex.lock(); - m_surface = surface; - m_mutex.unlock(); - supportedFormatsChanged(); - } - - void setClock(IMFPresentationClock *presentationClock) - { - QMutexLocker locker(&m_mutex); - if (!m_shutdown) { - if (m_presentationClock) - m_presentationClock->Release(); - m_presentationClock = presentationClock; - if (m_presentationClock) - m_presentationClock->AddRef(); - } - } - - void shutdown() - { - QMutexLocker locker(&m_mutex); - Q_ASSERT(!m_shutdown); - - if (m_currentMediaType) { - m_currentMediaType->Release(); - m_currentMediaType = NULL; - m_currentFormatIndex = -1; - } - - if (m_eventQueue) - m_eventQueue->Shutdown(); - - MFUnlockWorkQueue(m_workQueueId); - - if (m_presentationClock) { - m_presentationClock->Release(); - m_presentationClock = NULL; - } - - if (m_scheduledBuffer) { - m_scheduledBuffer->Release(); - m_scheduledBuffer = NULL; - } - - clearMediaTypes(); - clearSampleQueue(); - clearBufferCache(); - - if (m_eventQueue) { - m_eventQueue->Release(); - m_eventQueue = NULL; - } - - m_shutdown = true; - } - - HRESULT startPreroll(MFTIME hnsUpcomingStartTime) - { - QMutexLocker locker(&m_mutex); - HRESULT hr = validateOperation(OpPreroll); - if (SUCCEEDED(hr)) { - m_prerollTargetTime = hnsUpcomingStartTime; - hr = queueAsyncOperation(OpPreroll); - } - return hr; - } - - HRESULT finalize(IMFAsyncCallback *pCallback, IUnknown *punkState) - { - QMutexLocker locker(&m_mutex); - HRESULT hr = S_OK; - hr = validateOperation(OpFinalize); - if (SUCCEEDED(hr) && m_finalizeResult != NULL) - hr = MF_E_INVALIDREQUEST; // The operation is already pending. - - // Create and store the async result object. - if (SUCCEEDED(hr)) - hr = MFCreateAsyncResult(NULL, pCallback, punkState, &m_finalizeResult); - - if (SUCCEEDED(hr)) { - m_state = State_Finalized; - hr = queueAsyncOperation(OpFinalize); - } - return hr; - } - - HRESULT start(MFTIME start) - { -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "MediaStream::start" << start; -#endif - HRESULT hr = S_OK; - QMutexLocker locker(&m_mutex); - if (m_rate != 0) - hr = validateOperation(OpStart); - - if (SUCCEEDED(hr)) { - MFTIME sysTime; - if (start != PRESENTATION_CURRENT_POSITION) - m_startTime = start; // Cache the start time. - else - m_presentationClock->GetCorrelatedTime(0, &m_startTime, &sysTime); - m_state = State_Started; - hr = queueAsyncOperation(OpStart); - } - return hr; - } - - HRESULT restart() - { -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "MediaStream::restart"; -#endif - QMutexLocker locker(&m_mutex); - HRESULT hr = validateOperation(OpRestart); - if (SUCCEEDED(hr)) { - m_state = State_Started; - hr = queueAsyncOperation(OpRestart); - } - return hr; - } - - HRESULT stop() - { -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "MediaStream::stop"; -#endif - QMutexLocker locker(&m_mutex); - HRESULT hr = validateOperation(OpStop); - if (SUCCEEDED(hr)) { - m_state = State_Stopped; - hr = queueAsyncOperation(OpStop); - } - return hr; - } - - HRESULT pause() - { -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "MediaStream::pause"; -#endif - QMutexLocker locker(&m_mutex); - HRESULT hr = validateOperation(OpPause); - if (SUCCEEDED(hr)) { - m_state = State_Paused; - hr = queueAsyncOperation(OpPause); - } - return hr; - } - - HRESULT setRate(float rate) - { -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "MediaStream::setRate" << rate; -#endif - QMutexLocker locker(&m_mutex); - m_rate = rate; - queueEvent(MEStreamSinkRateChanged, GUID_NULL, S_OK, NULL); - return S_OK; - } - - void supportedFormatsChanged() - { - QMutexLocker locker(&m_mutex); - m_pixelFormats.clear(); - clearMediaTypes(); - QList<QVideoFrame::PixelFormat> formats = m_surface->supportedPixelFormats(); - foreach (QVideoFrame::PixelFormat format, formats) { - IMFMediaType *mediaType; - if (FAILED(MFCreateMediaType(&mediaType))) { - qWarning("Failed to create mf media type!"); - continue; - } - mediaType->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, TRUE); - mediaType->SetUINT32(MF_MT_COMPRESSED, FALSE); - mediaType->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE); - mediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video); - switch (format) { - case QVideoFrame::Format_ARGB32: - case QVideoFrame::Format_ARGB32_Premultiplied: - mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_ARGB32); - break; - case QVideoFrame::Format_RGB32: - mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB32); - break; - case QVideoFrame::Format_RGB24: - mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB24); - break; - case QVideoFrame::Format_RGB565: - mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB565); - break; - case QVideoFrame::Format_RGB555: - mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB555); - break; - case QVideoFrame::Format_AYUV444: - case QVideoFrame::Format_AYUV444_Premultiplied: - mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_AYUV); - break; - case QVideoFrame::Format_YUV420P: - mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_I420); - break; - case QVideoFrame::Format_UYVY: - mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_UYVY); - break; - case QVideoFrame::Format_YV12: - mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_YV12); - break; - case QVideoFrame::Format_NV12: - mediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12); - break; - default: - mediaType->Release(); - continue; - } - m_pixelFormats.push_back(format); - m_mediaTypes.push_back(mediaType); - } - } - - void present() - { - QMutexLocker locker(&m_mutex); - if (!m_scheduledBuffer) - return; - m_surface->present(QVideoFrame( - new MediaSampleVideoBuffer(m_scheduledBuffer, m_bytesPerLine), - m_surfaceFormat.frameSize(), - m_surfaceFormat.pixelFormat())); - m_scheduledBuffer->Release(); - m_scheduledBuffer = NULL; - if (m_rate != 0) - schedulePresentation(true); - } - - enum - { - StartSurface = QEvent::User, - StopSurface, - FlushSurface, - PresentSurface - }; - - class PresentEvent : public QEvent - { - public: - PresentEvent(MFTIME targetTime) - : QEvent(QEvent::Type(PresentSurface)) - , m_time(targetTime) - { - } - - int targetTime() - { - return m_time; - } - - private: - MFTIME m_time; - }; - - protected: - void customEvent(QEvent *event) - { - QMutexLocker locker(&m_mutex); - if (event->type() == StartSurface) { - if (m_state == State_WaitForSurfaceStart) { - m_startResult = startSurface(); - queueAsyncOperation(OpStart); - } - } else if (event->type() == StopSurface) { - stopSurface(); - } else { - QObject::customEvent(event); - } - } - HRESULT m_startResult; - - private: - HRESULT startSurface() - { - if (!m_surface->isFormatSupported(m_surfaceFormat)) - return S_FALSE; - if (!m_surface->start(m_surfaceFormat)) - return S_FALSE; - return S_OK; - } - - void stopSurface() - { - m_surface->stop(); - } - - enum FlushState - { - DropSamples = 0, - WriteSamples - }; - - // State enum: Defines the current state of the stream. - enum State - { - State_TypeNotSet = 0, // No media type is set - State_Ready, // Media type is set, Start has never been called. - State_Started, - State_Paused, - State_Stopped, - State_WaitForSurfaceStart, - State_Finalized, - State_Count = State_Finalized + 1 // Number of states - }; - - // StreamOperation: Defines various operations that can be performed on the stream. - enum StreamOperation - { - OpSetMediaType = 0, - OpPreroll, - OpStart, - OpRestart, - OpPause, - OpStop, - OpSetRate, - OpProcessSample, - OpPlaceMarker, - OpFinalize, - - Op_Count = OpFinalize + 1 // Number of operations - }; - - // AsyncOperation: - // Used to queue asynchronous operations. When we call MFPutWorkItem, we use this - // object for the callback state (pState). Then, when the callback is invoked, - // we can use the object to determine which asynchronous operation to perform. - class AsyncOperation : public IUnknown - { - public: - AsyncOperation(StreamOperation op) - :m_cRef(1), m_op(op) - { - } - - StreamOperation m_op; // The operation to perform. - - //from IUnknown - STDMETHODIMP QueryInterface(REFIID iid, void** ppv) - { - if (!ppv) - return E_POINTER; - if (iid == IID_IUnknown) { - *ppv = static_cast<IUnknown*>(this); - } else { - *ppv = NULL; - return E_NOINTERFACE; - } - AddRef(); - return S_OK; - } - STDMETHODIMP_(ULONG) AddRef() - { - return InterlockedIncrement(&m_cRef); - } - STDMETHODIMP_(ULONG) Release() - { - ULONG uCount = InterlockedDecrement(&m_cRef); - if (uCount == 0) - delete this; - // For thread safety, return a temporary variable. - return uCount; - } - - private: - long m_cRef; - virtual ~AsyncOperation() - { - Q_ASSERT(m_cRef == 0); - } - }; - - // ValidStateMatrix: Defines a look-up table that says which operations - // are valid from which states. - static BOOL ValidStateMatrix[State_Count][Op_Count]; - - long m_cRef; - QMutex m_mutex; - - IMFMediaType *m_currentMediaType; - State m_state; - IMFMediaSink *m_sink; - IMFMediaEventQueue *m_eventQueue; - DWORD m_workQueueId; - AsyncCallback<MediaStream> m_workQueueCB; - QList<IUnknown*> m_sampleQueue; - IMFAsyncResult *m_finalizeResult; // Result object for Finalize operation. - MFTIME m_startTime; // Presentation time when the clock started. - - bool m_shutdown; - QList<IMFMediaType*> m_mediaTypes; - QList<QVideoFrame::PixelFormat> m_pixelFormats; - int m_currentFormatIndex; - int m_bytesPerLine; - QVideoSurfaceFormat m_surfaceFormat; - QAbstractVideoSurface* m_surface; - MFVideoRendererControl *m_rendererControl; - - void clearMediaTypes() - { - foreach (IMFMediaType* mediaType, m_mediaTypes) - mediaType->Release(); - m_mediaTypes.clear(); - } - - int getMediaTypeIndex(IMFMediaType *mt) - { - GUID majorType; - if (FAILED(mt->GetMajorType(&majorType))) - return -1; - if (majorType != MFMediaType_Video) - return -1; - - GUID subType; - if (FAILED(mt->GetGUID(MF_MT_SUBTYPE, &subType))) - return -1; - - for (int index = 0; index < m_mediaTypes.size(); ++index) { - GUID st; - m_mediaTypes[index]->GetGUID(MF_MT_SUBTYPE, &st); - if (st == subType) - return index; - } - return -1; - } - - int getBytesPerLine(const QVideoSurfaceFormat &format) - { - switch (format.pixelFormat()) { - // 32 bpp packed formats. - case QVideoFrame::Format_RGB32: - case QVideoFrame::Format_AYUV444: - return format.frameWidth() * 4; - // 24 bpp packed formats. - case QVideoFrame::Format_RGB24: - return PAD_TO_DWORD(format.frameWidth() * 3); - // 16 bpp packed formats. - case QVideoFrame::Format_RGB565: - case QVideoFrame::Format_RGB555: - case QVideoFrame::Format_YUYV: - case QVideoFrame::Format_UYVY: - return PAD_TO_DWORD(format.frameWidth() * 2); - // Planar formats. - case QVideoFrame::Format_IMC1: - case QVideoFrame::Format_IMC2: - case QVideoFrame::Format_IMC3: - case QVideoFrame::Format_IMC4: - case QVideoFrame::Format_YV12: - case QVideoFrame::Format_NV12: - case QVideoFrame::Format_YUV420P: - return PAD_TO_DWORD(format.frameWidth()); - default: - return 0; - } - } - - // Callback for MFPutWorkItem. - HRESULT onDispatchWorkItem(IMFAsyncResult* pAsyncResult) - { - QMutexLocker locker(&m_mutex); - HRESULT hr = S_OK; - IUnknown *pState = NULL; - hr = pAsyncResult->GetState(&pState); - if (SUCCEEDED(hr)) { - // The state object is an AsncOperation object. - AsyncOperation *pOp = (AsyncOperation*)pState; - StreamOperation op = pOp->m_op; - switch (op) { - case OpStart: - endPreroll(S_FALSE); - if (m_state == State_WaitForSurfaceStart) { - hr = m_startResult; - m_state = State_Started; - } else if (!m_surface->isActive()) { - if (thread() == QThread::currentThread()) { - hr = startSurface(); - } - else { - m_state = State_WaitForSurfaceStart; - QCoreApplication::postEvent(m_rendererControl, new QChildEvent(QEvent::Type(StartSurface), this)); - break; - } - } - case OpRestart: - endPreroll(S_FALSE); - if (SUCCEEDED(hr)) { - // Send MEStreamSinkStarted. - hr = queueEvent(MEStreamSinkStarted, GUID_NULL, hr, NULL); - // Kick things off by requesting samples... - schedulePresentation(true); - // There might be samples queue from earlier (ie, while paused). - if (SUCCEEDED(hr)) - hr = processSamplesFromQueue(WriteSamples); - } - break; - case OpPreroll: - beginPreroll(); - break; - case OpStop: - // Drop samples from queue. - hr = processSamplesFromQueue(DropSamples); - if (m_scheduledBuffer) { - m_scheduledBuffer->Release(); - m_scheduledBuffer = NULL; - } - // Send the event even if the previous call failed. - hr = queueEvent(MEStreamSinkStopped, GUID_NULL, hr, NULL); - if (m_surface->isActive()) { - if (thread() == QThread::currentThread()) { - stopSurface(); - } - else { - QCoreApplication::postEvent(m_rendererControl, new QChildEvent(QEvent::Type(StopSurface), this)); - } - } - break; - case OpPause: - hr = queueEvent(MEStreamSinkPaused, GUID_NULL, hr, NULL); - break; - case OpSetRate: - //TODO: - break; - case OpProcessSample: - case OpPlaceMarker: - hr = dispatchProcessSample(pOp); - break; - case OpFinalize: - endPreroll(S_FALSE); - hr = dispatchFinalize(pOp); - break; - } - } - - if (pState) - pState->Release(); - return hr; - } - - - HRESULT queueEvent(MediaEventType met, REFGUID guidExtendedType, HRESULT hrStatus, const PROPVARIANT* pvValue) - { - HRESULT hr = S_OK; - if (m_shutdown) - hr = MF_E_SHUTDOWN; - if (SUCCEEDED(hr)) - hr = m_eventQueue->QueueEventParamVar(met, guidExtendedType, hrStatus, pvValue); - return hr; - } - - HRESULT validateOperation(StreamOperation op) - { - Q_ASSERT(!m_shutdown); - if (ValidStateMatrix[m_state][op]) - return S_OK; - else - return MF_E_INVALIDREQUEST; - } - - HRESULT queueAsyncOperation(StreamOperation op) - { - HRESULT hr = S_OK; - AsyncOperation *asyncOp = new AsyncOperation(op); - if (asyncOp == NULL) - hr = E_OUTOFMEMORY; - - if (SUCCEEDED(hr)) - hr = MFPutWorkItem(m_workQueueId, &m_workQueueCB, asyncOp); - - if (asyncOp) - asyncOp->Release(); - - return hr; - } - - HRESULT processSamplesFromQueue(FlushState bFlushData) - { - HRESULT hr = S_OK; - QList<IUnknown*>::Iterator pos = m_sampleQueue.begin(); - // Enumerate all of the samples/markers in the queue. - while (pos != m_sampleQueue.end()) { - IUnknown *pUnk = NULL; - IMarker *pMarker = NULL; - IMFSample *pSample = NULL; - pUnk = *pos; - // Figure out if this is a marker or a sample. - if (SUCCEEDED(hr)) { - hr = pUnk->QueryInterface(__uuidof(IMarker), (void**)&pMarker); - if (hr == E_NOINTERFACE) - hr = pUnk->QueryInterface(IID_IMFSample, (void**)&pSample); - } - - // Now handle the sample/marker appropriately. - if (SUCCEEDED(hr)) { - if (pMarker) { - hr = sendMarkerEvent(pMarker, bFlushData); - } else { - Q_ASSERT(pSample != NULL); // Not a marker, must be a sample - if (bFlushData == WriteSamples) - hr = processSampleData(pSample); - } - } - if (pMarker) - pMarker->Release(); - if (pSample) - pSample->Release(); - - if (FAILED(hr)) - break; - - pos++; - } - - clearSampleQueue(); - return hr; - } - - void beginPreroll() - { - if (m_prerolling) - return; - m_prerolling = true; - clearSampleQueue(); - clearBufferCache(); - queueEvent(MEStreamSinkRequestSample, GUID_NULL, S_OK, NULL); - } - - void endPreroll(HRESULT hrStatus) - { - if (!m_prerolling) - return; - m_prerolling = false; - queueEvent(MEStreamSinkPrerolled, GUID_NULL, hrStatus, NULL); - } - MFTIME m_prerollTargetTime; - bool m_prerolling; - - void clearSampleQueue() { - foreach (IUnknown* sample, m_sampleQueue) - sample->Release(); - m_sampleQueue.clear(); - } - - HRESULT sendMarkerEvent(IMarker *pMarker, FlushState FlushState) - { - HRESULT hr = S_OK; - HRESULT hrStatus = S_OK; // Status code for marker event. - if (FlushState == DropSamples) - hrStatus = E_ABORT; - - PROPVARIANT var; - PropVariantInit(&var); - - // Get the context data. - hr = pMarker->GetContext(&var); - - if (SUCCEEDED(hr)) - hr = queueEvent(MEStreamSinkMarker, GUID_NULL, hrStatus, &var); - - PropVariantClear(&var); - return hr; - } - - HRESULT dispatchProcessSample(AsyncOperation* pOp) - { - HRESULT hr = S_OK; - Q_ASSERT(pOp != NULL); - hr = processSamplesFromQueue(WriteSamples); - // We are in the middle of an asynchronous operation, so if something failed, send an error. - if (FAILED(hr)) - hr = queueEvent(MEError, GUID_NULL, hr, NULL); - - return hr; - } - - HRESULT dispatchFinalize(AsyncOperation*) - { - HRESULT hr = S_OK; - // Write any samples left in the queue... - hr = processSamplesFromQueue(WriteSamples); - - // Set the async status and invoke the callback. - m_finalizeResult->SetStatus(hr); - hr = MFInvokeCallback(m_finalizeResult); - return hr; - } - - HRESULT processSampleData(IMFSample *pSample) - { - LONGLONG time; - HRESULT hr = pSample->GetSampleTime(&time); - - if (m_prerolling) { - if (SUCCEEDED(hr) && time >= m_prerollTargetTime) { - IMFMediaBuffer *pBuffer = NULL; - hr = pSample->ConvertToContiguousBuffer(&pBuffer); - if (SUCCEEDED(hr)) { - SampleBuffer sb; - sb.m_buffer = pBuffer; - sb.m_time = time; - m_bufferCache.push_back(sb); - endPreroll(S_OK); - } - } else { - queueEvent(MEStreamSinkRequestSample, GUID_NULL, S_OK, NULL); - } - } else { - bool requestSample = true; - // If the time stamp is too early, just discard this sample. - if (SUCCEEDED(hr) && time >= m_startTime) { - IMFMediaBuffer *pBuffer = NULL; - hr = pSample->ConvertToContiguousBuffer(&pBuffer); - if (SUCCEEDED(hr)) { - SampleBuffer sb; - sb.m_buffer = pBuffer; - sb.m_time = time; - m_bufferCache.push_back(sb); - } - if (m_rate == 0) - requestSample = false; - } - schedulePresentation(requestSample); - } - return hr; - } - - class SampleBuffer - { - public: - IMFMediaBuffer *m_buffer; - LONGLONG m_time; - }; - QList<SampleBuffer> m_bufferCache; - static const int BUFFER_CACHE_SIZE = 2; - - void clearBufferCache() - { - foreach (SampleBuffer sb, m_bufferCache) - sb.m_buffer->Release(); - m_bufferCache.clear(); - } - - void schedulePresentation(bool requestSample) - { - if (m_state == State_Paused) - return; - if (!m_scheduledBuffer) { - //get time from presentation time - MFTIME currentTime = m_startTime, sysTime; - bool timeOK = true; - if (m_rate != 0) { - if (FAILED(m_presentationClock->GetCorrelatedTime(0, ¤tTime, &sysTime))) - timeOK = false; - } - while (!m_bufferCache.isEmpty()) { - SampleBuffer sb = m_bufferCache.first(); - m_bufferCache.pop_front(); - if (timeOK && currentTime > sb.m_time) { - sb.m_buffer->Release(); - qDebug() << "currentPresentTime =" << float(currentTime / 10000) * 0.001f << " and sampleTime is" << float(sb.m_time / 10000) * 0.001f; - continue; - } - m_scheduledBuffer = sb.m_buffer; - QCoreApplication::postEvent(m_rendererControl, new PresentEvent(sb.m_time)); - if (m_rate == 0) - queueEvent(MEStreamSinkScrubSampleComplete, GUID_NULL, S_OK, NULL); - break; - } - } - if (requestSample && m_bufferCache.size() < BUFFER_CACHE_SIZE) - queueEvent(MEStreamSinkRequestSample, GUID_NULL, S_OK, NULL); - } - IMFMediaBuffer *m_scheduledBuffer; - IMFPresentationClock *m_presentationClock; - float m_rate; - }; - - BOOL MediaStream::ValidStateMatrix[MediaStream::State_Count][MediaStream::Op_Count] = - { - // States: Operations: - // SetType Start Preroll, Restart Pause Stop SetRate Sample Marker Finalize - /* NotSet */ TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, - - /* Ready */ TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, - - /* Start */ FALSE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, - - /* Pause */ FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, - - /* Stop */ FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, - - /*WaitForSurfaceStart*/ FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, - - /* Final */ FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE - - // Note about states: - // 1. OnClockRestart should only be called from paused state. - // 2. While paused, the sink accepts samples but does not process them. - }; - - class MediaSink : public IMFFinalizableMediaSink, public IMFClockStateSink, public IMFMediaSinkPreroll - { - public: - MediaSink(MFVideoRendererControl *rendererControl) - : m_cRef(1) - , m_shutdown(false) - , m_presentationClock(0) - , m_playRate(1) - { - m_stream = new MediaStream(this, rendererControl); - } - - ~MediaSink() - { - Q_ASSERT(m_shutdown); - } - - void setSurface(QAbstractVideoSurface *surface) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return; - m_stream->setSurface(surface); - } - - void supportedFormatsChanged() - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return; - m_stream->supportedFormatsChanged(); - } - - void present() - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return; - m_stream->present(); - } - - MFTIME getTime() - { - QMutexLocker locker(&m_mutex); - if (!m_presentationClock) - return 0; - MFTIME time, sysTime; - m_presentationClock->GetCorrelatedTime(0, &time, &sysTime); - return time; - } - - float getPlayRate() - { - QMutexLocker locker(&m_mutex); - return m_playRate; - } - - //from IUnknown - STDMETHODIMP QueryInterface(REFIID riid, void** ppvObject) - { - if (!ppvObject) - return E_POINTER; - if (riid == IID_IMFMediaSink) { - *ppvObject = static_cast<IMFMediaSink*>(this); - } else if (riid == IID_IMFMediaSinkPreroll) { - *ppvObject = static_cast<IMFMediaSinkPreroll*>(this); - } else if (riid == IID_IMFClockStateSink) { - *ppvObject = static_cast<IMFClockStateSink*>(this); - } else if (riid == IID_IUnknown) { - *ppvObject = static_cast<IUnknown*>(static_cast<IMFFinalizableMediaSink*>(this)); - } else { - *ppvObject = NULL; - return E_NOINTERFACE; - } - AddRef(); - return S_OK; - } - - STDMETHODIMP_(ULONG) AddRef(void) - { - return InterlockedIncrement(&m_cRef); - } - - STDMETHODIMP_(ULONG) Release(void) - { - LONG cRef = InterlockedDecrement(&m_cRef); - if (cRef == 0) - delete this; - // For thread safety, return a temporary variable. - return cRef; - } - - - - //IMFMediaSinkPreroll - STDMETHODIMP NotifyPreroll(MFTIME hnsUpcomingStartTime) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - return m_stream->startPreroll(hnsUpcomingStartTime); - } - - //from IMFFinalizableMediaSink - STDMETHODIMP BeginFinalize(IMFAsyncCallback *pCallback, IUnknown *punkState) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - return m_stream->finalize(pCallback, punkState); - } - - STDMETHODIMP EndFinalize(IMFAsyncResult *pResult) - { - HRESULT hr = S_OK; - // Return the status code from the async result. - if (pResult == NULL) - hr = E_INVALIDARG; - else - hr = pResult->GetStatus(); - return hr; - } - - //from IMFMediaSink - STDMETHODIMP GetCharacteristics( - DWORD *pdwCharacteristics) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - *pdwCharacteristics = MEDIASINK_FIXED_STREAMS | MEDIASINK_CAN_PREROLL; - return S_OK; - } - - STDMETHODIMP AddStreamSink( - DWORD, - IMFMediaType *, - IMFStreamSink **) - { - QMutexLocker locker(&m_mutex); - return m_shutdown ? MF_E_SHUTDOWN : MF_E_STREAMSINKS_FIXED; - } - - STDMETHODIMP RemoveStreamSink( - DWORD) - { - QMutexLocker locker(&m_mutex); - return m_shutdown ? MF_E_SHUTDOWN : MF_E_STREAMSINKS_FIXED; - } - - STDMETHODIMP GetStreamSinkCount( - DWORD *pcStreamSinkCount) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - *pcStreamSinkCount = 1; - return S_OK; - } - - STDMETHODIMP GetStreamSinkByIndex( - DWORD dwIndex, - IMFStreamSink **ppStreamSink) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - - if (dwIndex != 0) - return MF_E_INVALIDINDEX; - - *ppStreamSink = m_stream; - m_stream->AddRef(); - return S_OK; - } - - STDMETHODIMP GetStreamSinkById( - DWORD dwStreamSinkIdentifier, - IMFStreamSink **ppStreamSink) - { - if (ppStreamSink == NULL) - return E_INVALIDARG; - if (dwStreamSinkIdentifier != MediaStream::DEFAULT_MEDIA_STREAM_ID) - return MF_E_INVALIDSTREAMNUMBER; - - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - - *ppStreamSink = m_stream; - m_stream->AddRef(); - return S_OK; - } - - STDMETHODIMP SetPresentationClock( - IMFPresentationClock *pPresentationClock) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - - if (m_presentationClock) { - m_presentationClock->RemoveClockStateSink(this); - m_presentationClock->Release(); - } - m_presentationClock = pPresentationClock; - if (m_presentationClock) { - m_presentationClock->AddRef(); - m_presentationClock->AddClockStateSink(this); - } - m_stream->setClock(m_presentationClock); - return S_OK; - } - - STDMETHODIMP GetPresentationClock( - IMFPresentationClock **ppPresentationClock) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - *ppPresentationClock = m_presentationClock; - if (m_presentationClock) { - m_presentationClock->AddRef(); - return S_OK; - } - return MF_E_NO_CLOCK; - } - - STDMETHODIMP Shutdown(void) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - - m_stream->shutdown(); - if (m_presentationClock) { - m_presentationClock->Release(); - m_presentationClock = NULL; - } - m_stream->Release(); - m_stream = NULL; - m_shutdown = true; - return S_OK; - } - - // IMFClockStateSink methods - STDMETHODIMP OnClockStart(MFTIME, LONGLONG llClockStartOffset) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - return m_stream->start(llClockStartOffset); - } - - STDMETHODIMP OnClockStop(MFTIME) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - return m_stream->stop(); - } - - STDMETHODIMP OnClockPause(MFTIME) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - return m_stream->pause(); - } - - STDMETHODIMP OnClockRestart(MFTIME) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - return m_stream->restart(); - } - - STDMETHODIMP OnClockSetRate(MFTIME, float flRate) - { - QMutexLocker locker(&m_mutex); - if (m_shutdown) - return MF_E_SHUTDOWN; - m_playRate = flRate; - return m_stream->setRate(flRate); - } - - private: - long m_cRef; - QMutex m_mutex; - bool m_shutdown; - IMFPresentationClock *m_presentationClock; - MediaStream *m_stream; - float m_playRate; - }; - - class VideoRendererActivate : public IMFActivate - { - public: - VideoRendererActivate(MFVideoRendererControl *rendererControl) - : m_cRef(1) - , m_sink(0) - , m_rendererControl(rendererControl) - , m_attributes(0) - { - MFCreateAttributes(&m_attributes, 0); - m_sink = new MediaSink(rendererControl); - } - - ~VideoRendererActivate() - { - m_attributes->Release(); - } - - //from IUnknown - STDMETHODIMP QueryInterface(REFIID riid, void** ppvObject) - { - if (!ppvObject) - return E_POINTER; - if (riid == IID_IMFActivate) { - *ppvObject = static_cast<IMFActivate*>(this); - } else if (riid == IID_IMFAttributes) { - *ppvObject = static_cast<IMFAttributes*>(this); - } else if (riid == IID_IUnknown) { - *ppvObject = static_cast<IUnknown*>(static_cast<IMFActivate*>(this)); - } else { - *ppvObject = NULL; - return E_NOINTERFACE; - } - AddRef(); - return S_OK; - } - - STDMETHODIMP_(ULONG) AddRef(void) - { - return InterlockedIncrement(&m_cRef); - } - - STDMETHODIMP_(ULONG) Release(void) - { - LONG cRef = InterlockedDecrement(&m_cRef); - if (cRef == 0) - delete this; - // For thread safety, return a temporary variable. - return cRef; - } - - //from IMFActivate - STDMETHODIMP ActivateObject(REFIID riid, void **ppv) - { - if (!ppv) - return E_INVALIDARG; - QMutexLocker locker(&m_mutex); - if (!m_sink) { - m_sink = new MediaSink(m_rendererControl); - if (m_surface) - m_sink->setSurface(m_surface); - } - return m_sink->QueryInterface(riid, ppv); - } - - STDMETHODIMP ShutdownObject(void) - { - QMutexLocker locker(&m_mutex); - HRESULT hr = S_OK; - if (m_sink) { - hr = m_sink->Shutdown(); - m_sink->Release(); - m_sink = NULL; - } - return hr; - } - - STDMETHODIMP DetachObject(void) - { - QMutexLocker locker(&m_mutex); - if (m_sink) { - m_sink->Release(); - m_sink = NULL; - } - return S_OK; - } - - //from IMFAttributes - STDMETHODIMP GetItem( - REFGUID guidKey, - PROPVARIANT *pValue) - { - return m_attributes->GetItem(guidKey, pValue); - } - - STDMETHODIMP GetItemType( - REFGUID guidKey, - MF_ATTRIBUTE_TYPE *pType) - { - return m_attributes->GetItemType(guidKey, pType); - } - - STDMETHODIMP CompareItem( - REFGUID guidKey, - REFPROPVARIANT Value, - BOOL *pbResult) - { - return m_attributes->CompareItem(guidKey, Value, pbResult); - } - - STDMETHODIMP Compare( - IMFAttributes *pTheirs, - MF_ATTRIBUTES_MATCH_TYPE MatchType, - BOOL *pbResult) - { - return m_attributes->Compare(pTheirs, MatchType, pbResult); - } - - STDMETHODIMP GetUINT32( - REFGUID guidKey, - UINT32 *punValue) - { - return m_attributes->GetUINT32(guidKey, punValue); - } - - STDMETHODIMP GetUINT64( - REFGUID guidKey, - UINT64 *punValue) - { - return m_attributes->GetUINT64(guidKey, punValue); - } - - STDMETHODIMP GetDouble( - REFGUID guidKey, - double *pfValue) - { - return m_attributes->GetDouble(guidKey, pfValue); - } - - STDMETHODIMP GetGUID( - REFGUID guidKey, - GUID *pguidValue) - { - return m_attributes->GetGUID(guidKey, pguidValue); - } - - STDMETHODIMP GetStringLength( - REFGUID guidKey, - UINT32 *pcchLength) - { - return m_attributes->GetStringLength(guidKey, pcchLength); - } - - STDMETHODIMP GetString( - REFGUID guidKey, - LPWSTR pwszValue, - UINT32 cchBufSize, - UINT32 *pcchLength) - { - return m_attributes->GetString(guidKey, pwszValue, cchBufSize, pcchLength); - } - - STDMETHODIMP GetAllocatedString( - REFGUID guidKey, - LPWSTR *ppwszValue, - UINT32 *pcchLength) - { - return m_attributes->GetAllocatedString(guidKey, ppwszValue, pcchLength); - } - - STDMETHODIMP GetBlobSize( - REFGUID guidKey, - UINT32 *pcbBlobSize) - { - return m_attributes->GetBlobSize(guidKey, pcbBlobSize); - } - - STDMETHODIMP GetBlob( - REFGUID guidKey, - UINT8 *pBuf, - UINT32 cbBufSize, - UINT32 *pcbBlobSize) - { - return m_attributes->GetBlob(guidKey, pBuf, cbBufSize, pcbBlobSize); - } - - STDMETHODIMP GetAllocatedBlob( - REFGUID guidKey, - UINT8 **ppBuf, - UINT32 *pcbSize) - { - return m_attributes->GetAllocatedBlob(guidKey, ppBuf, pcbSize); - } - - STDMETHODIMP GetUnknown( - REFGUID guidKey, - REFIID riid, - LPVOID *ppv) - { - return m_attributes->GetUnknown(guidKey, riid, ppv); - } - - STDMETHODIMP SetItem( - REFGUID guidKey, - REFPROPVARIANT Value) - { - return m_attributes->SetItem(guidKey, Value); - } - - STDMETHODIMP DeleteItem( - REFGUID guidKey) - { - return m_attributes->DeleteItem(guidKey); - } - - STDMETHODIMP DeleteAllItems(void) - { - return m_attributes->DeleteAllItems(); - } - - STDMETHODIMP SetUINT32( - REFGUID guidKey, - UINT32 unValue) - { - return m_attributes->SetUINT32(guidKey, unValue); - } - - STDMETHODIMP SetUINT64( - REFGUID guidKey, - UINT64 unValue) - { - return m_attributes->SetUINT64(guidKey, unValue); - } - - STDMETHODIMP SetDouble( - REFGUID guidKey, - double fValue) - { - return m_attributes->SetDouble(guidKey, fValue); - } - - STDMETHODIMP SetGUID( - REFGUID guidKey, - REFGUID guidValue) - { - return m_attributes->SetGUID(guidKey, guidValue); - } - - STDMETHODIMP SetString( - REFGUID guidKey, - LPCWSTR wszValue) - { - return m_attributes->SetString(guidKey, wszValue); - } - - STDMETHODIMP SetBlob( - REFGUID guidKey, - const UINT8 *pBuf, - UINT32 cbBufSize) - { - return m_attributes->SetBlob(guidKey, pBuf, cbBufSize); - } - - STDMETHODIMP SetUnknown( - REFGUID guidKey, - IUnknown *pUnknown) - { - return m_attributes->SetUnknown(guidKey, pUnknown); - } - - STDMETHODIMP LockStore(void) - { - return m_attributes->LockStore(); - } - - STDMETHODIMP UnlockStore(void) - { - return m_attributes->UnlockStore(); - } - - STDMETHODIMP GetCount( - UINT32 *pcItems) - { - return m_attributes->GetCount(pcItems); - } - - STDMETHODIMP GetItemByIndex( - UINT32 unIndex, - GUID *pguidKey, - PROPVARIANT *pValue) - { - return m_attributes->GetItemByIndex(unIndex, pguidKey, pValue); - } - - STDMETHODIMP CopyAllItems( - IMFAttributes *pDest) - { - return m_attributes->CopyAllItems(pDest); - } - - ///////////////////////////////// - void setSurface(QAbstractVideoSurface *surface) - { - QMutexLocker locker(&m_mutex); - if (m_surface == surface) - return; - - m_surface = surface; - - if (!m_sink) - return; - m_sink->setSurface(m_surface); - } - - void supportedFormatsChanged() - { - QMutexLocker locker(&m_mutex); - if (!m_sink) - return; - m_sink->supportedFormatsChanged(); - } - - void present() - { - QMutexLocker locker(&m_mutex); - if (!m_sink) - return; - m_sink->present(); - } - - MFTIME getTime() - { - if (m_sink) - return m_sink->getTime(); - return 0; - } - - float getPlayRate() - { - if (m_sink) - return m_sink->getPlayRate(); - return 1; - } - - private: - long m_cRef; - bool m_shutdown; - MediaSink *m_sink; - MFVideoRendererControl *m_rendererControl; - IMFAttributes *m_attributes; - QAbstractVideoSurface *m_surface; - QMutex m_mutex; - }; -} - -MFVideoRendererControl::MFVideoRendererControl(QObject *parent) - : QVideoRendererControl(parent) - , m_surface(0) - , m_callback(0) -{ - m_currentActivate = new VideoRendererActivate(this); -} - -MFVideoRendererControl::~MFVideoRendererControl() -{ - if (m_currentActivate) { - m_currentActivate->ShutdownObject(); - m_currentActivate->Release(); - } -} - -QAbstractVideoSurface *MFVideoRendererControl::surface() const -{ - return m_surface; -} - -void MFVideoRendererControl::setSurface(QAbstractVideoSurface *surface) -{ - if (m_surface == surface) - return; - - if (m_surface) - disconnect(m_surface, SIGNAL(supportedFormatsChanged()), this, SLOT(supportedFormatsChanged())); - m_surface = surface; - - if (m_surface) { - connect(m_surface, SIGNAL(supportedFormatsChanged()), this, SLOT(supportedFormatsChanged())); - } - static_cast<VideoRendererActivate*>(m_currentActivate)->setSurface(m_surface); -} - -void MFVideoRendererControl::customEvent(QEvent *event) -{ - if (event->type() == MediaStream::PresentSurface) { - MFTIME targetTime = static_cast<MediaStream::PresentEvent*>(event)->targetTime(); - MFTIME currentTime = static_cast<VideoRendererActivate*>(m_currentActivate)->getTime(); - float playRate = static_cast<VideoRendererActivate*>(m_currentActivate)->getPlayRate(); - if (playRate > 0.0001f && targetTime > currentTime) - QTimer::singleShot(int((float)((targetTime - currentTime) / 10000) / playRate), this, SLOT(present())); - else - present(); - return; - } - QChildEvent *childEvent = dynamic_cast<QChildEvent*>(event); - if (!childEvent) { - QObject::customEvent(event); - return; - } - static_cast<MediaStream*>(childEvent->child())->customEvent(event); -} - -void MFVideoRendererControl::supportedFormatsChanged() -{ - static_cast<VideoRendererActivate*>(m_currentActivate)->supportedFormatsChanged(); -} - -void MFVideoRendererControl::present() -{ - static_cast<VideoRendererActivate*>(m_currentActivate)->present(); -} - -IMFActivate* MFVideoRendererControl::currentActivate() const -{ - return m_currentActivate; -} - -#include "moc_mfvideorenderercontrol.cpp" -#include "mfvideorenderercontrol.moc" diff --git a/src/plugins/wmf/player/mfvideorenderercontrol.h b/src/plugins/wmf/player/mfvideorenderercontrol.h deleted file mode 100644 index ad02772..0000000 --- a/src/plugins/wmf/player/mfvideorenderercontrol.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MFVIDEORENDERERCONTROL_H -#define MFVIDEORENDERERCONTROL_H - -#include "../../src/multimedia/qvideorenderercontrol.h" -#include <mfapi.h> -#include <mfidl.h> - -QT_USE_NAMESPACE - -class MFVideoRendererControl : public QVideoRendererControl -{ - Q_OBJECT -public: - MFVideoRendererControl(QObject *parent = 0); - ~MFVideoRendererControl(); - - QAbstractVideoSurface *surface() const; - void setSurface(QAbstractVideoSurface *surface); - - IMFActivate* currentActivate() const; - -protected: - void customEvent(QEvent *event); - -private Q_SLOTS: - void supportedFormatsChanged(); - void present(); - -private: - QAbstractVideoSurface *m_surface; - IMFActivate *m_currentActivate; - IMFSampleGrabberSinkCallback *m_callback; -}; - -#endif diff --git a/src/plugins/wmf/player/player.pri b/src/plugins/wmf/player/player.pri deleted file mode 100644 index 58375ba..0000000 --- a/src/plugins/wmf/player/player.pri +++ /dev/null @@ -1,30 +0,0 @@ -INCLUDEPATH += $$PWD - -LIBS += -lstrmiids -ldmoguids -luuid -lmsdmo -lole32 -loleaut32 -lMf -lMfuuid -lMfplat -lPropsys - -DEFINES += QMEDIA_MEDIAFOUNDATION_PLAYER - -HEADERS += \ - $$PWD/mfplayerservice.h \ - $$PWD/mfplayersession.h \ - $$PWD/mfstream.h \ - $$PWD/sourceresolver.h \ - $$PWD/mfplayercontrol.h \ - $$PWD/mfvideorenderercontrol.h \ - $$PWD/mfaudioendpointcontrol.h \ - $$PWD/mfmetadatacontrol.h - -SOURCES += \ - $$PWD/mfplayerservice.cpp \ - $$PWD/mfplayersession.cpp \ - $$PWD/mfstream.cpp \ - $$PWD/sourceresolver.cpp \ - $$PWD/mfplayercontrol.cpp \ - $$PWD/mfvideorenderercontrol.cpp \ - $$PWD/mfaudioendpointcontrol.cpp \ - $$PWD/mfmetadatacontrol.cpp - -!simulator { - HEADERS += $$PWD/evr9videowindowcontrol.h - SOURCES += $$PWD/evr9videowindowcontrol.cpp -} diff --git a/src/plugins/wmf/player/sourceresolver.cpp b/src/plugins/wmf/player/sourceresolver.cpp deleted file mode 100644 index 9c62fa8..0000000 --- a/src/plugins/wmf/player/sourceresolver.cpp +++ /dev/null @@ -1,318 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "mfplayersession.h" -#include "mfstream.h" -#include "sourceresolver.h" -#include <Mferror.h> -#include <nserror.h> -#include <QtCore/qfile.h> - -/* - SourceResolver is separated from MFPlayerSession to handle the work of resolving a media source - asynchronously. You call SourceResolver::load to request resolving a media source asynchronously, - and it will emit mediaSourceReady() when resolving is done. You can call SourceResolver::cancel to - stop the previous load operation if there is any. -*/ - -SourceResolver::SourceResolver(QObject *parent) - : QObject(parent) - , m_cRef(1) - , m_cancelCookie(0) - , m_sourceResolver(0) - , m_mediaSource(0) - , m_stream(0) -{ -} - -SourceResolver::~SourceResolver() -{ - shutdown(); - if (m_cancelCookie) - m_cancelCookie->Release(); - if (m_sourceResolver) - m_sourceResolver->Release(); -} - -STDMETHODIMP SourceResolver::QueryInterface(REFIID riid, LPVOID *ppvObject) -{ - if (!ppvObject) - return E_POINTER; - if (riid == IID_IUnknown) { - *ppvObject = static_cast<IUnknown*>(this); - } else if (riid == IID_IMFAsyncCallback) { - *ppvObject = static_cast<IMFAsyncCallback*>(this); - } else { - *ppvObject = NULL; - return E_NOINTERFACE; - } - AddRef(); - return S_OK; -} - -STDMETHODIMP_(ULONG) SourceResolver::AddRef(void) -{ - return InterlockedIncrement(&m_cRef); -} - -STDMETHODIMP_(ULONG) SourceResolver::Release(void) -{ - LONG cRef = InterlockedDecrement(&m_cRef); - if (cRef == 0) - this->deleteLater(); - return cRef; -} - -HRESULT STDMETHODCALLTYPE SourceResolver::Invoke(IMFAsyncResult *pAsyncResult) -{ - QMutexLocker locker(&m_mutex); - MF_OBJECT_TYPE ObjectType = MF_OBJECT_INVALID; - IUnknown* pSource = NULL; - State *state = static_cast<State*>(pAsyncResult->GetStateNoAddRef()); - - HRESULT hr = S_OK; - if (state->fromStream()) - hr = m_sourceResolver->EndCreateObjectFromByteStream(pAsyncResult, &ObjectType, &pSource); - else - hr = m_sourceResolver->EndCreateObjectFromURL(pAsyncResult, &ObjectType, &pSource); - - if (state->sourceResolver() != m_sourceResolver) { - //This is a cancelled one - return S_OK; - } - - if (m_cancelCookie) { - m_cancelCookie->Release(); - m_cancelCookie = NULL; - } - - if (FAILED(hr)) { - emit error(hr); - return S_OK; - } - - if (m_mediaSource) { - m_mediaSource->Release(); - m_mediaSource = NULL; - } - - hr = pSource->QueryInterface(IID_PPV_ARGS(&m_mediaSource)); - if (FAILED(hr)) { - emit error(hr); - return S_OK; - } - - emit mediaSourceReady(); - - return S_OK; -} - -HRESULT STDMETHODCALLTYPE SourceResolver::GetParameters(DWORD*, DWORD*) -{ - return E_NOTIMPL; -} - -void SourceResolver::load(QMediaResourceList& resources, QIODevice* stream) -{ - QMutexLocker locker(&m_mutex); - HRESULT hr = S_OK; - if (!m_sourceResolver) - hr = MFCreateSourceResolver(&m_sourceResolver); - - if (m_stream) { - m_stream->Release(); - m_stream = NULL; - } - - if (FAILED(hr)) { - qWarning() << "Failed to create Source Resolver!"; - emit error(hr); - } else if (stream) { - if (resources.count() > 0) { - QMediaResource resource = resources.takeFirst(); - QUrl url = resource.url(); - m_stream = new MFStream(stream, false); - hr = m_sourceResolver->BeginCreateObjectFromByteStream(m_stream, reinterpret_cast<const OLECHAR *>(url.toString().utf16()), - MF_RESOLUTION_MEDIASOURCE, NULL, &m_cancelCookie, this, new State(m_sourceResolver, true)); - if (FAILED(hr)) { - qWarning() << "Unsupported stream!"; - emit error(hr); - } - } else { - hr = MF_E_UNSUPPORTED_BYTESTREAM_TYPE; - qWarning() << "Can't load stream without a hint of MIME type in a url"; - emit error(hr); - } - } else { - QMediaResource resource = resources.takeFirst(); - QUrl url = resource.url(); -#ifdef DEBUG_MEDIAFOUNDATION - qDebug() << "loading :" << url; - qDebug() << "url path =" << url.path().mid(1); -#endif -#ifdef TEST_STREAMING - //Testing stream function - if (url.scheme() == QLatin1String("file")) { - stream = new QFile(url.path().mid(1), this); - if (stream->open(QIODevice::ReadOnly)) { - m_stream = new MFStream(stream, true); - hr = m_sourceResolver->BeginCreateObjectFromByteStream(m_stream, reinterpret_cast<const OLECHAR *>(url.toString().utf16()), - MF_RESOLUTION_MEDIASOURCE, NULL, &m_cancelCookie, this, new State(m_sourceResolver, true)); - if (FAILED(hr)) { - qWarning() << "Unsupported stream!"; - emit error(hr); - } - } else { - delete stream; - emit error(QMediaPlayer::FormatError); - } - } else -#endif - if (url.scheme() == QLatin1String("qrc")) { - // If the canonical URL refers to a Qt resource, open with QFile and use - // the stream playback capability to play. - stream = new QFile(QLatin1Char(':') + url.path(), this); - if (stream->open(QIODevice::ReadOnly)) { - m_stream = new MFStream(stream, true); - hr = m_sourceResolver->BeginCreateObjectFromByteStream(m_stream, reinterpret_cast<const OLECHAR *>(url.toString().utf16()), - MF_RESOLUTION_MEDIASOURCE, NULL, &m_cancelCookie, this, new State(m_sourceResolver, true)); - if (FAILED(hr)) { - qWarning() << "Unsupported stream!"; - emit error(hr); - } - } else { - delete stream; - emit error(QMediaPlayer::FormatError); - } - } else { - hr = m_sourceResolver->BeginCreateObjectFromURL(reinterpret_cast<const OLECHAR *>(url.toString().utf16()), - MF_RESOLUTION_MEDIASOURCE, NULL, &m_cancelCookie, this, new State(m_sourceResolver, false)); - if (FAILED(hr)) { - qWarning() << "Unsupported url scheme!"; - emit error(hr); - } - } - } -} - -void SourceResolver::cancel() -{ - QMutexLocker locker(&m_mutex); - if (m_cancelCookie) { - m_sourceResolver->CancelObjectCreation(m_cancelCookie); - m_cancelCookie->Release(); - m_cancelCookie = NULL; - m_sourceResolver->Release(); - m_sourceResolver = NULL; - } -} - -void SourceResolver::shutdown() -{ - if (m_mediaSource) { - m_mediaSource->Shutdown(); - m_mediaSource->Release(); - m_mediaSource = NULL; - } - - if (m_stream) { - m_stream->Release(); - m_stream = NULL; - } -} - -IMFMediaSource* SourceResolver::mediaSource() const -{ - return m_mediaSource; -} - -///////////////////////////////////////////////////////////////////////////////// -SourceResolver::State::State(IMFSourceResolver *sourceResolver, bool fromStream) - : m_cRef(1) - , m_sourceResolver(sourceResolver) - , m_fromStream(fromStream) -{ - sourceResolver->AddRef(); -} - -SourceResolver::State::~State() -{ - m_sourceResolver->Release(); -} - -STDMETHODIMP SourceResolver::State::QueryInterface(REFIID riid, LPVOID *ppvObject) -{ - if (!ppvObject) - return E_POINTER; - if (riid == IID_IUnknown) { - *ppvObject = static_cast<IUnknown*>(this); - } else { - *ppvObject = NULL; - return E_NOINTERFACE; - } - AddRef(); - return S_OK; -} - -STDMETHODIMP_(ULONG) SourceResolver::State::AddRef(void) -{ - return InterlockedIncrement(&m_cRef); -} - -STDMETHODIMP_(ULONG) SourceResolver::State::Release(void) -{ - LONG cRef = InterlockedDecrement(&m_cRef); - if (cRef == 0) - delete this; - // For thread safety, return a temporary variable. - return cRef; -} - -IMFSourceResolver* SourceResolver::State::sourceResolver() const -{ - return m_sourceResolver; -} - -bool SourceResolver::State::fromStream() const -{ - return m_fromStream; -} - diff --git a/src/plugins/wmf/player/sourceresolver.h b/src/plugins/wmf/player/sourceresolver.h deleted file mode 100644 index 18eb737..0000000 --- a/src/plugins/wmf/player/sourceresolver.h +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef SOURCERESOLVER_H -#define SOURCERESOLVER_H - -#include "mfstream.h" -#include "qmediaresource.h" - -class SourceResolver: public QObject, public IMFAsyncCallback -{ - Q_OBJECT -public: - SourceResolver(QObject *parent); - - ~SourceResolver(); - - STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject); - STDMETHODIMP_(ULONG) AddRef(void); - STDMETHODIMP_(ULONG) Release(void); - - HRESULT STDMETHODCALLTYPE Invoke(IMFAsyncResult *pAsyncResult); - - HRESULT STDMETHODCALLTYPE GetParameters(DWORD*, DWORD*); - - void load(QMediaResourceList& resources, QIODevice* stream); - - void cancel(); - - void shutdown(); - - IMFMediaSource* mediaSource() const; - -Q_SIGNALS: - void error(long hr); - void mediaSourceReady(); - -private: - class State : public IUnknown - { - public: - State(IMFSourceResolver *sourceResolver, bool fromStream); - ~State(); - - STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject); - - STDMETHODIMP_(ULONG) AddRef(void); - - STDMETHODIMP_(ULONG) Release(void); - - IMFSourceResolver* sourceResolver() const; - bool fromStream() const; - - private: - long m_cRef; - IMFSourceResolver *m_sourceResolver; - bool m_fromStream; - }; - - long m_cRef; - IUnknown *m_cancelCookie; - IMFSourceResolver *m_sourceResolver; - IMFMediaSource *m_mediaSource; - MFStream *m_stream; - QMutex m_mutex; -}; - -#endif diff --git a/src/plugins/wmf/wmf.pro b/src/plugins/wmf/wmf.pro deleted file mode 100644 index d0b4ec3..0000000 --- a/src/plugins/wmf/wmf.pro +++ /dev/null @@ -1,16 +0,0 @@ -load(qt_module) - -TARGET = wmfengine -QT += multimedia-private network multimediawidgets-private -PLUGIN_TYPE=mediaservice - -load(qt_plugin) - -DESTDIR = $$QT.multimedia.plugins/$${PLUGIN_TYPE} - -DEPENDPATH += . - -HEADERS += wmfserviceplugin.h -SOURCES += wmfserviceplugin.cpp - -include (player/player.pri) diff --git a/src/plugins/wmf/wmfserviceplugin.cpp b/src/plugins/wmf/wmfserviceplugin.cpp deleted file mode 100644 index ccc4ada..0000000 --- a/src/plugins/wmf/wmfserviceplugin.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qstring.h> -#include <QtCore/qdebug.h> -#include <QtCore/QFile> - -#include "wmfserviceplugin.h" -#ifdef QMEDIA_MEDIAFOUNDATION_PLAYER -#include "mfplayerservice.h" -#endif -#include <qmediaserviceprovider.h> - -QStringList WMFServicePlugin::keys() const -{ - return QStringList() -#ifdef QMEDIA_MEDIAFOUNDATION_PLAYER - << QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER) -#endif - ; -} - -QMediaService* WMFServicePlugin::create(QString const& key) -{ -#ifdef QMEDIA_MEDIAFOUNDATION_PLAYER - if (key == QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER)) - return new MFPlayerService; -#endif - - //qDebug() << "unsupported key:" << key; - return 0; -} - -void WMFServicePlugin::release(QMediaService *service) -{ - delete service; -} - -QMediaServiceProviderHint::Features WMFServicePlugin::supportedFeatures( - const QByteArray &service) const -{ - if (service == Q_MEDIASERVICE_MEDIAPLAYER) - return QMediaServiceProviderHint::StreamPlayback; - else - return QMediaServiceProviderHint::Features(); -} - -QList<QByteArray> WMFServicePlugin::devices(const QByteArray &service) const -{ - return QList<QByteArray>(); -} - -QString WMFServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device) -{ - return QString(); -} - -Q_EXPORT_PLUGIN2(qtmedia_wmfengine, WMFServicePlugin); - diff --git a/src/plugins/wmf/wmfserviceplugin.h b/src/plugins/wmf/wmfserviceplugin.h deleted file mode 100644 index 9bcffaf..0000000 --- a/src/plugins/wmf/wmfserviceplugin.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** 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$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef WMFSERVICEPLUGIN_H -#define WMFSERVICEPLUGIN_H - -#include "qmediaserviceproviderplugin.h" - -QT_USE_NAMESPACE - -class WMFServicePlugin - : public QMediaServiceProviderPlugin - , public QMediaServiceSupportedDevicesInterface - , public QMediaServiceFeaturesInterface -{ - Q_OBJECT - Q_INTERFACES(QMediaServiceSupportedDevicesInterface) - Q_INTERFACES(QMediaServiceFeaturesInterface) -public: - QStringList keys() const; - QMediaService* create(QString const& key); - void release(QMediaService *service); - - QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const; - - QList<QByteArray> devices(const QByteArray &service) const; - QString deviceDescription(const QByteArray &service, const QByteArray &device); -}; - -#endif // DSSERVICEPLUGIN_H |