diff options
Diffstat (limited to 'src/multimedia/platform/darwin/mediaplayer')
-rw-r--r-- | src/multimedia/platform/darwin/mediaplayer/avfmediaplayercontrol.mm | 11 | ||||
-rw-r--r-- | src/multimedia/platform/darwin/mediaplayer/avfmediaplayercontrol_p.h | 4 | ||||
-rw-r--r-- | src/multimedia/platform/darwin/mediaplayer/avfmediaplayerservice.mm | 29 | ||||
-rw-r--r-- | src/multimedia/platform/darwin/mediaplayer/avfmediaplayerservice_p.h | 3 | ||||
-rw-r--r-- | src/multimedia/platform/darwin/mediaplayer/avfmediaplayersession.mm | 6 | ||||
-rw-r--r-- | src/multimedia/platform/darwin/mediaplayer/avfmetadata.mm (renamed from src/multimedia/platform/darwin/mediaplayer/avfmediaplayermetadatacontrol.mm) | 92 | ||||
-rw-r--r-- | src/multimedia/platform/darwin/mediaplayer/avfmetadata_p.h (renamed from src/multimedia/platform/darwin/mediaplayer/avfmediaplayermetadatacontrol_p.h) | 23 | ||||
-rw-r--r-- | src/multimedia/platform/darwin/mediaplayer/mediaplayer.pri | 4 |
8 files changed, 43 insertions, 129 deletions
diff --git a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayercontrol.mm b/src/multimedia/platform/darwin/mediaplayer/avfmediaplayercontrol.mm index bfc667509..1e55fb770 100644 --- a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayercontrol.mm +++ b/src/multimedia/platform/darwin/mediaplayer/avfmediaplayercontrol.mm @@ -177,6 +177,17 @@ QAudioDeviceInfo AVFMediaPlayerControl::audioOutput() const #endif } +QMediaMetaData AVFMediaPlayerControl::metaData() const +{ + return m_metaData; +} + +void AVFMediaPlayerControl::setMetaData(const QMediaMetaData &metaData) +{ + m_metaData = metaData; + metaDataChanged(); +} + void AVFMediaPlayerControl::setPosition(qint64 pos) { m_session->setPosition(pos); diff --git a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayercontrol_p.h b/src/multimedia/platform/darwin/mediaplayer/avfmediaplayercontrol_p.h index b4fd8dc5a..9b8018ecb 100644 --- a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayercontrol_p.h +++ b/src/multimedia/platform/darwin/mediaplayer/avfmediaplayercontrol_p.h @@ -94,6 +94,9 @@ public: bool setAudioOutput(const QAudioDeviceInfo &) override; QAudioDeviceInfo audioOutput() const override; + QMediaMetaData metaData() const override; + void setMetaData(const QMediaMetaData &metaData); + public Q_SLOTS: void setPosition(qint64 pos) override; @@ -106,6 +109,7 @@ public Q_SLOTS: private: AVFMediaPlayerSession *m_session; + QMediaMetaData m_metaData; }; QT_END_NAMESPACE diff --git a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayerservice.mm b/src/multimedia/platform/darwin/mediaplayer/avfmediaplayerservice.mm index b300c4c1a..32cc5fd27 100644 --- a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayerservice.mm +++ b/src/multimedia/platform/darwin/mediaplayer/avfmediaplayerservice.mm @@ -40,7 +40,6 @@ #include "avfmediaplayerservice_p.h" #include "avfmediaplayersession_p.h" #include "avfmediaplayercontrol_p.h" -#include "avfmediaplayermetadatacontrol_p.h" #include "avfvideooutput_p.h" #if QT_CONFIG(opengl) #include "avfvideorenderercontrol_p.h" @@ -56,9 +55,6 @@ AVFMediaPlayerService::AVFMediaPlayerService() m_session = new AVFMediaPlayerSession(this); m_control = new AVFMediaPlayerControl(this); m_control->setSession(m_session); - m_playerMetaDataControl = new AVFMediaPlayerMetaDataControl(m_session, this); - - connect(m_control, SIGNAL(mediaChanged(QMediaContent)), m_playerMetaDataControl, SLOT(updateTags())); } AVFMediaPlayerService::~AVFMediaPlayerService() @@ -78,9 +74,6 @@ QObject *AVFMediaPlayerService::requestControl(const char *name) if (qstrcmp(name, QMediaPlayerControl_iid) == 0) return m_control; - if (qstrcmp(name, QMetaDataReaderControl_iid) == 0) - return m_playerMetaDataControl; - #if QT_CONFIG(opengl) if (qstrcmp(name, QVideoRendererControl_iid) == 0) { if (!m_videoOutput) @@ -124,11 +117,6 @@ QMediaPlayerControl *AVFMediaPlayerService::player() return m_control; } -QMetaDataReaderControl *AVFMediaPlayerService::dataReader() -{ - return m_playerMetaDataControl; -} - QVideoRendererControl *AVFMediaPlayerService::createVideoRenderer() { if (m_videoOutput) @@ -152,20 +140,3 @@ QVideoWindowControl *AVFMediaPlayerService::createVideoWindow() m_session->setVideoOutput(control); return control; } - -#if 0 -void listSupportedMimeTypes() -{ - //Populate m_supportedMimeTypes with mimetypes AVAsset supports - NSArray *mimeTypes = [AVURLAsset audiovisualMIMETypes]; - for (NSString *mimeType in mimeTypes) - { - m_supportedMimeTypes.append(QString::fromUtf8([mimeType UTF8String])); - } -#ifdef QT_DEBUG_AVF - qDebug() << "AVFMediaPlayerServicePlugin::buildSupportedTypes"; - qDebug() << "Supported Types: " << m_supportedMimeTypes; -#endif - -} -#endif diff --git a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayerservice_p.h b/src/multimedia/platform/darwin/mediaplayer/avfmediaplayerservice_p.h index f37c1e50f..2690c7828 100644 --- a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayerservice_p.h +++ b/src/multimedia/platform/darwin/mediaplayer/avfmediaplayerservice_p.h @@ -57,7 +57,6 @@ QT_BEGIN_NAMESPACE class AVFMediaPlayerSession; class AVFMediaPlayerControl; -class AVFMediaPlayerMetaDataControl; class AVFVideoOutput; class AVFMediaPlayerService : public QMediaPlatformPlayerInterface @@ -71,7 +70,6 @@ public: // QMediaPlatformPlayerInterface QMediaPlayerControl *player() override; - QMetaDataReaderControl *dataReader() override; // QMediaStreamsControl *streams() override; QVideoRendererControl *createVideoRenderer() override; @@ -82,7 +80,6 @@ private: AVFMediaPlayerSession *m_session = nullptr; AVFMediaPlayerControl *m_control = nullptr; QObject *m_videoOutput = nullptr; - AVFMediaPlayerMetaDataControl *m_playerMetaDataControl = nullptr; }; QT_END_NAMESPACE diff --git a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayersession.mm b/src/multimedia/platform/darwin/mediaplayer/avfmediaplayersession.mm index 7fa6d25c6..386e66ecd 100644 --- a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayersession.mm +++ b/src/multimedia/platform/darwin/mediaplayer/avfmediaplayersession.mm @@ -39,7 +39,9 @@ #include "avfmediaplayersession_p.h" #include "avfmediaplayerservice_p.h" +#include "avfmediaplayercontrol_p.h" #include "avfvideooutput_p.h" +#include "avfmetadata_p.h" #include <qpointer.h> #include <QFileInfo> @@ -945,6 +947,10 @@ void AVFMediaPlayerSession::processLoadStateChange(QMediaPlayer::State newState) AVPlayerItem *playerItem = [static_cast<AVFMediaPlayerSessionObserver*>(m_observer) playerItem]; + // get the meta data + QMediaMetaData metaData = AVFMetaData::fromAsset(playerItem.asset); + static_cast<AVFMediaPlayerControl *>(m_service->player())->setMetaData(metaData); + if (playerItem) { // Check each track for audio and video content AVAssetTrack *videoTrack = nil; diff --git a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayermetadatacontrol.mm b/src/multimedia/platform/darwin/mediaplayer/avfmetadata.mm index 5a5780e52..0b6feace4 100644 --- a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayermetadatacontrol.mm +++ b/src/multimedia/platform/darwin/mediaplayer/avfmetadata.mm @@ -37,8 +37,7 @@ ** ****************************************************************************/ -#include "avfmediaplayermetadatacontrol_p.h" -#include "avfmediaplayersession_p.h" +#include "avfmetadata_p.h" #include <QtMultimedia/qmediametadata.h> @@ -46,50 +45,15 @@ QT_USE_NAMESPACE -AVFMediaPlayerMetaDataControl::AVFMediaPlayerMetaDataControl(AVFMediaPlayerSession *session, QObject *parent) - : QMetaDataReaderControl(parent) - , m_session(session) - , m_asset(nullptr) -{ - QObject::connect(m_session, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(updateTags())); -} - -AVFMediaPlayerMetaDataControl::~AVFMediaPlayerMetaDataControl() -{ -#ifdef QT_DEBUG_AVF - qDebug() << Q_FUNC_INFO; -#endif -} - -bool AVFMediaPlayerMetaDataControl::isMetaDataAvailable() const -{ - return !m_tags.isEmpty(); -} - -bool AVFMediaPlayerMetaDataControl::isWritable() const -{ - return false; -} - -QVariant AVFMediaPlayerMetaDataControl::metaData(const QString &key) const -{ - return m_tags.value(key); -} - -QStringList AVFMediaPlayerMetaDataControl::availableMetaData() const -{ - return m_tags.keys(); -} - -static QString itemKey(AVMetadataItem *item) +static std::optional<QMediaMetaData::Key> itemKey(AVMetadataItem *item) { NSString *keyString = [item commonKey]; if (keyString.length != 0) { if ([keyString isEqualToString:AVMetadataCommonKeyTitle]) { return QMediaMetaData::Title; - } else if ([keyString isEqualToString: AVMetadataCommonKeySubject]) { - return QMediaMetaData::SubTitle; +// } else if ([keyString isEqualToString: AVMetadataCommonKeySubject]) { +// return QMediaMetaData::SubTitle; } else if ([keyString isEqualToString: AVMetadataCommonKeyDescription]) { return QMediaMetaData::Description; } else if ([keyString isEqualToString: AVMetadataCommonKeyPublisher]) { @@ -108,54 +72,32 @@ static QString itemKey(AVMetadataItem *item) return QMediaMetaData::Author; } else if ([keyString isEqualToString: AVMetadataCommonKeyArtist]) { return QMediaMetaData::ContributingArtist; - } else if ([keyString isEqualToString: AVMetadataCommonKeyArtwork]) { - return QMediaMetaData::PosterUrl; +// } else if ([keyString isEqualToString: AVMetadataCommonKeyArtwork]) { +// return QMediaMetaData::PosterUrl; } } - return QString(); + return std::nullopt; } -void AVFMediaPlayerMetaDataControl::updateTags() +QMediaMetaData AVFMetaData::fromAsset(AVAsset *asset) { #ifdef QT_DEBUG_AVF qDebug() << Q_FUNC_INFO; #endif - AVAsset *currentAsset = static_cast<AVAsset*>(m_session->currentAssetHandle()); - - //Don't read the tags from the same asset more than once - if (currentAsset == m_asset) - return; - - m_asset = currentAsset; - - QVariantMap oldTags = m_tags; - //Since we've changed assets, clear old tags - m_tags.clear(); - bool changed = false; + QMediaMetaData metaData; // TODO: also process ID3, iTunes and QuickTime metadata - NSArray *metadataItems = [currentAsset commonMetadata]; + NSArray *metadataItems = [asset commonMetadata]; for (AVMetadataItem* item in metadataItems) { - const QString key = itemKey(item); - if (!key.isEmpty()) { - const QString value = QString::fromNSString([item stringValue]); - if (!value.isNull()) { - m_tags.insert(key, value); - if (value != oldTags.value(key)) { - changed = true; - Q_EMIT metaDataChanged(key, value); - } - } - } - } + auto key = itemKey(item); + if (!key) + continue; - if (oldTags.isEmpty() != m_tags.isEmpty()) { - Q_EMIT metaDataAvailableChanged(!m_tags.isEmpty()); - changed = true; + const QString value = QString::fromNSString([item stringValue]); + if (!value.isNull()) + metaData.insert(*key, value); } - - if (changed) - Q_EMIT metaDataChanged(); + return metaData; } diff --git a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayermetadatacontrol_p.h b/src/multimedia/platform/darwin/mediaplayer/avfmetadata_p.h index 067aa2487..c88a4084d 100644 --- a/src/multimedia/platform/darwin/mediaplayer/avfmediaplayermetadatacontrol_p.h +++ b/src/multimedia/platform/darwin/mediaplayer/avfmetadata_p.h @@ -51,7 +51,7 @@ // We mean it. // -#include <QtMultimedia/QMetaDataReaderControl> +#include <QtMultimedia/QMediaMetaData> #include <QtCore/qvariant.h> QT_BEGIN_NAMESPACE @@ -60,27 +60,10 @@ Q_FORWARD_DECLARE_OBJC_CLASS(AVAsset); class AVFMediaPlayerSession; -class AVFMediaPlayerMetaDataControl : public QMetaDataReaderControl +class AVFMetaData { - Q_OBJECT public: - explicit AVFMediaPlayerMetaDataControl(AVFMediaPlayerSession *session, QObject *parent = nullptr); - virtual ~AVFMediaPlayerMetaDataControl(); - - bool isMetaDataAvailable() const override; - bool isWritable() const; - - QVariant metaData(const QString &key) const override; - QStringList availableMetaData() const override; - -private Q_SLOTS: - void updateTags(); - -private: - AVFMediaPlayerSession *m_session; - QVariantMap m_tags; - AVAsset *m_asset; - + static QMediaMetaData fromAsset(AVAsset *asset); }; QT_END_NAMESPACE diff --git a/src/multimedia/platform/darwin/mediaplayer/mediaplayer.pri b/src/multimedia/platform/darwin/mediaplayer/mediaplayer.pri index 6c02ed23d..0aab9faa5 100644 --- a/src/multimedia/platform/darwin/mediaplayer/mediaplayer.pri +++ b/src/multimedia/platform/darwin/mediaplayer/mediaplayer.pri @@ -2,7 +2,7 @@ QT += opengl network HEADERS += \ $$PWD/avfmediaplayercontrol_p.h \ - $$PWD/avfmediaplayermetadatacontrol_p.h \ + $$PWD/avfmetadata_p.h \ $$PWD/avfmediaplayerservice_p.h \ $$PWD/avfmediaplayersession_p.h \ $$PWD/avfvideooutput_p.h \ @@ -10,7 +10,7 @@ HEADERS += \ SOURCES += \ $$PWD/avfmediaplayercontrol.mm \ - $$PWD/avfmediaplayermetadatacontrol.mm \ + $$PWD/avfmetadata.mm \ $$PWD/avfmediaplayerservice.mm \ $$PWD/avfmediaplayersession.mm \ $$PWD/avfvideooutput.mm \ |