diff options
Diffstat (limited to 'src')
43 files changed, 685 insertions, 791 deletions
diff --git a/src/gsttools/qgstcodecsinfo.cpp b/src/gsttools/qgstcodecsinfo.cpp index edee797ae..230dc581b 100644 --- a/src/gsttools/qgstcodecsinfo.cpp +++ b/src/gsttools/qgstcodecsinfo.cpp @@ -41,62 +41,11 @@ #include "qgstutils_p.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); - } - - gst_caps_unref(caps); - gst_caps_unref(allCaps); -#else - Q_UNUSED(elementType); -#endif // GST_CHECK_VERSION(0,10,31) + updateCodecs(elementType); } QStringList QGstCodecsInfo::supportedCodecs() const @@ -106,23 +55,49 @@ QStringList QGstCodecsInfo::supportedCodecs() const QString QGstCodecsInfo::codecDescription(const QString &codec) const { - return m_codecDescriptions.value(codec); + return m_codecInfo.value(codec).description; } -#if GST_CHECK_VERSION(0,10,31) +QByteArray QGstCodecsInfo::codecElement(const QString &codec) const -/*! - List all supported caps for all installed elements of type \a elementType. +{ + return m_codecInfo.value(codec).elementName; +} + +QStringList QGstCodecsInfo::codecOptions(const QString &codec) const +{ + QStringList options; + + QByteArray elementName = m_codecInfo.value(codec).elementName; + if (elementName.isEmpty()) + return options; + + GstElement *element = gst_element_factory_make(elementName, NULL); + if (element) { + guint numProperties; + GParamSpec **properties = g_object_class_list_properties(G_OBJECT_GET_CLASS(element), + &numProperties); + for (guint j = 0; j < numProperties; ++j) { + GParamSpec *property = properties[j]; + // ignore some properties + if (strcmp(property->name, "name") == 0 || strcmp(property->name, "parent") == 0) + continue; + + options.append(QLatin1String(property->name)); + } + g_free(properties); + gst_object_unref(element); + } + + return options; +} - 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) +void QGstCodecsInfo::updateCodecs(ElementType elementType) { - GList *elements = gst_element_factory_list_get_elements(elementType, minimumRank); - GstCaps *res = gst_caps_new_empty(); + m_codecs.clear(); + m_codecInfo.clear(); + + GList *elements = elementFactories(elementType); QSet<QByteArray> fakeEncoderMimeTypes; fakeEncoderMimeTypes << "unknown/unknown" @@ -143,7 +118,7 @@ GstCaps* QGstCodecsInfo::supportedElementCaps(GstElementFactoryListType elementT GstStaticPadTemplate *padTemplate = (GstStaticPadTemplate *)padTemplates->data; padTemplates = padTemplates->next; - if (padTemplate->direction == padDirection) { + if (padTemplate->direction == GST_PAD_SRC) { 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); @@ -172,18 +147,101 @@ GstCaps* QGstCodecsInfo::supportedElementCaps(GstElementFactoryListType elementT } } -#if GST_CHECK_VERSION(1,0,0) - res = -#endif - gst_caps_merge_structure(res, newStructure); + GstCaps *newCaps = gst_caps_new_full(newStructure, NULL); + gchar *capsString = gst_caps_to_string(newCaps); + QString codec = QLatin1String(capsString); + if (capsString) + g_free(capsString); + GstRank rank = GstRank(gst_plugin_feature_get_rank(GST_PLUGIN_FEATURE(factory))); + + // If two elements provide the same codec, use the highest ranked one + QMap<QString, CodecInfo>::const_iterator it = m_codecInfo.find(codec); + if (it == m_codecInfo.constEnd() || it->rank < rank) { + if (it == m_codecInfo.constEnd()) + m_codecs.append(codec); + + CodecInfo info; + info.elementName = gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(factory)); + + gchar *description = gst_pb_utils_get_codec_description(newCaps); + info.description = QString::fromUtf8(description); + if (description) + g_free(description); + + info.rank = rank; + + m_codecInfo.insert(codec, info); + } + + gst_caps_unref(newCaps); } gst_caps_unref(caps); } } } + gst_plugin_feature_list_free(elements); +} + +#if !GST_CHECK_VERSION(0, 10, 31) +static gboolean element_filter(GstPluginFeature *feature, gpointer user_data) +{ + if (Q_UNLIKELY(!GST_IS_ELEMENT_FACTORY(feature))) + return FALSE; + + const QGstCodecsInfo::ElementType type = *reinterpret_cast<QGstCodecsInfo::ElementType *>(user_data); + + const gchar *klass = gst_element_factory_get_klass(GST_ELEMENT_FACTORY(feature)); + if (type == QGstCodecsInfo::AudioEncoder && !(strstr(klass, "Encoder") && strstr(klass, "Audio"))) + return FALSE; + if (type == QGstCodecsInfo::VideoEncoder && !(strstr(klass, "Encoder") && strstr(klass, "Video"))) + return FALSE; + if (type == QGstCodecsInfo::Muxer && !strstr(klass, "Muxer")) + return FALSE; + + guint rank = gst_plugin_feature_get_rank(feature); + if (rank < GST_RANK_MARGINAL) + return FALSE; + + return TRUE; +} + +static gint compare_plugin_func(const void *item1, const void *item2) +{ + GstPluginFeature *f1 = reinterpret_cast<GstPluginFeature *>(const_cast<void *>(item1)); + GstPluginFeature *f2 = reinterpret_cast<GstPluginFeature *>(const_cast<void *>(item2)); - return res; + gint diff = gst_plugin_feature_get_rank(f2) - gst_plugin_feature_get_rank(f1); + if (diff != 0) + return diff; + + return strcmp(gst_plugin_feature_get_name(f1), gst_plugin_feature_get_name (f2)); +} +#endif + +GList *QGstCodecsInfo::elementFactories(ElementType elementType) const +{ +#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; + } + + return gst_element_factory_list_get_elements(gstElementType, GST_RANK_MARGINAL); +#else + GList *result = gst_registry_feature_filter(gst_registry_get_default(), + element_filter, + FALSE, &elementType); + result = g_list_sort(result, compare_plugin_func); + return result; +#endif } -#endif //GST_CHECK_VERSION(0,10,31) diff --git a/src/gsttools/qgstutils.cpp b/src/gsttools/qgstutils.cpp index a2b35073c..902c71013 100644 --- a/src/gsttools/qgstutils.cpp +++ b/src/gsttools/qgstutils.cpp @@ -1429,6 +1429,40 @@ QPair<qreal, qreal> QGstUtils::structureFrameRateRange(const GstStructure *s) return rate; } +typedef QMap<QString, QString> FileExtensionMap; +Q_GLOBAL_STATIC(FileExtensionMap, fileExtensionMap) + +QString QGstUtils::fileExtensionForMimeType(const QString &mimeType) +{ + if (fileExtensionMap->isEmpty()) { + //extension for containers hard to guess from mimetype + fileExtensionMap->insert("video/x-matroska", "mkv"); + fileExtensionMap->insert("video/quicktime", "mov"); + fileExtensionMap->insert("video/x-msvideo", "avi"); + fileExtensionMap->insert("video/msvideo", "avi"); + fileExtensionMap->insert("audio/mpeg", "mp3"); + fileExtensionMap->insert("application/x-shockwave-flash", "swf"); + fileExtensionMap->insert("application/x-pn-realmedia", "rm"); + } + + //for container names like avi instead of video/x-msvideo, use it as extension + if (!mimeType.contains('/')) + return mimeType; + + QString format = mimeType.left(mimeType.indexOf(',')); + QString extension = fileExtensionMap->value(format); + + if (!extension.isEmpty() || format.isEmpty()) + return extension; + + QRegExp rx("[-/]([\\w]+)$"); + + if (rx.indexIn(format) != -1) + extension = rx.cap(1); + + return extension; +} + void qt_gst_object_ref_sink(gpointer object) { #if GST_CHECK_VERSION(0,10,24) diff --git a/src/imports/multimedia/Video.qml b/src/imports/multimedia/Video.qml index b3fee7495..66b86c74b 100644 --- a/src/imports/multimedia/Video.qml +++ b/src/imports/multimedia/Video.qml @@ -38,7 +38,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtMultimedia 5.6 +import QtMultimedia 5.9 /*! \qmltype Video @@ -384,6 +384,34 @@ Item { property alias autoPlay: player.autoPlay /*! + \qmlproperty int Video::notifyInterval + + The interval at which notifiable properties will update. + + The notifiable properties are \l position and \l bufferProgress. + + The interval is expressed in milliseconds, the default value is 1000. + + \since 5.9 + */ + property alias notifyInterval: player.notifyInterval + + /*! + \qmlproperty int Video::loops + + This property holds the number of times the media is played. A value of \c 0 or \c 1 means + the media will be played only once; set to \c MediaPlayer.Infinite to enable infinite looping. + + The value can be changed while the media is playing, in which case it will update + the remaining loops to the new value. + + The default is \c 1. + + \since 5.9 + */ + property alias loops: player.loops + + /*! \qmlsignal Video::paused() This signal is emitted when playback is paused. diff --git a/src/imports/multimedia/multimedia.cpp b/src/imports/multimedia/multimedia.cpp index b7ab473c7..1b8c87cc0 100644 --- a/src/imports/multimedia/multimedia.cpp +++ b/src/imports/multimedia/multimedia.cpp @@ -143,6 +143,14 @@ public: // 5.8 types (nothing new, re-register one of the types) qmlRegisterType<QSoundEffect>(uri, 5, 8, "SoundEffect"); + // 5.9 types + qmlRegisterType<QDeclarativeAudio, 2>(uri, 5, 9, "Audio"); + qmlRegisterType<QDeclarativeAudio, 2>(uri, 5, 9, "MediaPlayer"); + qmlRegisterUncreatableType<QDeclarativeCameraCapture, 1>(uri, 5, 9, "CameraCapture", + trUtf8("CameraCapture is provided by Camera")); + qmlRegisterUncreatableType<QDeclarativeCameraFlash, 1>(uri, 5, 9, "CameraFlash", + trUtf8("CameraFlash is provided by Camera")); + qmlRegisterType<QDeclarativeMediaMetaData>(); qmlRegisterType<QAbstractVideoFilter>(); } diff --git a/src/imports/multimedia/qdeclarativeaudio.cpp b/src/imports/multimedia/qdeclarativeaudio.cpp index 5a065072c..75bb21ee5 100644 --- a/src/imports/multimedia/qdeclarativeaudio.cpp +++ b/src/imports/multimedia/qdeclarativeaudio.cpp @@ -119,6 +119,7 @@ QDeclarativeAudio::QDeclarativeAudio(QObject *parent) , m_status(QMediaPlayer::NoMedia) , m_error(QMediaPlayer::ServiceMissingError) , m_player(0) + , m_notifyInterval(1000) { } @@ -201,6 +202,34 @@ void QDeclarativeAudio::setAudioRole(QDeclarativeAudio::AudioRole audioRole) } /*! + \qmlproperty int QtMultimedia::Audio::notifyInterval + + The interval at which notifiable properties will update. + + The notifiable properties are \l position and \l bufferProgress. + + The interval is expressed in milliseconds, the default value is 1000. + + \since 5.9 +*/ +int QDeclarativeAudio::notifyInterval() const +{ + return m_complete ? m_player->notifyInterval() : m_notifyInterval; +} + +void QDeclarativeAudio::setNotifyInterval(int value) +{ + if (notifyInterval() == value) + return; + if (m_complete) { + m_player->setNotifyInterval(value); + return; + } + m_notifyInterval = value; + emit notifyIntervalChanged(); +} + +/*! \qmlmethod list<int> QtMultimedia::Audio::supportedAudioRoles() Returns a list of supported audio roles. @@ -821,6 +850,8 @@ void QDeclarativeAudio::classBegin() this, SIGNAL(hasVideoChanged())); connect(m_player, SIGNAL(audioRoleChanged(QAudio::Role)), this, SIGNAL(audioRoleChanged())); + connect(m_player, SIGNAL(notifyIntervalChanged(int)), + this, SIGNAL(notifyIntervalChanged())); m_error = m_player->availability() == QMultimedia::ServiceMissing ? QMediaPlayer::ServiceMissingError : QMediaPlayer::NoError; @@ -845,6 +876,8 @@ void QDeclarativeAudio::componentComplete() m_player->setPlaybackRate(m_playbackRate); if (m_audioRole != UnknownRole) m_player->setAudioRole(QAudio::Role(m_audioRole)); + if (m_notifyInterval != m_player->notifyInterval()) + m_player->setNotifyInterval(m_notifyInterval); if (!m_content.isNull() && (m_autoLoad || m_autoPlay)) { m_player->setMedia(m_content, 0); @@ -1165,6 +1198,18 @@ void QDeclarativeAudio::_q_mediaChanged(const QMediaContent &media) */ /*! + \qmlproperty int QtMultimedia::MediaPlayer::notifyInterval + + The interval at which notifiable properties will update. + + The notifiable properties are \l position and \l bufferProgress. + + The interval is expressed in milliseconds, the default value is 1000. + + \since 5.9 +*/ + +/*! \qmlmethod QtMultimedia::MediaPlayer::play() Starts playback of the media. diff --git a/src/imports/multimedia/qdeclarativeaudio_p.h b/src/imports/multimedia/qdeclarativeaudio_p.h index 48c8704e9..ad30fa729 100644 --- a/src/imports/multimedia/qdeclarativeaudio_p.h +++ b/src/imports/multimedia/qdeclarativeaudio_p.h @@ -95,6 +95,7 @@ class QDeclarativeAudio : public QObject, public QQmlParserStatus Q_PROPERTY(QObject *mediaObject READ mediaObject NOTIFY mediaObjectChanged SCRIPTABLE false DESIGNABLE false) Q_PROPERTY(Availability availability READ availability NOTIFY availabilityChanged) Q_PROPERTY(AudioRole audioRole READ audioRole WRITE setAudioRole NOTIFY audioRoleChanged REVISION 1) + Q_PROPERTY(int notifyInterval READ notifyInterval WRITE setNotifyInterval NOTIFY notifyIntervalChanged REVISION 2) Q_ENUMS(Status) Q_ENUMS(Error) Q_ENUMS(Loop) @@ -214,6 +215,8 @@ public: bool autoPlay() const; void setAutoPlay(bool autoplay); + int notifyInterval() const; + void setNotifyInterval(int); public Q_SLOTS: void play(); @@ -260,6 +263,7 @@ Q_SIGNALS: void error(QDeclarativeAudio::Error error, const QString &errorString); void mediaObjectChanged(); + Q_REVISION(2) void notifyIntervalChanged(); private Q_SLOTS: void _q_error(QMediaPlayer::Error); @@ -294,6 +298,7 @@ private: QScopedPointer<QDeclarativeMediaMetaData> m_metaData; QMediaPlayer *m_player; + int m_notifyInterval; friend class QDeclarativeMediaBaseAnimation; }; diff --git a/src/imports/multimedia/qdeclarativecameracapture.cpp b/src/imports/multimedia/qdeclarativecameracapture.cpp index 32f3cfc37..22d87ec22 100644 --- a/src/imports/multimedia/qdeclarativecameracapture.cpp +++ b/src/imports/multimedia/qdeclarativecameracapture.cpp @@ -112,6 +112,9 @@ QDeclarativeCameraCapture::QDeclarativeCameraCapture(QCamera *camera, QObject *p connect(m_capture, SIGNAL(error(int,QCameraImageCapture::Error,QString)), this, SLOT(_q_captureFailed(int,QCameraImageCapture::Error,QString))); + connect(m_camera, SIGNAL(statusChanged(QCamera::Status)), + this, SLOT(_q_cameraStatusChanged(QCamera::Status))); + QMediaService *service = camera->service(); m_metadataWriterControl = service ? service->requestControl<QMetaDataWriterControl*>() : 0; } @@ -239,6 +242,15 @@ void QDeclarativeCameraCapture::_q_captureFailed(int id, QCameraImageCapture::Er qWarning() << "QCameraImageCapture error:" << message; emit captureFailed(id, message); } + +void QDeclarativeCameraCapture::_q_cameraStatusChanged(QCamera::Status status) +{ + if (status != QCamera::UnloadedStatus && status != QCamera::LoadedStatus && + status != QCamera::ActiveStatus) + return; + + emit supportedResolutionsChanged(); +} /*! \property QDeclarativeCameraCapture::resolution @@ -251,6 +263,8 @@ void QDeclarativeCameraCapture::_q_captureFailed(int id, QCameraImageCapture::Er This property holds the resolution/size of the image to be captured. If empty, the system chooses the appropriate resolution. + + \sa supportedResolutions */ QSize QDeclarativeCameraCapture::resolution() @@ -289,6 +303,24 @@ QString QDeclarativeCameraCapture::errorString() const } /*! + \qmlproperty list<size> QtMultimedia::CameraCapture::supportedResolutions + + This property holds a list of resolutions which are supported for capturing. + The information can be used to set a valid \e resolution. If the camera isn't + loaded, the list will be empty. + + \since 5.9 + \sa resolution + */ +QVariantList QDeclarativeCameraCapture::supportedResolutions() +{ + QVariantList supportedResolutions; + for (const QSize &res : m_capture->supportedResolutions()) + supportedResolutions.append(QVariant(res)); + return supportedResolutions; +} + +/*! \qmlmethod QtMultimedia::CameraCapture::setMetadata(key, value) diff --git a/src/imports/multimedia/qdeclarativecameracapture_p.h b/src/imports/multimedia/qdeclarativecameracapture_p.h index 06cb1b8f1..1b8066a4e 100644 --- a/src/imports/multimedia/qdeclarativecameracapture_p.h +++ b/src/imports/multimedia/qdeclarativecameracapture_p.h @@ -69,6 +69,7 @@ class QDeclarativeCameraCapture : public QObject Q_PROPERTY(QString capturedImagePath READ capturedImagePath NOTIFY imageSaved) Q_PROPERTY(QSize resolution READ resolution WRITE setResolution NOTIFY resolutionChanged) Q_PROPERTY(QString errorString READ errorString NOTIFY captureFailed) + Q_PROPERTY(QVariantList supportedResolutions READ supportedResolutions NOTIFY supportedResolutionsChanged REVISION 1) public: ~QDeclarativeCameraCapture(); @@ -80,6 +81,7 @@ public: QString capturedImagePath() const; QCameraImageCapture::Error error() const; QString errorString() const; + QVariantList supportedResolutions(); public Q_SLOTS: int capture(); @@ -99,12 +101,14 @@ Q_SIGNALS: void captureFailed(int requestId, const QString &message); void resolutionChanged(const QSize &); + void supportedResolutionsChanged(); private slots: void _q_imageCaptured(int, const QImage&); void _q_imageSaved(int, const QString&); void _q_imageMetadataAvailable(int, const QString &, const QVariant &); void _q_captureFailed(int, QCameraImageCapture::Error, const QString&); + void _q_cameraStatusChanged(QCamera::Status status); private: friend class QDeclarativeCamera; diff --git a/src/imports/multimedia/qdeclarativecameraflash.cpp b/src/imports/multimedia/qdeclarativecameraflash.cpp index f8adc5e71..551b88aef 100644 --- a/src/imports/multimedia/qdeclarativecameraflash.cpp +++ b/src/imports/multimedia/qdeclarativecameraflash.cpp @@ -73,11 +73,13 @@ QT_BEGIN_NAMESPACE /*! Construct a declarative camera flash object using \a parent object. */ -QDeclarativeCameraFlash::QDeclarativeCameraFlash(QCamera *camera, QObject *parent) : - QObject(parent) +QDeclarativeCameraFlash::QDeclarativeCameraFlash(QCamera *camera, QObject *parent) + : QObject(parent) { m_exposure = camera->exposure(); connect(m_exposure, SIGNAL(flashReady(bool)), this, SIGNAL(flashReady(bool))); + connect(camera, SIGNAL(statusChanged(QCamera::Status)), + this, SLOT(_q_cameraStatusChanged(QCamera::Status))); } QDeclarativeCameraFlash::~QDeclarativeCameraFlash() @@ -133,6 +135,51 @@ void QDeclarativeCameraFlash::setFlashMode(QDeclarativeCameraFlash::FlashMode mo } } +void QDeclarativeCameraFlash::_q_cameraStatusChanged(QCamera::Status status) +{ + if (status != QCamera::UnloadedStatus && status != QCamera::LoadedStatus && + status != QCamera::ActiveStatus) + return; + + emit supportedModesChanged(); +} + +/*! + \qmlproperty list<FlashMode> QtMultimedia::CameraFlash::supportedModes + + This property holds the supported flash modes of the camera. If the list + only contains Camera.FlashOff, no flash is supported. + + \code + Camera { + id: camera + flash { + onSupportedModesChanged { + if (flash.supportedModes.length == 1) { + // no flash supported + } else { + // some flash is supported + } + } + } + } + \endcode + + \since 5.9 + \sa mode + */ +QVariantList QDeclarativeCameraFlash::supportedModes() const +{ + QVariantList supportedModes; + + for (int i=1; i <= (int) QCameraExposure::FlashManual; i = (i << 1)) { + if (m_exposure->isFlashModeSupported((QCameraExposure::FlashMode) i)) + supportedModes.append(QVariant(i)); + } + + return supportedModes; +} + /*! \qmlsignal QtMultimedia::CameraFlash::flashModeChanged(int) This signal is emitted when the \c flashMode property is changed. diff --git a/src/imports/multimedia/qdeclarativecameraflash_p.h b/src/imports/multimedia/qdeclarativecameraflash_p.h index 9247c7202..df037c4d6 100644 --- a/src/imports/multimedia/qdeclarativecameraflash_p.h +++ b/src/imports/multimedia/qdeclarativecameraflash_p.h @@ -63,6 +63,7 @@ class QDeclarativeCameraFlash : public QObject Q_OBJECT Q_PROPERTY(bool ready READ isFlashReady NOTIFY flashReady) Q_PROPERTY(FlashMode mode READ flashMode WRITE setFlashMode NOTIFY flashModeChanged) + Q_PROPERTY(QVariantList supportedModes READ supportedModes NOTIFY supportedModesChanged REVISION 1) Q_ENUMS(FlashMode) public: @@ -83,6 +84,7 @@ public: FlashMode flashMode() const; bool isFlashReady() const; + QVariantList supportedModes() const; public Q_SLOTS: void setFlashMode(FlashMode); @@ -90,6 +92,10 @@ public Q_SLOTS: Q_SIGNALS: void flashReady(bool status); void flashModeChanged(FlashMode); + void supportedModesChanged(); + +private slots: + void _q_cameraStatusChanged(QCamera::Status status); private: friend class QDeclarativeCamera; diff --git a/src/multimedia/gsttools_headers/qgstcodecsinfo_p.h b/src/multimedia/gsttools_headers/qgstcodecsinfo_p.h index 64e9ac21f..af1a4486f 100644 --- a/src/multimedia/gsttools_headers/qgstcodecsinfo_p.h +++ b/src/multimedia/gsttools_headers/qgstcodecsinfo_p.h @@ -63,22 +63,28 @@ class QGstCodecsInfo public: enum ElementType { AudioEncoder, VideoEncoder, Muxer }; + struct CodecInfo { + QString description; + QByteArray elementName; + GstRank rank; + }; + 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 + QByteArray codecElement(const QString &codec) const; + QStringList codecOptions(const QString &codec) const; private: + void updateCodecs(ElementType elementType); + GList *elementFactories(ElementType elementType) const; + QStringList m_codecs; - QMap<QString,QString> m_codecDescriptions; + QMap<QString, CodecInfo> m_codecInfo; }; +Q_DECLARE_TYPEINFO(QGstCodecsInfo::CodecInfo, Q_MOVABLE_TYPE); QT_END_NAMESPACE diff --git a/src/multimedia/gsttools_headers/qgstutils_p.h b/src/multimedia/gsttools_headers/qgstutils_p.h index 68c9ecda1..8b7de3661 100644 --- a/src/multimedia/gsttools_headers/qgstutils_p.h +++ b/src/multimedia/gsttools_headers/qgstutils_p.h @@ -146,6 +146,7 @@ namespace QGstUtils { QSize structurePixelAspectRatio(const GstStructure *s); QPair<qreal, qreal> structureFrameRateRange(const GstStructure *s); + QString fileExtensionForMimeType(const QString &mimeType); } void qt_gst_object_ref_sink(gpointer object); diff --git a/src/plugins/avfoundation/camera/avfcameraservice.mm b/src/plugins/avfoundation/camera/avfcameraservice.mm index a1213be3b..7fd04250e 100644 --- a/src/plugins/avfoundation/camera/avfcameraservice.mm +++ b/src/plugins/avfoundation/camera/avfcameraservice.mm @@ -37,9 +37,9 @@ ** ****************************************************************************/ +#include <QtCore/qoperatingsystemversion.h> #include <QtCore/qvariant.h> #include <QtCore/qdebug.h> -#include <QtCore/qsysinfo.h> #include "avfcameraservice.h" #include "avfcameracontrol.h" @@ -96,7 +96,7 @@ AVFCameraService::AVFCameraService(QObject *parent): m_cameraFocusControl = new AVFCameraFocusControl(this); m_cameraExposureControl = 0; #if defined(Q_OS_IOS) && QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_8_0) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_8_0) + if (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::IOS, 8)) m_cameraExposureControl = new AVFCameraExposureControl(this); #endif diff --git a/src/plugins/avfoundation/camera/avfcamerasession.mm b/src/plugins/avfoundation/camera/avfcamerasession.mm index c32b072ef..0b7c0e9d8 100644 --- a/src/plugins/avfoundation/camera/avfcamerasession.mm +++ b/src/plugins/avfoundation/camera/avfcamerasession.mm @@ -432,18 +432,12 @@ void AVFCameraSession::removeProbe(AVFMediaVideoProbeControl *probe) FourCharCode AVFCameraSession::defaultCodec() { if (!m_defaultCodec) { -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) - if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_7, QSysInfo::MV_IOS_7_0)) { - if (AVCaptureDevice *device = videoCaptureDevice()) { - AVCaptureDeviceFormat *format = device.activeFormat; - if (!format || !format.formatDescription) - return m_defaultCodec; - m_defaultCodec = CMVideoFormatDescriptionGetCodecType(format.formatDescription); - } + if (AVCaptureDevice *device = videoCaptureDevice()) { + AVCaptureDeviceFormat *format = device.activeFormat; + if (!format || !format.formatDescription) + return m_defaultCodec; + m_defaultCodec = CMVideoFormatDescriptionGetCodecType(format.formatDescription); } -#else - // TODO: extract media subtype. -#endif } return m_defaultCodec; } diff --git a/src/plugins/avfoundation/camera/avfcamerautility.h b/src/plugins/avfoundation/camera/avfcamerautility.h index 4da5f751e..ba1bd3861 100644 --- a/src/plugins/avfoundation/camera/avfcamerautility.h +++ b/src/plugins/avfoundation/camera/avfcamerautility.h @@ -40,7 +40,6 @@ #ifndef AVFCAMERAUTILITY_H #define AVFCAMERAUTILITY_H -#include <QtCore/qsysinfo.h> #include <QtCore/qglobal.h> #include <QtCore/qvector.h> #include <QtCore/qdebug.h> @@ -152,23 +151,9 @@ private: Q_DISABLE_COPY(AVFScopedPointer); }; -inline QSysInfo::MacVersion qt_OS_limit(QSysInfo::MacVersion osxVersion, - QSysInfo::MacVersion iosVersion) -{ -#ifdef Q_OS_OSX - Q_UNUSED(iosVersion) - return osxVersion; -#else - Q_UNUSED(osxVersion) - return iosVersion; -#endif -} - typedef QPair<qreal, qreal> AVFPSRange; AVFPSRange qt_connection_framerates(AVCaptureConnection *videoConnection); -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) - QVector<AVCaptureDeviceFormat *> qt_unique_device_formats(AVCaptureDevice *captureDevice, FourCharCode preferredFormat); QSize qt_device_format_resolution(AVCaptureDeviceFormat *format); @@ -185,8 +170,6 @@ AVFrameRateRange *qt_find_supported_framerate_range(AVCaptureDeviceFormat *forma bool qt_formats_are_equal(AVCaptureDeviceFormat *f1, AVCaptureDeviceFormat *f2); bool qt_set_active_format(AVCaptureDevice *captureDevice, AVCaptureDeviceFormat *format, bool preserveFps); -#endif - AVFPSRange qt_current_framerates(AVCaptureDevice *captureDevice, AVCaptureConnection *videoConnection); void qt_set_framerate_limits(AVCaptureDevice *captureDevice, AVCaptureConnection *videoConnection, qreal minFPS, qreal maxFPS); diff --git a/src/plugins/avfoundation/camera/avfcamerautility.mm b/src/plugins/avfoundation/camera/avfcamerautility.mm index 279642e4f..872075e0f 100644 --- a/src/plugins/avfoundation/camera/avfcamerautility.mm +++ b/src/plugins/avfoundation/camera/avfcamerautility.mm @@ -40,6 +40,7 @@ #include "avfcamerautility.h" #include "avfcameradebug.h" +#include <QtCore/qoperatingsystemversion.h> #include <QtCore/qvector.h> #include <QtCore/qpair.h> #include <private/qmultimediautils_p.h> @@ -66,26 +67,17 @@ AVFPSRange qt_connection_framerates(AVCaptureConnection *videoConnection) } } -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_5_0) -#if QT_OSX_DEPLOYMENT_TARGET_BELOW(__MAC_10_9) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_9) -#endif - { - if (videoConnection.supportsVideoMaxFrameDuration) { - const CMTime cmMax = videoConnection.videoMaxFrameDuration; - if (CMTimeCompare(cmMax, kCMTimeInvalid)) { - if (const Float64 maxSeconds = CMTimeGetSeconds(cmMax)) - newRange.first = 1. / maxSeconds; - } + if (videoConnection.supportsVideoMaxFrameDuration) { + const CMTime cmMax = videoConnection.videoMaxFrameDuration; + if (CMTimeCompare(cmMax, kCMTimeInvalid)) { + if (const Float64 maxSeconds = CMTimeGetSeconds(cmMax)) + newRange.first = 1. / maxSeconds; } } -#endif return newRange; } -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) - namespace { inline bool qt_area_sane(const QSize &size) @@ -189,7 +181,7 @@ QSize qt_device_format_high_resolution(AVCaptureDeviceFormat *format) Q_ASSERT(format); QSize res; #if defined(Q_OS_IOS) && QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_8_0) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_8_0) { + if (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::IOS, 8)) { const CMVideoDimensions hrDim(format.highResolutionStillImageDimensions); res.setWidth(hrDim.width); res.setHeight(hrDim.height); @@ -436,8 +428,6 @@ bool qt_set_active_format(AVCaptureDevice *captureDevice, AVCaptureDeviceFormat return true; } -#endif // SDK - void qt_set_framerate_limits(AVCaptureConnection *videoConnection, qreal minFPS, qreal maxFPS) { Q_ASSERT(videoConnection); @@ -458,32 +448,17 @@ void qt_set_framerate_limits(AVCaptureConnection *videoConnection, qreal minFPS, if (videoConnection.supportsVideoMinFrameDuration) videoConnection.videoMinFrameDuration = minDuration; -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_5_0) -#if QT_OSX_DEPLOYMENT_TARGET_BELOW(__MAC_10_9) - if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_9) { - if (minFPS > 0.) + CMTime maxDuration = kCMTimeInvalid; + if (minFPS > 0.) { + if (!videoConnection.supportsVideoMaxFrameDuration) qDebugCamera() << Q_FUNC_INFO << "minimum framerate is not supported"; - } else -#endif - { - CMTime maxDuration = kCMTimeInvalid; - if (minFPS > 0.) { - if (!videoConnection.supportsVideoMaxFrameDuration) - qDebugCamera() << Q_FUNC_INFO << "minimum framerate is not supported"; - else - maxDuration = CMTimeMake(1, minFPS); - } - if (videoConnection.supportsVideoMaxFrameDuration) - videoConnection.videoMaxFrameDuration = maxDuration; + else + maxDuration = CMTimeMake(1, minFPS); } -#else - if (minFPS > 0.) - qDebugCamera() << Q_FUNC_INFO << "minimum framerate is not supported"; -#endif + if (videoConnection.supportsVideoMaxFrameDuration) + videoConnection.videoMaxFrameDuration = maxDuration; } -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) - CMTime qt_adjusted_frame_duration(AVFrameRateRange *range, qreal fps) { Q_ASSERT(range); @@ -549,7 +524,7 @@ void qt_set_framerate_limits(AVCaptureDevice *captureDevice, qreal minFPS, qreal #ifdef Q_OS_IOS [captureDevice setActiveVideoMinFrameDuration:minFrameDuration]; [captureDevice setActiveVideoMaxFrameDuration:maxFrameDuration]; -#else // Q_OS_OSX +#elif defined(Q_OS_MACOS) if (CMTimeCompare(minFrameDuration, kCMTimeInvalid) == 0 && CMTimeCompare(maxFrameDuration, kCMTimeInvalid) == 0) { AVFrameRateRange *range = captureDevice.activeFormat.videoSupportedFrameRateRanges.firstObject; @@ -560,32 +535,16 @@ void qt_set_framerate_limits(AVCaptureDevice *captureDevice, qreal minFPS, qreal if (CMTimeCompare(minFrameDuration, kCMTimeInvalid)) [captureDevice setActiveVideoMinFrameDuration:minFrameDuration]; -#if QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9) -#if QT_OSX_DEPLOYMENT_TARGET_BELOW(__MAC_10_9) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_9) -#endif - { - if (CMTimeCompare(maxFrameDuration, kCMTimeInvalid)) - [captureDevice setActiveVideoMaxFrameDuration:maxFrameDuration]; - } -#endif // QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9) -#endif // Q_OS_OSX + if (CMTimeCompare(maxFrameDuration, kCMTimeInvalid)) + [captureDevice setActiveVideoMaxFrameDuration:maxFrameDuration]; +#endif // Q_OS_MACOS } -#endif // Platform SDK >= 10.9, >= 7.0. - void qt_set_framerate_limits(AVCaptureDevice *captureDevice, AVCaptureConnection *videoConnection, qreal minFPS, qreal maxFPS) { Q_ASSERT(captureDevice); -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) - if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_9, QSysInfo::MV_IOS_7_0)) - qt_set_framerate_limits(captureDevice, minFPS, maxFPS); - else -#endif - if (videoConnection) - qt_set_framerate_limits(videoConnection, minFPS, maxFPS); - + qt_set_framerate_limits(captureDevice, minFPS, maxFPS); } AVFPSRange qt_current_framerates(AVCaptureDevice *captureDevice, AVCaptureConnection *videoConnection) @@ -593,33 +552,16 @@ AVFPSRange qt_current_framerates(AVCaptureDevice *captureDevice, AVCaptureConnec Q_ASSERT(captureDevice); AVFPSRange fps; -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) - if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_7, QSysInfo::MV_IOS_7_0)) { - const CMTime minDuration = captureDevice.activeVideoMinFrameDuration; - if (CMTimeCompare(minDuration, kCMTimeInvalid)) { - if (const Float64 minSeconds = CMTimeGetSeconds(minDuration)) - fps.second = 1. / minSeconds; // Max FPS = 1 / MinDuration. - } - -#if QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9) -#if QT_OSX_DEPLOYMENT_TARGET_BELOW(__MAC_10_9) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_9) -#endif - { - const CMTime maxDuration = captureDevice.activeVideoMaxFrameDuration; - if (CMTimeCompare(maxDuration, kCMTimeInvalid)) { - if (const Float64 maxSeconds = CMTimeGetSeconds(maxDuration)) - fps.first = 1. / maxSeconds; // Min FPS = 1 / MaxDuration. - } - } -#endif // QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9) + const CMTime minDuration = captureDevice.activeVideoMinFrameDuration; + if (CMTimeCompare(minDuration, kCMTimeInvalid)) { + if (const Float64 minSeconds = CMTimeGetSeconds(minDuration)) + fps.second = 1. / minSeconds; // Max FPS = 1 / MinDuration. + } - } else { -#else // OSX < 10.7 or iOS < 7.0 - { -#endif // QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) - if (videoConnection) - fps = qt_connection_framerates(videoConnection); + const CMTime maxDuration = captureDevice.activeVideoMaxFrameDuration; + if (CMTimeCompare(maxDuration, kCMTimeInvalid)) { + if (const Float64 maxSeconds = CMTimeGetSeconds(maxDuration)) + fps.first = 1. / maxSeconds; // Min FPS = 1 / MaxDuration. } return fps; diff --git a/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm b/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm index 23dd2a4aa..0054a8d01 100644 --- a/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm +++ b/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm @@ -47,7 +47,6 @@ #include <QtMultimedia/qabstractvideosurface.h> #include <QtCore/qvariant.h> -#include <QtCore/qsysinfo.h> #include <QtCore/qvector.h> #include <QtCore/qdebug.h> #include <QtCore/qlist.h> @@ -97,57 +96,36 @@ QList<QCameraViewfinderSettings> AVFCameraViewfinderSettingsControl2::supportedV if (!pixelFormats.size()) pixelFormats << QVideoFrame::Format_Invalid; // The default value. -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) - if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_7, QSysInfo::MV_IOS_7_0)) { - if (!captureDevice.formats || !captureDevice.formats.count) { - qDebugCamera() << Q_FUNC_INFO << "no capture device formats found"; - return supportedSettings; - } + if (!captureDevice.formats || !captureDevice.formats.count) { + qDebugCamera() << Q_FUNC_INFO << "no capture device formats found"; + return supportedSettings; + } - const QVector<AVCaptureDeviceFormat *> formats(qt_unique_device_formats(captureDevice, - m_service->session()->defaultCodec())); - for (int i = 0; i < formats.size(); ++i) { - AVCaptureDeviceFormat *format = formats[i]; - - const QSize res(qt_device_format_resolution(format)); - if (res.isNull() || !res.isValid()) - continue; - const QSize par(qt_device_format_pixel_aspect_ratio(format)); - if (par.isNull() || !par.isValid()) - continue; - - framerates = qt_device_format_framerates(format); - if (!framerates.size()) - framerates << AVFPSRange(); // The default value. - - for (int i = 0; i < pixelFormats.size(); ++i) { - for (int j = 0; j < framerates.size(); ++j) { - QCameraViewfinderSettings newSet; - newSet.setResolution(res); - newSet.setPixelAspectRatio(par); - newSet.setPixelFormat(pixelFormats[i]); - newSet.setMinimumFrameRate(framerates[j].first); - newSet.setMaximumFrameRate(framerates[j].second); - supportedSettings << newSet; - } - } - } - } else { -#else - { -#endif - AVCaptureConnection *connection = videoConnection(); - if (connection) { - // TODO: resolution and PAR. - framerates << qt_connection_framerates(connection); - for (int i = 0; i < pixelFormats.size(); ++i) { - for (int j = 0; j < framerates.size(); ++j) { - QCameraViewfinderSettings newSet; - newSet.setPixelFormat(pixelFormats[i]); - newSet.setMinimumFrameRate(framerates[j].first); - newSet.setMaximumFrameRate(framerates[j].second); - supportedSettings << newSet; - } + const QVector<AVCaptureDeviceFormat *> formats(qt_unique_device_formats(captureDevice, + m_service->session()->defaultCodec())); + for (int i = 0; i < formats.size(); ++i) { + AVCaptureDeviceFormat *format = formats[i]; + + const QSize res(qt_device_format_resolution(format)); + if (res.isNull() || !res.isValid()) + continue; + const QSize par(qt_device_format_pixel_aspect_ratio(format)); + if (par.isNull() || !par.isValid()) + continue; + + framerates = qt_device_format_framerates(format); + if (!framerates.size()) + framerates << AVFPSRange(); // The default value. + + for (int i = 0; i < pixelFormats.size(); ++i) { + for (int j = 0; j < framerates.size(); ++j) { + QCameraViewfinderSettings newSet; + newSet.setResolution(res); + newSet.setPixelAspectRatio(par); + newSet.setPixelFormat(pixelFormats[i]); + newSet.setMinimumFrameRate(framerates[j].first); + newSet.setMaximumFrameRate(framerates[j].second); + supportedSettings << newSet; } } } @@ -170,25 +148,21 @@ QCameraViewfinderSettings AVFCameraViewfinderSettingsControl2::viewfinderSetting return settings; } -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) - if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_7, QSysInfo::MV_IOS_7_0)) { - if (!captureDevice.activeFormat) { - qDebugCamera() << Q_FUNC_INFO << "no active capture device format"; - return settings; - } - - const QSize res(qt_device_format_resolution(captureDevice.activeFormat)); - const QSize par(qt_device_format_pixel_aspect_ratio(captureDevice.activeFormat)); - if (res.isNull() || !res.isValid() || par.isNull() || !par.isValid()) { - qDebugCamera() << Q_FUNC_INFO << "failed to obtain resolution/pixel aspect ratio"; - return settings; - } + if (!captureDevice.activeFormat) { + qDebugCamera() << Q_FUNC_INFO << "no active capture device format"; + return settings; + } - settings.setResolution(res); - settings.setPixelAspectRatio(par); + const QSize res(qt_device_format_resolution(captureDevice.activeFormat)); + const QSize par(qt_device_format_pixel_aspect_ratio(captureDevice.activeFormat)); + if (res.isNull() || !res.isValid() || par.isNull() || !par.isValid()) { + qDebugCamera() << Q_FUNC_INFO << "failed to obtain resolution/pixel aspect ratio"; + return settings; } -#endif - // TODO: resolution and PAR before 7.0. + + settings.setResolution(res); + settings.setPixelAspectRatio(par); + const AVFPSRange fps = qt_current_framerates(captureDevice, videoConnection()); settings.setMinimumFrameRate(fps.first); settings.setMaximumFrameRate(fps.second); @@ -285,35 +259,30 @@ AVCaptureDeviceFormat *AVFCameraViewfinderSettingsControl2::findBestFormatMatch( if (!captureDevice || settings.isNull()) return nil; -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) - if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_7, QSysInfo::MV_IOS_7_0)) { - - const QSize &resolution = settings.resolution(); - if (!resolution.isNull() && resolution.isValid()) { - // Either the exact match (including high resolution for images on iOS) - // or a format with a resolution close to the requested one. - return qt_find_best_resolution_match(captureDevice, resolution, - m_service->session()->defaultCodec()); - } - - // No resolution requested, what about framerates? - if (!qt_framerates_sane(settings)) { - qDebugCamera() << Q_FUNC_INFO << "invalid framerate requested (min/max):" - << settings.minimumFrameRate() << settings.maximumFrameRate(); - return nil; - } + const QSize &resolution = settings.resolution(); + if (!resolution.isNull() && resolution.isValid()) { + // Either the exact match (including high resolution for images on iOS) + // or a format with a resolution close to the requested one. + return qt_find_best_resolution_match(captureDevice, resolution, + m_service->session()->defaultCodec()); + } - const qreal minFPS(settings.minimumFrameRate()); - const qreal maxFPS(settings.maximumFrameRate()); - if (minFPS || maxFPS) - return qt_find_best_framerate_match(captureDevice, - m_service->session()->defaultCodec(), - maxFPS ? maxFPS : minFPS); - // Ignore PAR for the moment (PAR without resolution can - // pick a format with really bad resolution). - // No need to test pixel format, just return settings. + // No resolution requested, what about framerates? + if (!qt_framerates_sane(settings)) { + qDebugCamera() << Q_FUNC_INFO << "invalid framerate requested (min/max):" + << settings.minimumFrameRate() << settings.maximumFrameRate(); + return nil; } -#endif + + const qreal minFPS(settings.minimumFrameRate()); + const qreal maxFPS(settings.maximumFrameRate()); + if (minFPS || maxFPS) + return qt_find_best_framerate_match(captureDevice, + m_service->session()->defaultCodec(), + maxFPS ? maxFPS : minFPS); + // Ignore PAR for the moment (PAR without resolution can + // pick a format with really bad resolution). + // No need to test pixel format, just return settings. return nil; } @@ -395,7 +364,6 @@ bool AVFCameraViewfinderSettingsControl2::applySettings(const QCameraViewfinderS bool activeFormatChanged = false; -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) AVCaptureDeviceFormat *match = findBestFormatMatch(settings); if (match) { activeFormatChanged = qt_set_active_format(captureDevice, match, false); @@ -403,7 +371,6 @@ bool AVFCameraViewfinderSettingsControl2::applySettings(const QCameraViewfinderS qDebugCamera() << Q_FUNC_INFO << "matching device format not found"; // We still can update the pixel format at least. } -#endif AVCaptureVideoDataOutput *videoOutput = m_service->videoOutput() ? m_service->videoOutput()->videoDataOutput() : 0; if (videoOutput) { diff --git a/src/plugins/avfoundation/camera/avfcamerazoomcontrol.mm b/src/plugins/avfoundation/camera/avfcamerazoomcontrol.mm index 2662793f8..47dc736a1 100644 --- a/src/plugins/avfoundation/camera/avfcamerazoomcontrol.mm +++ b/src/plugins/avfoundation/camera/avfcamerazoomcontrol.mm @@ -44,7 +44,6 @@ #include "avfcameracontrol.h" #include "avfcameradebug.h" -#include <QtCore/qsysinfo.h> #include <QtCore/qglobal.h> #include <QtCore/qdebug.h> @@ -98,9 +97,6 @@ void AVFCameraZoomControl::zoomTo(qreal optical, qreal digital) { Q_UNUSED(optical) Q_UNUSED(digital) -#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_7_0) - if (QSysInfo::MacintoshVersion < QSysInfo::MV_IOS_7_0) - return; if (qFuzzyCompare(CGFloat(digital), m_requestedZoomFactor)) return; @@ -109,15 +105,10 @@ void AVFCameraZoomControl::zoomTo(qreal optical, qreal digital) Q_EMIT requestedDigitalZoomChanged(digital); zoomToRequestedDigital(); -#endif } void AVFCameraZoomControl::cameraStateChanged() { -#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_7_0) - if (QSysInfo::MacintoshVersion < QSysInfo::MV_IOS_7_0) - return; - const QCamera::State state = m_session->state(); if (state != QCamera::ActiveState) { if (state == QCamera::UnloadedState && m_maxZoomFactor > 1.) { @@ -146,15 +137,10 @@ void AVFCameraZoomControl::cameraStateChanged() } zoomToRequestedDigital(); -#endif } void AVFCameraZoomControl::zoomToRequestedDigital() { -#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_7_0) - if (QSysInfo::MacintoshVersion < QSysInfo::MV_IOS_7_0) - return; - AVCaptureDevice *captureDevice = m_session->videoCaptureDevice(); if (!captureDevice || !captureDevice.activeFormat) return; @@ -186,7 +172,6 @@ void AVFCameraZoomControl::zoomToRequestedDigital() m_zoomFactor = clampedZoom; Q_EMIT currentDigitalZoomChanged(clampedZoom); } -#endif } QT_END_NAMESPACE diff --git a/src/plugins/avfoundation/camera/avfimageencodercontrol.mm b/src/plugins/avfoundation/camera/avfimageencodercontrol.mm index e5aa8a4c2..8384ce6ae 100644 --- a/src/plugins/avfoundation/camera/avfimageencodercontrol.mm +++ b/src/plugins/avfoundation/camera/avfimageencodercontrol.mm @@ -48,7 +48,7 @@ #include <QtMultimedia/qmediaencodersettings.h> -#include <QtCore/qsysinfo.h> +#include <QtCore/qoperatingsystemversion.h> #include <QtCore/qdebug.h> #include <AVFoundation/AVFoundation.h> @@ -84,36 +84,28 @@ QList<QSize> AVFImageEncoderControl::supportedResolutions(const QImageEncoderSet if (!videoCaptureDeviceIsValid()) return resolutions; -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) - if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_7, QSysInfo::MV_IOS_7_0)) { - AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice(); - const QVector<AVCaptureDeviceFormat *> formats(qt_unique_device_formats(captureDevice, - m_service->session()->defaultCodec())); + AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice(); + const QVector<AVCaptureDeviceFormat *> formats(qt_unique_device_formats(captureDevice, + m_service->session()->defaultCodec())); - for (int i = 0; i < formats.size(); ++i) { - AVCaptureDeviceFormat *format = formats[i]; + for (int i = 0; i < formats.size(); ++i) { + AVCaptureDeviceFormat *format = formats[i]; - const QSize res(qt_device_format_resolution(format)); - if (!res.isNull() && res.isValid()) - resolutions << res; + const QSize res(qt_device_format_resolution(format)); + if (!res.isNull() && res.isValid()) + resolutions << res; #if defined(Q_OS_IOS) && QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_8_0) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_8_0) { - // From Apple's docs (iOS): - // By default, AVCaptureStillImageOutput emits images with the same dimensions as - // its source AVCaptureDevice instance’s activeFormat.formatDescription. However, - // if you set this property to YES, the receiver emits still images at the capture - // device’s highResolutionStillImageDimensions value. - const QSize hrRes(qt_device_format_high_resolution(format)); - if (!hrRes.isNull() && hrRes.isValid()) - resolutions << res; - } -#endif + if (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::IOS, 8)) { + // From Apple's docs (iOS): + // By default, AVCaptureStillImageOutput emits images with the same dimensions as + // its source AVCaptureDevice instance’s activeFormat.formatDescription. However, + // if you set this property to YES, the receiver emits still images at the capture + // device’s highResolutionStillImageDimensions value. + const QSize hrRes(qt_device_format_high_resolution(format)); + if (!hrRes.isNull() && hrRes.isValid()) + resolutions << res; } - } else { -#else - { #endif - // TODO: resolutions without AVCaptureDeviceFormat ... } if (continuous) @@ -134,40 +126,32 @@ QImageEncoderSettings AVFImageEncoderControl::imageSettings() const if (!videoCaptureDeviceIsValid()) return settings; -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) - if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_7, QSysInfo::MV_IOS_7_0)) { - AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice(); - if (!captureDevice.activeFormat) { - qDebugCamera() << Q_FUNC_INFO << "no active format"; - return settings; - } + AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice(); + if (!captureDevice.activeFormat) { + qDebugCamera() << Q_FUNC_INFO << "no active format"; + return settings; + } - QSize res(qt_device_format_resolution(captureDevice.activeFormat)); + QSize res(qt_device_format_resolution(captureDevice.activeFormat)); #if defined(Q_OS_IOS) && QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_8_0) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_8_0) { - if (!m_service->imageCaptureControl() || !m_service->imageCaptureControl()->stillImageOutput()) { - qDebugCamera() << Q_FUNC_INFO << "no still image output"; - return settings; - } - - AVCaptureStillImageOutput *stillImageOutput = m_service->imageCaptureControl()->stillImageOutput(); - if (stillImageOutput.highResolutionStillImageOutputEnabled) - res = qt_device_format_high_resolution(captureDevice.activeFormat); - } -#endif - if (res.isNull() || !res.isValid()) { - qDebugCamera() << Q_FUNC_INFO << "failed to exctract the image resolution"; + if (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::IOS, 8)) { + if (!m_service->imageCaptureControl() || !m_service->imageCaptureControl()->stillImageOutput()) { + qDebugCamera() << Q_FUNC_INFO << "no still image output"; return settings; } - settings.setResolution(res); - } else { -#else - { + AVCaptureStillImageOutput *stillImageOutput = m_service->imageCaptureControl()->stillImageOutput(); + if (stillImageOutput.highResolutionStillImageOutputEnabled) + res = qt_device_format_high_resolution(captureDevice.activeFormat); + } #endif - // TODO: resolution without AVCaptureDeviceFormat. + if (res.isNull() || !res.isValid()) { + qDebugCamera() << Q_FUNC_INFO << "failed to exctract the image resolution"; + return settings; } + settings.setResolution(res); + settings.setCodec(QLatin1String("jpeg")); return settings; @@ -222,34 +206,26 @@ bool AVFImageEncoderControl::applySettings() bool activeFormatChanged = false; -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) - if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_7, QSysInfo::MV_IOS_7_0)) { - AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice(); - AVCaptureDeviceFormat *match = qt_find_best_resolution_match(captureDevice, res, - m_service->session()->defaultCodec()); + AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice(); + AVCaptureDeviceFormat *match = qt_find_best_resolution_match(captureDevice, res, + m_service->session()->defaultCodec()); - if (!match) { - qDebugCamera() << Q_FUNC_INFO << "unsupported resolution:" << res; - return false; - } + if (!match) { + qDebugCamera() << Q_FUNC_INFO << "unsupported resolution:" << res; + return false; + } - activeFormatChanged = qt_set_active_format(captureDevice, match, true); + activeFormatChanged = qt_set_active_format(captureDevice, match, true); #if defined(Q_OS_IOS) && QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_8_0) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_8_0) { - AVCaptureStillImageOutput *imageOutput = m_service->imageCaptureControl()->stillImageOutput(); - if (res == qt_device_format_high_resolution(captureDevice.activeFormat)) - imageOutput.highResolutionStillImageOutputEnabled = YES; - else - imageOutput.highResolutionStillImageOutputEnabled = NO; - } -#endif - } else { -#else - { -#endif - // TODO: resolution without capture device format ... + if (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::IOS, 8)) { + AVCaptureStillImageOutput *imageOutput = m_service->imageCaptureControl()->stillImageOutput(); + if (res == qt_device_format_high_resolution(captureDevice.activeFormat)) + imageOutput.highResolutionStillImageOutputEnabled = YES; + else + imageOutput.highResolutionStillImageOutputEnabled = NO; } +#endif return activeFormatChanged; } diff --git a/src/plugins/avfoundation/camera/avfmediaassetwriter.mm b/src/plugins/avfoundation/camera/avfmediaassetwriter.mm index 28735bc6a..5a1257f6c 100644 --- a/src/plugins/avfoundation/camera/avfmediaassetwriter.mm +++ b/src/plugins/avfoundation/camera/avfmediaassetwriter.mm @@ -47,7 +47,6 @@ #include "avfmediacontainercontrol.h" #include <QtCore/qmetaobject.h> -#include <QtCore/qsysinfo.h> QT_USE_NAMESPACE diff --git a/src/plugins/avfoundation/camera/avfvideoencodersettingscontrol.mm b/src/plugins/avfoundation/camera/avfvideoencodersettingscontrol.mm index b478ba321..bbb16e709 100644 --- a/src/plugins/avfoundation/camera/avfvideoencodersettingscontrol.mm +++ b/src/plugins/avfoundation/camera/avfvideoencodersettingscontrol.mm @@ -56,7 +56,6 @@ Q_GLOBAL_STATIC_WITH_ARGS(QStringList, supportedCodecs, (QStringList() << QLatin #endif )) -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) static bool format_supports_framerate(AVCaptureDeviceFormat *format, qreal fps) { if (format && fps > qreal(0)) { @@ -74,7 +73,6 @@ static bool format_supports_framerate(AVCaptureDeviceFormat *format, qreal fps) return false; } -#endif static bool real_list_contains(const QList<qreal> &list, qreal value) { @@ -107,24 +105,20 @@ QList<QSize> AVFVideoEncoderSettingsControl::supportedResolutions(const QVideoEn QList<QSize> resolutions; resolutions.append(QSize(32, 32)); -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) - if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_7, QSysInfo::MV_IOS_7_0)) { - AVCaptureDevice *device = m_service->session()->videoCaptureDevice(); - if (device) { - int maximumWidth = 0; - const QVector<AVCaptureDeviceFormat *> formats(qt_unique_device_formats(device, - m_service->session()->defaultCodec())); - for (int i = 0; i < formats.size(); ++i) { - const QSize res(qt_device_format_resolution(formats[i])); - if (res.width() > maximumWidth) - maximumWidth = res.width(); - } - - if (maximumWidth > 0) - resolutions.append(QSize(maximumWidth, maximumWidth)); + AVCaptureDevice *device = m_service->session()->videoCaptureDevice(); + if (device) { + int maximumWidth = 0; + const QVector<AVCaptureDeviceFormat *> formats(qt_unique_device_formats(device, + m_service->session()->defaultCodec())); + for (int i = 0; i < formats.size(); ++i) { + const QSize res(qt_device_format_resolution(formats[i])); + if (res.width() > maximumWidth) + maximumWidth = res.width(); } + + if (maximumWidth > 0) + resolutions.append(QSize(maximumWidth, maximumWidth)); } -#endif if (resolutions.count() == 1) resolutions.append(QSize(3840, 3840)); @@ -135,45 +129,39 @@ QList<QSize> AVFVideoEncoderSettingsControl::supportedResolutions(const QVideoEn QList<qreal> AVFVideoEncoderSettingsControl::supportedFrameRates(const QVideoEncoderSettings &settings, bool *continuous) const { -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) QList<qreal> uniqueFrameRates; - if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_7, QSysInfo::MV_IOS_7_0)) { - AVCaptureDevice *device = m_service->session()->videoCaptureDevice(); - if (!device) - return uniqueFrameRates; + AVCaptureDevice *device = m_service->session()->videoCaptureDevice(); + if (!device) + return uniqueFrameRates; - if (continuous) - *continuous = false; + if (continuous) + *continuous = false; - QVector<AVFPSRange> allRates; + QVector<AVFPSRange> allRates; - if (!settings.resolution().isValid()) { - const QVector<AVCaptureDeviceFormat *> formats(qt_unique_device_formats(device, 0)); - for (int i = 0; i < formats.size(); ++i) { - AVCaptureDeviceFormat *format = formats.at(i); - allRates += qt_device_format_framerates(format); - } - } else { - AVCaptureDeviceFormat *format = qt_find_best_resolution_match(device, - settings.resolution(), - m_service->session()->defaultCodec()); - if (format) - allRates = qt_device_format_framerates(format); + if (!settings.resolution().isValid()) { + const QVector<AVCaptureDeviceFormat *> formats(qt_unique_device_formats(device, 0)); + for (int i = 0; i < formats.size(); ++i) { + AVCaptureDeviceFormat *format = formats.at(i); + allRates += qt_device_format_framerates(format); } + } else { + AVCaptureDeviceFormat *format = qt_find_best_resolution_match(device, + settings.resolution(), + m_service->session()->defaultCodec()); + if (format) + allRates = qt_device_format_framerates(format); + } - for (int j = 0; j < allRates.size(); ++j) { - if (!real_list_contains(uniqueFrameRates, allRates[j].first)) - uniqueFrameRates.append(allRates[j].first); - if (!real_list_contains(uniqueFrameRates, allRates[j].second)) - uniqueFrameRates.append(allRates[j].second); - } + for (int j = 0; j < allRates.size(); ++j) { + if (!real_list_contains(uniqueFrameRates, allRates[j].first)) + uniqueFrameRates.append(allRates[j].first); + if (!real_list_contains(uniqueFrameRates, allRates[j].second)) + uniqueFrameRates.append(allRates[j].second); } return uniqueFrameRates; -#else - return QList<qreal>(); -#endif } QStringList AVFVideoEncoderSettingsControl::supportedVideoCodecs() const @@ -243,7 +231,6 @@ NSDictionary *AVFVideoEncoderSettingsControl::applySettings(AVCaptureConnection int w = m_requestedSettings.resolution().width(); int h = m_requestedSettings.resolution().height(); -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) if (AVCaptureDeviceFormat *currentFormat = device.activeFormat) { CMFormatDescriptionRef formatDesc = currentFormat.formatDescription; CMVideoDimensions dim = CMVideoFormatDescriptionGetDimensions(formatDesc); @@ -300,7 +287,6 @@ NSDictionary *AVFVideoEncoderSettingsControl::applySettings(AVCaptureConnection h = qMin(h, dim.height); } } -#endif if (w > 0 && h > 0) { // Width and height must be divisible by 2 @@ -382,13 +368,11 @@ void AVFVideoEncoderSettingsControl::unapplySettings(AVCaptureConnection *connec const bool needFpsChanged = m_restoreFps.first || m_restoreFps.second; -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0) if (m_restoreFormat) { qt_set_active_format(device, m_restoreFormat, !needFpsChanged); [m_restoreFormat release]; m_restoreFormat = nil; } -#endif if (needFpsChanged) { qt_set_framerate_limits(device, connection, m_restoreFps.first, m_restoreFps.second); diff --git a/src/plugins/avfoundation/camera/camera.pro b/src/plugins/avfoundation/camera/camera.pro index ab70c25c3..bd7b1fc97 100644 --- a/src/plugins/avfoundation/camera/camera.pro +++ b/src/plugins/avfoundation/camera/camera.pro @@ -5,13 +5,16 @@ CONFIG += no_keywords QT += multimedia-private network -LIBS += -framework AudioToolbox \ +LIBS += -framework CoreFoundation \ + -framework Foundation \ + -framework AudioToolbox \ -framework CoreAudio \ -framework QuartzCore \ -framework CoreMedia osx:LIBS += -framework AppKit \ -framework AudioUnit -ios:LIBS += -framework CoreVideo +ios:LIBS += -framework CoreGraphics \ + -framework CoreVideo QMAKE_USE += avfoundation diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.h b/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.h index b18862b55..4460a4867 100644 --- a/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.h +++ b/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.h @@ -63,7 +63,6 @@ private: AVFMediaPlayerControl *m_control; QMediaControl *m_videoOutput; AVFMediaPlayerMetaDataControl *m_playerMetaDataControl; - bool m_enableRenderControl; }; QT_END_NAMESPACE diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.mm b/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.mm index 526c36cc6..6218401b3 100644 --- a/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.mm +++ b/src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.mm @@ -48,32 +48,19 @@ #endif #include "avfvideowindowcontrol.h" -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_8, __IPHONE_6_0) #import <AVFoundation/AVFoundation.h> -#endif QT_USE_NAMESPACE AVFMediaPlayerService::AVFMediaPlayerService(QObject *parent) : QMediaService(parent) , m_videoOutput(0) - , m_enableRenderControl(true) { m_session = new AVFMediaPlayerSession(this); m_control = new AVFMediaPlayerControl(this); m_control->setSession(m_session); m_playerMetaDataControl = new AVFMediaPlayerMetaDataControl(m_session, this); -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_8, __IPHONE_6_0) - // AVPlayerItemVideoOutput is available in SDK - #if QT_MAC_DEPLOYMENT_TARGET_BELOW(__MAC_10_8, __IPHONE_6_0) - // might not be available at runtime - #if defined(Q_OS_IOS) || defined(Q_OS_TVOS) - m_enableRenderControl = [AVPlayerItemVideoOutput class] != 0; - #endif - #endif -#endif - connect(m_control, SIGNAL(mediaChanged(QMediaContent)), m_playerMetaDataControl, SLOT(updateTags())); } @@ -98,7 +85,7 @@ QMediaControl *AVFMediaPlayerService::requestControl(const char *name) return m_playerMetaDataControl; - if (m_enableRenderControl && (qstrcmp(name, QVideoRendererControl_iid) == 0)) { + if (qstrcmp(name, QVideoRendererControl_iid) == 0) { if (!m_videoOutput) m_videoOutput = new AVFVideoRendererControl(this); diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.h b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.h index f0cb46aaa..5696faf15 100644 --- a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.h +++ b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.h @@ -86,8 +86,6 @@ public: qreal playbackRate() const; - inline bool isVolumeSupported() const { return m_volumeSupported; } - public Q_SLOTS: void setPlaybackRate(qreal rate); @@ -169,7 +167,6 @@ private: QMediaContent m_resources; ResourceHandler m_resourceHandler; - const bool m_volumeSupported; bool m_muted; bool m_tryingAsync; int m_volume; diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm index 473a18884..e15c2e44a 100644 --- a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm +++ b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm @@ -233,7 +233,7 @@ static void *AVFMediaPlayerSessionObserverCurrentItemObservationContext = &AVFMe [m_player retain]; //Set the initial volume on new player object - if (self.session && self.session->isVolumeSupported()) { + if (self.session) { [m_player setVolume:m_session->volume() / 100.0f]; [m_player setMuted:m_session->isMuted()]; } @@ -380,11 +380,6 @@ AVFMediaPlayerSession::AVFMediaPlayerSession(AVFMediaPlayerService *service, QOb , m_state(QMediaPlayer::StoppedState) , m_mediaStatus(QMediaPlayer::NoMedia) , m_mediaStream(0) -#ifdef Q_OS_IOS - , m_volumeSupported(QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_7_0) -#else - , m_volumeSupported(true) -#endif , m_muted(false) , m_tryingAsync(false) , m_volume(100) @@ -749,11 +744,6 @@ void AVFMediaPlayerSession::setVolume(int volume) qDebug() << Q_FUNC_INFO << volume; #endif - if (!m_volumeSupported) { - qWarning("%s not implemented, requires iOS 7 or later", Q_FUNC_INFO); - return; - } - if (m_volume == volume) return; @@ -772,11 +762,6 @@ void AVFMediaPlayerSession::setMuted(bool muted) qDebug() << Q_FUNC_INFO << muted; #endif - if (!m_volumeSupported) { - qWarning("%s not implemented, requires iOS 7 or later", Q_FUNC_INFO); - return; - } - if (m_muted == muted) return; diff --git a/src/plugins/coreaudio/coreaudiosessionmanager.mm b/src/plugins/coreaudio/coreaudiosessionmanager.mm index d381b82c0..923a1942f 100644 --- a/src/plugins/coreaudio/coreaudiosessionmanager.mm +++ b/src/plugins/coreaudio/coreaudiosessionmanager.mm @@ -42,10 +42,6 @@ #import <AVFoundation/AVAudioSession.h> #import <Foundation/Foundation.h> -#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0) -#include <AudioToolbox/AudioToolbox.h> -#endif - QT_BEGIN_NAMESPACE @interface CoreAudioSessionObserver : NSObject @@ -81,24 +77,19 @@ QT_BEGIN_NAMESPACE self->m_sessionManager = sessionManager; self->m_audioSession = [AVAudioSession sharedInstance]; -#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_6_0) -#endif - { - //Set up observers - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(audioSessionInterruption:) - name:AVAudioSessionInterruptionNotification - object:self->m_audioSession]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(audioSessionMediaServicesWereReset:) - name:AVAudioSessionMediaServicesWereResetNotification - object:self->m_audioSession]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(audioSessionRouteChange:) - name:AVAudioSessionRouteChangeNotification - object:self->m_audioSession]; - } + //Set up observers + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(audioSessionInterruption:) + name:AVAudioSessionInterruptionNotification + object:self->m_audioSession]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(audioSessionMediaServicesWereReset:) + name:AVAudioSessionMediaServicesWereResetNotification + object:self->m_audioSession]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(audioSessionRouteChange:) + name:AVAudioSessionRouteChangeNotification + object:self->m_audioSession]; return self; } @@ -109,20 +100,15 @@ QT_BEGIN_NAMESPACE qDebug() << Q_FUNC_INFO; #endif -#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_6_0) -#endif - { - [[NSNotificationCenter defaultCenter] removeObserver:self - name:AVAudioSessionInterruptionNotification - object:self->m_audioSession]; - [[NSNotificationCenter defaultCenter] removeObserver:self - name:AVAudioSessionMediaServicesWereResetNotification - object:self->m_audioSession]; - [[NSNotificationCenter defaultCenter] removeObserver:self - name:AVAudioSessionRouteChangeNotification - object:self->m_audioSession]; - } + [[NSNotificationCenter defaultCenter] removeObserver:self + name:AVAudioSessionInterruptionNotification + object:self->m_audioSession]; + [[NSNotificationCenter defaultCenter] removeObserver:self + name:AVAudioSessionMediaServicesWereResetNotification + object:self->m_audioSession]; + [[NSNotificationCenter defaultCenter] removeObserver:self + name:AVAudioSessionRouteChangeNotification + object:self->m_audioSession]; [super dealloc]; } @@ -285,9 +271,6 @@ bool CoreAudioSessionManager::setCategory(CoreAudioSessionManager::AudioSessionC #endif break; case CoreAudioSessionManager::MultiRoute: -#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_6_0) -#endif targetCategory = AVAudioSessionCategoryMultiRoute; break; } @@ -295,16 +278,9 @@ bool CoreAudioSessionManager::setCategory(CoreAudioSessionManager::AudioSessionC if (targetCategory == nil) return false; -#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0) - if (QSysInfo::MacintoshVersion < QSysInfo::MV_IOS_6_0) { - return [[m_sessionObserver audioSession] setCategory:targetCategory error:nil]; - } else -#endif - { - return [[m_sessionObserver audioSession] setCategory:targetCategory - withOptions:(AVAudioSessionCategoryOptions)options - error:nil]; - } + return [[m_sessionObserver audioSession] setCategory:targetCategory + withOptions:(AVAudioSessionCategoryOptions)options + error:nil]; } bool CoreAudioSessionManager::setMode(CoreAudioSessionManager::AudioSessionModes mode) @@ -327,9 +303,6 @@ bool CoreAudioSessionManager::setMode(CoreAudioSessionManager::AudioSessionModes targetMode = AVAudioSessionModeMeasurement; break; case CoreAudioSessionManager::MoviePlayback: -#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_6_0) -#endif targetMode = AVAudioSessionModeMoviePlayback; break; } @@ -360,11 +333,7 @@ CoreAudioSessionManager::AudioSessionCategorys CoreAudioSessionManager::category } else if (category == AVAudioSessionCategoryAudioProcessing) { localCategory = AudioProcessing; #endif - } else if ( -#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0) - QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_6_0 && -#endif - category == AVAudioSessionCategoryMultiRoute) { + } else if (category == AVAudioSessionCategoryMultiRoute) { localCategory = MultiRoute; } @@ -386,11 +355,7 @@ CoreAudioSessionManager::AudioSessionModes CoreAudioSessionManager::mode() localMode = VideoRecording; } else if (mode == AVAudioSessionModeMeasurement) { localMode = Measurement; - } else if ( -#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0) - QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_6_0 && -#endif - mode == AVAudioSessionModeMoviePlayback) { + } else if (mode == AVAudioSessionModeMoviePlayback) { localMode = MoviePlayback; } @@ -419,32 +384,12 @@ QList<QByteArray> CoreAudioSessionManager::outputDevices() float CoreAudioSessionManager::currentIOBufferDuration() { -#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0) - if (QSysInfo::MacintoshVersion < QSysInfo::MV_IOS_6_0) { - Float32 duration; - UInt32 size = sizeof(duration); - AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareIOBufferDuration, &size, &duration); - return duration; - } else -#endif - { - return [[m_sessionObserver audioSession] IOBufferDuration]; - } + return [[m_sessionObserver audioSession] IOBufferDuration]; } float CoreAudioSessionManager::preferredSampleRate() { -#if QT_IOS_DEPLOYMENT_TARGET_BELOW(__IPHONE_6_0) - if (QSysInfo::MacintoshVersion < QSysInfo::MV_IOS_6_0) { - Float64 sampleRate; - UInt32 size = sizeof(sampleRate); - AudioSessionGetProperty(kAudioSessionProperty_PreferredHardwareSampleRate, &size, &sampleRate); - return sampleRate; - } else -#endif - { - return [[m_sessionObserver audioSession] preferredSampleRate]; - } + return [[m_sessionObserver audioSession] preferredSampleRate]; } #ifdef QT_DEBUG_COREAUDIO diff --git a/src/plugins/directshow/camera/dscamerasession.cpp b/src/plugins/directshow/camera/dscamerasession.cpp index 5587b479c..9955a4821 100644 --- a/src/plugins/directshow/camera/dscamerasession.cpp +++ b/src/plugins/directshow/camera/dscamerasession.cpp @@ -1078,40 +1078,10 @@ bool DSCameraSession::connectGraph() void DSCameraSession::disconnectGraph() { - IPin *pPin = 0; - HRESULT hr = getPin(m_sourceFilter, PINDIR_OUTPUT, &pPin); - if (SUCCEEDED(hr)) { - m_filterGraph->Disconnect(pPin); - pPin->Release(); - pPin = NULL; - } - - hr = getPin(m_previewFilter, PINDIR_INPUT, &pPin); - if (SUCCEEDED(hr)) { - m_filterGraph->Disconnect(pPin); - pPin->Release(); - pPin = NULL; - } - - hr = getPin(m_previewFilter, PINDIR_OUTPUT, &pPin); - if (SUCCEEDED(hr)) { - m_filterGraph->Disconnect(pPin); - pPin->Release(); - pPin = NULL; - } - - hr = getPin(m_nullRendererFilter, PINDIR_INPUT, &pPin); - if (SUCCEEDED(hr)) { - m_filterGraph->Disconnect(pPin); - pPin->Release(); - pPin = NULL; - } - // To avoid increasing the memory usage every time the graph is re-connected it's // important that all filters are released; also the ones added by the "Intelligent Connect". IEnumFilters *enumFilters = NULL; - hr = m_filterGraph->EnumFilters(&enumFilters); - if (SUCCEEDED(hr)) { + if (SUCCEEDED(m_filterGraph->EnumFilters(&enumFilters))) { IBaseFilter *filter = NULL; while (enumFilters->Next(1, &filter, NULL) == S_OK) { m_filterGraph->RemoveFilter(filter); diff --git a/src/plugins/directshow/dsserviceplugin.cpp b/src/plugins/directshow/dsserviceplugin.cpp index 6f31ce7e2..1c9d0eee1 100644 --- a/src/plugins/directshow/dsserviceplugin.cpp +++ b/src/plugins/directshow/dsserviceplugin.cpp @@ -43,6 +43,7 @@ #include <QtCore/qdebug.h> #include <QtCore/QFile> +#include "directshowglobal.h" #include "dsserviceplugin.h" #ifdef QMEDIA_DIRECTSHOW_CAMERA @@ -79,6 +80,8 @@ extern const CLSID CLSID_VideoInputDeviceCategory; QT_USE_NAMESPACE +Q_LOGGING_CATEGORY(qtDirectShowPlugin, "qt.multimedia.plugins.directshow") + static int g_refCount = 0; void addRefCount() { diff --git a/src/plugins/directshow/helpers/directshowglobal.h b/src/plugins/directshow/helpers/directshowglobal.h index f7890c52b..1447bff16 100644 --- a/src/plugins/directshow/helpers/directshowglobal.h +++ b/src/plugins/directshow/helpers/directshowglobal.h @@ -43,6 +43,13 @@ #include <dshow.h> #include <QtCore/qglobal.h> +#include <QtCore/qloggingcategory.h> + +QT_BEGIN_NAMESPACE + +Q_DECLARE_LOGGING_CATEGORY(qtDirectShowPlugin) + +QT_END_NAMESPACE template <typename T> T *com_cast(IUnknown *unknown, const IID &iid) { diff --git a/src/plugins/directshow/player/directshowplayercontrol.cpp b/src/plugins/directshow/player/directshowplayercontrol.cpp index fce488af2..2d0ee2d59 100644 --- a/src/plugins/directshow/player/directshowplayercontrol.cpp +++ b/src/plugins/directshow/player/directshowplayercontrol.cpp @@ -200,7 +200,7 @@ qreal DirectShowPlayerControl::playbackRate() const void DirectShowPlayerControl::setPlaybackRate(qreal rate) { - if (m_playbackRate != rate) { + if (!qFuzzyCompare(m_playbackRate, rate)) { m_service->setRate(rate); emit playbackRateChanged(m_playbackRate = rate); @@ -370,7 +370,7 @@ void DirectShowPlayerControl::updateMediaInfo(qint64 duration, int streamTypes, void DirectShowPlayerControl::updatePlaybackRate(qreal rate) { - if (m_playbackRate != rate) { + if (!qFuzzyCompare(m_playbackRate, rate)) { m_playbackRate = rate; scheduleUpdate(PlaybackRateProperty); diff --git a/src/plugins/directshow/player/directshowplayerservice.h b/src/plugins/directshow/player/directshowplayerservice.h index b8d30e79a..d933bd660 100644 --- a/src/plugins/directshow/player/directshowplayerservice.h +++ b/src/plugins/directshow/player/directshowplayerservice.h @@ -186,6 +186,7 @@ private: int m_pendingTasks; int m_executingTask; int m_executedTasks; + int m_streamTypes; HANDLE m_taskHandle; HANDLE m_eventHandle; GraphStatus m_graphStatus; @@ -195,20 +196,19 @@ private: IBaseFilter *m_source; IBaseFilter *m_audioOutput; IBaseFilter *m_videoOutput; - int m_streamTypes; qreal m_rate; qint64 m_position; qint64 m_seekPosition; qint64 m_duration; - bool m_buffering; - bool m_seekable; - bool m_atEnd; - bool m_dontCacheNextSeekResult; QMediaTimeRange m_playbackRange; QUrl m_url; QMediaResourceList m_resources; QString m_errorString; QMutex m_mutex; + bool m_buffering; + bool m_seekable; + bool m_atEnd; + bool m_dontCacheNextSeekResult; friend class DirectShowPlayerServiceThread; }; diff --git a/src/plugins/gstreamer/camerabin/camerabincontainer.cpp b/src/plugins/gstreamer/camerabin/camerabincontainer.cpp index e72bf0e3c..e424f92a1 100644 --- a/src/plugins/gstreamer/camerabin/camerabincontainer.cpp +++ b/src/plugins/gstreamer/camerabin/camerabincontainer.cpp @@ -39,6 +39,7 @@ #include "camerabincontainer.h" #include <QtCore/qregexp.h> +#include <private/qgstutils_p.h> #include <QtCore/qdebug.h> @@ -50,14 +51,6 @@ CameraBinContainer::CameraBinContainer(QObject *parent) , m_supportedContainers(QGstCodecsInfo::Muxer) #endif { - //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 @@ -127,9 +120,9 @@ GstEncodingContainerProfile *CameraBinContainer::createProfile() //if format is not in the list of supported gstreamer mime types, //try to find the mime type with matching extension if (!supportedFormats.contains(format)) { - QString extension = suggestedFileExtension(m_actualFormat); + QString extension = QGstUtils::fileExtensionForMimeType(m_actualFormat); for (const QString &formatCandidate : supportedFormats) { - if (suggestedFileExtension(formatCandidate) == extension) { + if (QGstUtils::fileExtensionForMimeType(formatCandidate) == extension) { format = formatCandidate; break; } @@ -152,27 +145,4 @@ GstEncodingContainerProfile *CameraBinContainer::createProfile() #endif -/*! - Suggest file extension for current container mimetype. - */ -QString CameraBinContainer::suggestedFileExtension(const QString &containerFormat) const -{ - //for container names like avi instead of video/x-msvideo, use it as extension - if (!containerFormat.contains('/')) - return containerFormat; - - QString format = containerFormat.left(containerFormat.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; -} - QT_END_NAMESPACE diff --git a/src/plugins/gstreamer/camerabin/camerabincontainer.h b/src/plugins/gstreamer/camerabin/camerabincontainer.h index 8e9f21eaf..676d2de66 100644 --- a/src/plugins/gstreamer/camerabin/camerabincontainer.h +++ b/src/plugins/gstreamer/camerabin/camerabincontainer.h @@ -72,8 +72,6 @@ public: void setActualContainerFormat(const QString &containerFormat); void resetActualContainerFormat(); - QString suggestedFileExtension(const QString &containerFormat) const; - #ifdef HAVE_GST_ENCODING_PROFILES GstEncodingContainerProfile *createProfile(); #endif @@ -84,7 +82,6 @@ Q_SIGNALS: private: QString m_format; QString m_actualFormat; - QMap<QString, QString> m_fileExtensions; #ifdef HAVE_GST_ENCODING_PROFILES QGstCodecsInfo m_supportedContainers; diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.cpp b/src/plugins/gstreamer/camerabin/camerabinsession.cpp index 64c8780d3..1e075f58d 100644 --- a/src/plugins/gstreamer/camerabin/camerabinsession.cpp +++ b/src/plugins/gstreamer/camerabin/camerabinsession.cpp @@ -1112,7 +1112,7 @@ void CameraBinSession::recordVideo() : m_sink.toString(), QMediaStorageLocation::Movies, QLatin1String("clip_"), - m_mediaContainerControl->suggestedFileExtension(format)); + QGstUtils::fileExtensionForMimeType(format)); m_recordingActive = true; m_actualSink = QUrl::fromLocalFile(actualFileName); diff --git a/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.cpp b/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.cpp index abb58c963..40294214a 100644 --- a/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.cpp +++ b/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.cpp @@ -48,52 +48,18 @@ QGstreamerAudioEncode::QGstreamerAudioEncode(QObject *parent) :QAudioEncoderSettingsControl(parent) + , m_codecs(QGstCodecsInfo::AudioEncoder) { - QList<QByteArray> codecCandidates; - - codecCandidates << "audio/mpeg" << "audio/vorbis" << "audio/speex" << "audio/GSM" - << "audio/PCM" << "audio/AMR" << "audio/AMR-WB" << "audio/FLAC"; - - m_elementNames["audio/mpeg"] = "lamemp3enc"; - m_elementNames["audio/AMR"] = "amrnbenc"; - m_elementNames["audio/AMR-WB"] = "amrwbenc"; - - 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(); - - for (const QByteArray& codecName : qAsConst(codecCandidates)) { - QByteArray elementName = m_elementNames[codecName]; - GstElementFactory *factory = gst_element_factory_find(elementName.constData()); + for (const QString& codecName : m_codecs.supportedCodecs()) { + GstElementFactory *factory = gst_element_factory_find(m_codecs.codecElement(codecName).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() @@ -102,17 +68,17 @@ QGstreamerAudioEncode::~QGstreamerAudioEncode() QStringList QGstreamerAudioEncode::supportedAudioCodecs() const { - return m_codecs; + return m_codecs.supportedCodecs(); } QString QGstreamerAudioEncode::codecDescription(const QString &codecName) const { - return m_codecDescriptions.value(codecName); + return m_codecs.codecDescription(codecName); } QStringList QGstreamerAudioEncode::supportedEncodingOptions(const QString &codec) const { - return m_codecOptions.value(codec); + return m_codecs.codecOptions(codec); } QVariant QGstreamerAudioEncode::encodingOption( @@ -148,24 +114,24 @@ void QGstreamerAudioEncode::setAudioSettings(const QAudioEncoderSettings &settin GstElement *QGstreamerAudioEncode::createEncoder() { QString codec = m_audioSettings.codec(); - GstElement *encoderElement = gst_element_factory_make(m_elementNames.value(codec).constData(), NULL); + GstElement *encoderElement = gst_element_factory_make(m_codecs.codecElement(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); + GstElement *sinkCapsFilter = gst_element_factory_make("capsfilter", NULL); + GstElement *srcCapsFilter = gst_element_factory_make("capsfilter", NULL); - gst_bin_add(encoderBin, capsFilter); - gst_bin_add(encoderBin, encoderElement); - gst_element_link(capsFilter, encoderElement); + gst_bin_add_many(encoderBin, sinkCapsFilter, encoderElement, srcCapsFilter, NULL); + gst_element_link_many(sinkCapsFilter, encoderElement, srcCapsFilter, NULL); // add ghostpads - GstPad *pad = gst_element_get_static_pad(capsFilter, "sink"); + GstPad *pad = gst_element_get_static_pad(sinkCapsFilter, "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"); + pad = gst_element_get_static_pad(srcCapsFilter, "src"); gst_element_add_pad(GST_ELEMENT(encoderBin), gst_ghost_pad_new("src", pad)); gst_object_unref(GST_OBJECT(pad)); @@ -181,18 +147,23 @@ GstElement *QGstreamerAudioEncode::createEncoder() gst_caps_append_structure(caps,structure); - //qDebug() << "set caps filter:" << gst_caps_to_string(caps); - - g_object_set(G_OBJECT(capsFilter), "caps", caps, NULL); + g_object_set(G_OBJECT(sinkCapsFilter), "caps", caps, NULL); gst_caps_unref(caps); } + // Some encoders support several codecs. Setting a caps filter downstream with the desired + // codec (which is actually a string representation of the caps) will make sure we use the + // correct codec. + GstCaps *caps = gst_caps_from_string(codec.toUtf8().constData()); + g_object_set(G_OBJECT(srcCapsFilter), "caps", caps, NULL); + gst_caps_unref(caps); + if (encoderElement) { if (m_audioSettings.encodingMode() == QMultimedia::ConstantQualityEncoding) { QMultimedia::EncodingQuality qualityValue = m_audioSettings.quality(); - if (codec == QLatin1String("audio/vorbis")) { + if (codec == QLatin1String("audio/x-vorbis")) { double qualityTable[] = { 0.1, //VeryLow 0.3, //Low @@ -211,7 +182,7 @@ GstElement *QGstreamerAudioEncode::createEncoder() 9 //VeryHigh }; g_object_set(G_OBJECT(encoderElement), "quality", quality[qualityValue], NULL); - } else if (codec == QLatin1String("audio/speex")) { + } else if (codec == QLatin1String("audio/x-speex")) { //0-10 range with default 8 double qualityTable[] = { 2, //VeryLow diff --git a/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.h b/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.h index 8474aa1a0..b4d5c4a88 100644 --- a/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.h +++ b/src/plugins/gstreamer/mediacapture/qgstreameraudioencode.h @@ -49,6 +49,7 @@ #include <gst/gst.h> #include <qaudioformat.h> +#include <private/qgstcodecsinfo_p.h> QT_BEGIN_NAMESPACE @@ -81,10 +82,7 @@ public: 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; + QGstCodecsInfo m_codecs; QMap<QString, QMap<QString, QVariant> > m_options; diff --git a/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.cpp b/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.cpp index 4e07b35bd..05f1c8af5 100644 --- a/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.cpp +++ b/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.cpp @@ -39,53 +39,19 @@ #include "qgstreamermediacontainercontrol.h" +#include <private/qgstutils_p.h> #include <QtCore/qdebug.h> QGstreamerMediaContainerControl::QGstreamerMediaContainerControl(QObject *parent) :QMediaContainerControl(parent) + , m_containers(QGstCodecsInfo::Muxer) { - 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; - for (const QByteArray& formatName : qAsConst(formatCandidates)) { - QByteArray elementName = m_elementNames[formatName]; - GstElementFactory *factory = gst_element_factory_find(elementName.constData()); + for (const QString& formatName : supportedContainers()) { + GstElementFactory *factory = gst_element_factory_find(m_containers.codecElement(formatName).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 { @@ -97,9 +63,6 @@ QGstreamerMediaContainerControl::QGstreamerMediaContainerControl(QObject *parent gst_object_unref(GST_OBJECT(factory)); } } - - //if (!m_supportedContainers.isEmpty()) - // setContainerFormat(m_supportedContainers[0]); } QSet<QString> QGstreamerMediaContainerControl::supportedStreamTypes(GstElementFactory *factory, GstPadDirection direction) @@ -129,5 +92,5 @@ QSet<QString> QGstreamerMediaContainerControl::supportedStreamTypes(const QStrin QString QGstreamerMediaContainerControl::containerExtension() const { - return m_containerExtensions.value(m_format, m_format); + return QGstUtils::fileExtensionForMimeType(m_format); } diff --git a/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.h b/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.h index b8e2cc045..0f25ad5d7 100644 --- a/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.h +++ b/src/plugins/gstreamer/mediacapture/qgstreamermediacontainercontrol.h @@ -45,6 +45,8 @@ #include <QtCore/qstringlist.h> #include <QtCore/qset.h> +#include <private/qgstcodecsinfo_p.h> + #include <gst/gst.h> QT_BEGIN_NAMESPACE @@ -56,13 +58,13 @@ public: QGstreamerMediaContainerControl(QObject *parent); virtual ~QGstreamerMediaContainerControl() {}; - virtual QStringList supportedContainers() const { return m_supportedContainers; } + virtual QStringList supportedContainers() const { return m_containers.supportedCodecs(); } virtual QString containerFormat() const { return m_format; } virtual void setContainerFormat(const QString &formatMimeType) { m_format = formatMimeType; } - virtual QString containerDescription(const QString &formatMimeType) const { return m_containerDescriptions.value(formatMimeType); } + virtual QString containerDescription(const QString &formatMimeType) const { return m_containers.codecDescription(formatMimeType); } - QByteArray formatElementName() const { return m_elementNames.value(containerFormat()); } + QByteArray formatElementName() const { return m_containers.codecElement(containerFormat()); } QSet<QString> supportedStreamTypes(const QString &container) const; @@ -72,10 +74,7 @@ public: private: QString m_format; - QStringList m_supportedContainers; - QMap<QString,QByteArray> m_elementNames; - QMap<QString, QString> m_containerDescriptions; - QMap<QString, QString> m_containerExtensions; + QGstCodecsInfo m_containers; QMap<QString, QSet<QString> > m_streamTypes; }; diff --git a/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.cpp b/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.cpp index f0781d831..6b4dbe4b7 100644 --- a/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.cpp +++ b/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.cpp @@ -47,41 +47,17 @@ QGstreamerVideoEncode::QGstreamerVideoEncode(QGstreamerCaptureSession *session) :QVideoEncoderSettingsControl(session), m_session(session) + , m_codecs(QGstCodecsInfo::VideoEncoder) { - 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(); - - for (const QByteArray& codecName : qAsConst(codecCandidates)) { - QByteArray elementName = m_elementNames[codecName]; - GstElementFactory *factory = gst_element_factory_find(elementName.constData()); + for (const QString& codecName : supportedVideoCodecs()) { + GstElementFactory *factory = gst_element_factory_find(m_codecs.codecElement(codecName).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() @@ -106,17 +82,17 @@ QList< qreal > QGstreamerVideoEncode::supportedFrameRates(const QVideoEncoderSet QStringList QGstreamerVideoEncode::supportedVideoCodecs() const { - return m_codecs; + return m_codecs.supportedCodecs(); } QString QGstreamerVideoEncode::videoCodecDescription(const QString &codecName) const { - return m_codecDescriptions.value(codecName); + return m_codecs.codecDescription(codecName); } QStringList QGstreamerVideoEncode::supportedEncodingOptions(const QString &codec) const { - return m_codecOptions.value(codec); + return m_codecs.codecOptions(codec); } QVariant QGstreamerVideoEncode::encodingOption(const QString &codec, const QString &name) const @@ -143,28 +119,28 @@ void QGstreamerVideoEncode::setVideoSettings(const QVideoEncoderSettings &settin 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"); + GstElement *encoderElement = gst_element_factory_make(m_codecs.codecElement(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 *sinkCapsFilter = gst_element_factory_make("capsfilter", "capsfilter-video"); + GstElement *srcCapsFilter = gst_element_factory_make("capsfilter", "capsfilter-video"); + gst_bin_add_many(encoderBin, sinkCapsFilter, srcCapsFilter, NULL); GstElement *colorspace = gst_element_factory_make(QT_GSTREAMER_COLORCONVERSION_ELEMENT_NAME, NULL); gst_bin_add(encoderBin, colorspace); gst_bin_add(encoderBin, encoderElement); - gst_element_link_many(capsFilter, colorspace, encoderElement, NULL); + gst_element_link_many(sinkCapsFilter, colorspace, encoderElement, srcCapsFilter, NULL); // add ghostpads - GstPad *pad = gst_element_get_static_pad(capsFilter, "sink"); + GstPad *pad = gst_element_get_static_pad(sinkCapsFilter, "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"); + pad = gst_element_get_static_pad(srcCapsFilter, "src"); gst_element_add_pad(GST_ELEMENT(encoderBin), gst_ghost_pad_new("src", pad)); gst_object_unref(GST_OBJECT(pad)); @@ -172,7 +148,7 @@ GstElement *QGstreamerVideoEncode::createEncoder() if (m_videoSettings.encodingMode() == QMultimedia::ConstantQualityEncoding) { QMultimedia::EncodingQuality qualityValue = m_videoSettings.quality(); - if (codec == QLatin1String("video/h264")) { + if (codec == QLatin1String("video/x-h264")) { //constant quantizer mode g_object_set(G_OBJECT(encoderElement), "pass", 4, NULL); int qualityTable[] = { @@ -183,7 +159,7 @@ GstElement *QGstreamerVideoEncode::createEncoder() 8 //VeryHigh }; g_object_set(G_OBJECT(encoderElement), "quantizer", qualityTable[qualityValue], NULL); - } else if (codec == QLatin1String("video/xvid")) { + } else if (codec == QLatin1String("video/x-xvid")) { //constant quantizer mode g_object_set(G_OBJECT(encoderElement), "pass", 3, NULL); int qualityTable[] = { @@ -195,9 +171,7 @@ GstElement *QGstreamerVideoEncode::createEncoder() }; 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") ) { + } else if (codec.startsWith(QLatin1String("video/mpeg"))) { //constant quantizer mode g_object_set(G_OBJECT(encoderElement), "pass", 2, NULL); //quant from 1 to 30, default ~3 @@ -210,7 +184,7 @@ GstElement *QGstreamerVideoEncode::createEncoder() }; double quant = qualityTable[qualityValue]; g_object_set(G_OBJECT(encoderElement), "quantizer", quant, NULL); - } else if (codec == QLatin1String("video/theora")) { + } else if (codec == QLatin1String("video/x-theora")) { int qualityTable[] = { 8, //VeryLow 16, //Low @@ -278,11 +252,18 @@ GstElement *QGstreamerVideoEncode::createEncoder() //qDebug() << "set video caps filter:" << gst_caps_to_string(caps); - g_object_set(G_OBJECT(capsFilter), "caps", caps, NULL); + g_object_set(G_OBJECT(sinkCapsFilter), "caps", caps, NULL); gst_caps_unref(caps); } + // Some encoders support several codecs. Setting a caps filter downstream with the desired + // codec (which is actually a string representation of the caps) will make sure we use the + // correct codec. + GstCaps *caps = gst_caps_from_string(codec.toUtf8().constData()); + g_object_set(G_OBJECT(srcCapsFilter), "caps", caps, NULL); + gst_caps_unref(caps); + return GST_ELEMENT(encoderBin); } diff --git a/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.h b/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.h index f4134b46f..0c8d99d1d 100644 --- a/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.h +++ b/src/plugins/gstreamer/mediacapture/qgstreamervideoencode.h @@ -46,6 +46,8 @@ #include <QtCore/qmap.h> #include <QtCore/qset.h> +#include <private/qgstcodecsinfo_p.h> + #include <gst/gst.h> QT_BEGIN_NAMESPACE @@ -84,10 +86,7 @@ public: private: QGstreamerCaptureSession *m_session; - QStringList m_codecs; - QMap<QString,QString> m_codecDescriptions; - QMap<QString,QByteArray> m_elementNames; - QMap<QString,QStringList> m_codecOptions; + QGstCodecsInfo m_codecs; QVideoEncoderSettings m_videoSettings; QMap<QString, QMap<QString, QVariant> > m_options; diff --git a/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp b/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp index 177a0731c..54f4b103b 100644 --- a/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp +++ b/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp @@ -109,15 +109,16 @@ struct CaptureRequest class QWinRTCameraImageCaptureControlPrivate { public: + QWinRTCameraImageCaptureControlPrivate() + : isActive(false) + { + } + QPointer<QWinRTCameraControl> cameraControl; QHash<IAsyncAction *, CaptureRequest> requests; quint16 currentCaptureId; QMediaStorageLocation location; - - void onCameraStateChanged() - { - - } + bool isActive; }; QWinRTCameraImageCaptureControl::QWinRTCameraImageCaptureControl(QWinRTCameraControl *parent) @@ -128,14 +129,14 @@ QWinRTCameraImageCaptureControl::QWinRTCameraImageCaptureControl(QWinRTCameraCon d->cameraControl = parent; connect(d->cameraControl, &QCameraControl::stateChanged, - this, &QWinRTCameraImageCaptureControl::readyForCaptureChanged); + this, &QWinRTCameraImageCaptureControl::onCameraStateChanged); d->currentCaptureId = 0; } bool QWinRTCameraImageCaptureControl::isReadyForCapture() const { Q_D(const QWinRTCameraImageCaptureControl); - return d->cameraControl->state() == QCamera::ActiveState; + return d->isActive; } QCameraImageCapture::DriveMode QWinRTCameraImageCaptureControl::driveMode() const @@ -215,6 +216,17 @@ void QWinRTCameraImageCaptureControl::cancelCapture() emit captureQueueChanged(true); } +void QWinRTCameraImageCaptureControl::onCameraStateChanged(QCamera::State state) +{ + Q_D(QWinRTCameraImageCaptureControl); + const bool newActive = state == QCamera::ActiveState; + if (d->isActive == newActive) + return; + + d->isActive = newActive; + emit readyForCaptureChanged(newActive); +} + HRESULT QWinRTCameraImageCaptureControl::onCaptureCompleted(IAsyncAction *asyncInfo, AsyncStatus status) { qCDebug(lcMMCamera) << __FUNCTION__; diff --git a/src/plugins/winrt/qwinrtcameraimagecapturecontrol.h b/src/plugins/winrt/qwinrtcameraimagecapturecontrol.h index 177eaf5d7..3820bfaf1 100644 --- a/src/plugins/winrt/qwinrtcameraimagecapturecontrol.h +++ b/src/plugins/winrt/qwinrtcameraimagecapturecontrol.h @@ -40,6 +40,7 @@ #ifndef QWINRTCAMERAIMAGECAPTURECONTROL_H #define QWINRTCAMERAIMAGECAPTURECONTROL_H +#include <QtMultimedia/QCamera> #include <QtMultimedia/QCameraImageCaptureControl> #include <QtCore/qt_windows.h> @@ -71,6 +72,9 @@ public: int capture(const QString &fileName) Q_DECL_OVERRIDE; void cancelCapture() Q_DECL_OVERRIDE; +private slots: + void onCameraStateChanged(QCamera::State state); + signals: void captureQueueChanged(bool isEmpty); |