1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qgstreamermetadataprovider.h"
41#include <private/qgstreamerplayersession_p.h>
42#include <QDebug>
43#include <QtMultimedia/qmediametadata.h>
44
45#include <gst/gstversion.h>
46#include <private/qgstutils_p.h>
47
48QT_BEGIN_NAMESPACE
49
50typedef QMap<QByteArray, QString> QGstreamerMetaDataKeyLookup;
51Q_GLOBAL_STATIC(QGstreamerMetaDataKeyLookup, metadataKeys)
52
53static const QGstreamerMetaDataKeyLookup *qt_gstreamerMetaDataKeys()
54{
55 if (metadataKeys->isEmpty()) {
56 metadataKeys->insert(GST_TAG_TITLE, avalue: QMediaMetaData::Title);
57 //metadataKeys->insert(0, QMediaMetaData::SubTitle);
58 //metadataKeys->insert(0, QMediaMetaData::Author);
59 metadataKeys->insert(GST_TAG_COMMENT, avalue: QMediaMetaData::Comment);
60 metadataKeys->insert(GST_TAG_DESCRIPTION, avalue: QMediaMetaData::Description);
61 //metadataKeys->insert(0, QMediaMetaData::Category);
62 metadataKeys->insert(GST_TAG_GENRE, avalue: QMediaMetaData::Genre);
63 metadataKeys->insert(akey: "year", avalue: QMediaMetaData::Year);
64 //metadataKeys->insert(0, QMediaMetaData::UserRating);
65
66 metadataKeys->insert(GST_TAG_LANGUAGE_CODE, avalue: QMediaMetaData::Language);
67
68 metadataKeys->insert(GST_TAG_ORGANIZATION, avalue: QMediaMetaData::Publisher);
69 metadataKeys->insert(GST_TAG_COPYRIGHT, avalue: QMediaMetaData::Copyright);
70 //metadataKeys->insert(0, QMediaMetaData::ParentalRating);
71 //metadataKeys->insert(0, QMediaMetaData::RatingOrganisation);
72
73 // Media
74 //metadataKeys->insert(0, QMediaMetaData::Size);
75 //metadataKeys->insert(0,QMediaMetaData::MediaType );
76 metadataKeys->insert(GST_TAG_DURATION, avalue: QMediaMetaData::Duration);
77
78 // Audio
79 metadataKeys->insert(GST_TAG_BITRATE, avalue: QMediaMetaData::AudioBitRate);
80 metadataKeys->insert(GST_TAG_AUDIO_CODEC, avalue: QMediaMetaData::AudioCodec);
81 //metadataKeys->insert(0, QMediaMetaData::ChannelCount);
82 //metadataKeys->insert(0, QMediaMetaData::SampleRate);
83
84 // Music
85 metadataKeys->insert(GST_TAG_ALBUM, avalue: QMediaMetaData::AlbumTitle);
86#if GST_CHECK_VERSION(0, 10, 25)
87 metadataKeys->insert(GST_TAG_ALBUM_ARTIST, avalue: QMediaMetaData::AlbumArtist);
88#endif
89 metadataKeys->insert(GST_TAG_ARTIST, avalue: QMediaMetaData::ContributingArtist);
90 //metadataKeys->insert(0, QMediaMetaData::Conductor);
91 //metadataKeys->insert(0, QMediaMetaData::Lyrics);
92 //metadataKeys->insert(0, QMediaMetaData::Mood);
93 metadataKeys->insert(GST_TAG_TRACK_NUMBER, avalue: QMediaMetaData::TrackNumber);
94
95 //metadataKeys->insert(0, QMediaMetaData::CoverArtUrlSmall);
96 //metadataKeys->insert(0, QMediaMetaData::CoverArtUrlLarge);
97 metadataKeys->insert(GST_TAG_PREVIEW_IMAGE, avalue: QMediaMetaData::ThumbnailImage);
98 metadataKeys->insert(GST_TAG_IMAGE, avalue: QMediaMetaData::CoverArtImage);
99
100 // Image/Video
101 metadataKeys->insert(akey: "resolution", avalue: QMediaMetaData::Resolution);
102 metadataKeys->insert(akey: "pixel-aspect-ratio", avalue: QMediaMetaData::PixelAspectRatio);
103#if GST_CHECK_VERSION(0,10,30)
104 metadataKeys->insert(GST_TAG_IMAGE_ORIENTATION, avalue: QMediaMetaData::Orientation);
105#endif
106
107 // Video
108 //metadataKeys->insert(0, QMediaMetaData::VideoFrameRate);
109 //metadataKeys->insert(0, QMediaMetaData::VideoBitRate);
110 metadataKeys->insert(GST_TAG_VIDEO_CODEC, avalue: QMediaMetaData::VideoCodec);
111
112 //metadataKeys->insert(0, QMediaMetaData::PosterUrl);
113
114 // Movie
115 //metadataKeys->insert(0, QMediaMetaData::ChapterNumber);
116 //metadataKeys->insert(0, QMediaMetaData::Director);
117 metadataKeys->insert(GST_TAG_PERFORMER, avalue: QMediaMetaData::LeadPerformer);
118 //metadataKeys->insert(0, QMediaMetaData::Writer);
119
120 // Photos
121 //metadataKeys->insert(0, QMediaMetaData::CameraManufacturer);
122 //metadataKeys->insert(0, QMediaMetaData::CameraModel);
123 //metadataKeys->insert(0, QMediaMetaData::Event);
124 //metadataKeys->insert(0, QMediaMetaData::Subject);
125 }
126
127 return metadataKeys;
128}
129
130QGstreamerMetaDataProvider::QGstreamerMetaDataProvider(QGstreamerPlayerSession *session, QObject *parent)
131 :QMetaDataReaderControl(parent), m_session(session)
132{
133 connect(asender: m_session, SIGNAL(tagsChanged()), SLOT(updateTags()));
134}
135
136QGstreamerMetaDataProvider::~QGstreamerMetaDataProvider()
137{
138}
139
140bool QGstreamerMetaDataProvider::isMetaDataAvailable() const
141{
142 return !m_session->tags().isEmpty();
143}
144
145bool QGstreamerMetaDataProvider::isWritable() const
146{
147 return false;
148}
149
150QVariant QGstreamerMetaDataProvider::metaData(const QString &key) const
151{
152#if GST_CHECK_VERSION(0,10,30)
153 if (key == QMediaMetaData::Orientation)
154 return QGstUtils::fromGStreamerOrientation(value: m_tags.value(akey: key));
155#endif
156 return m_tags.value(akey: key);
157}
158
159QStringList QGstreamerMetaDataProvider::availableMetaData() const
160{
161 return m_tags.keys();
162}
163
164void QGstreamerMetaDataProvider::updateTags()
165{
166 QVariantMap oldTags = m_tags;
167 m_tags.clear();
168 bool changed = false;
169
170 const auto tags = m_session->tags();
171 for (auto i = tags.cbegin(), end = tags.cend(); i != end; ++i) {
172 //use gstreamer native keys for elements not in our key map
173 QString key = qt_gstreamerMetaDataKeys()->value(akey: i.key(), adefaultValue: i.key());
174 m_tags.insert(akey: key, avalue: i.value());
175 if (i.value() != oldTags.value(akey: key)) {
176 changed = true;
177 emit metaDataChanged(key, value: i.value());
178 }
179 }
180
181 if (oldTags.isEmpty() != m_tags.isEmpty()) {
182 emit metaDataAvailableChanged(available: isMetaDataAvailable());
183 changed = true;
184 }
185
186 if (changed)
187 emit metaDataChanged();
188}
189
190QT_END_NAMESPACE
191

source code of qtmultimedia/src/plugins/gstreamer/mediaplayer/qgstreamermetadataprovider.cpp