| 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 "qgstreamercapturemetadatacontrol.h" |
| 41 | |
| 42 | #include <QtMultimedia/qmediametadata.h> |
| 43 | |
| 44 | #include <gst/gst.h> |
| 45 | #include <gst/gstversion.h> |
| 46 | |
| 47 | |
| 48 | typedef QMap<QString, QByteArray> QGstreamerMetaDataKeyLookup; |
| 49 | Q_GLOBAL_STATIC(QGstreamerMetaDataKeyLookup, metadataKeys) |
| 50 | |
| 51 | static const QGstreamerMetaDataKeyLookup *qt_gstreamerMetaDataKeys() |
| 52 | { |
| 53 | if (metadataKeys->isEmpty()) { |
| 54 | metadataKeys->insert(akey: QMediaMetaData::Title, GST_TAG_TITLE); |
| 55 | metadataKeys->insert(akey: QMediaMetaData::SubTitle, avalue: 0); |
| 56 | //metadataKeys->insert(QMediaMetaData::Author, 0); |
| 57 | metadataKeys->insert(akey: QMediaMetaData::Comment, GST_TAG_COMMENT); |
| 58 | metadataKeys->insert(akey: QMediaMetaData::Description, GST_TAG_DESCRIPTION); |
| 59 | //metadataKeys->insert(QMediaMetaData::Category, 0); |
| 60 | metadataKeys->insert(akey: QMediaMetaData::Genre, GST_TAG_GENRE); |
| 61 | //metadataKeys->insert(QMediaMetaData::Year, 0); |
| 62 | //metadataKeys->insert(QMediaMetaData::UserRating, 0); |
| 63 | |
| 64 | metadataKeys->insert(akey: QMediaMetaData::Language, GST_TAG_LANGUAGE_CODE); |
| 65 | |
| 66 | metadataKeys->insert(akey: QMediaMetaData::Publisher, GST_TAG_ORGANIZATION); |
| 67 | metadataKeys->insert(akey: QMediaMetaData::Copyright, GST_TAG_COPYRIGHT); |
| 68 | //metadataKeys->insert(QMediaMetaData::ParentalRating, 0); |
| 69 | //metadataKeys->insert(QMediaMetaData::RatingOrganisation, 0); |
| 70 | |
| 71 | // Media |
| 72 | //metadataKeys->insert(QMediaMetaData::Size, 0); |
| 73 | //metadataKeys->insert(QMediaMetaData::MediaType, 0); |
| 74 | metadataKeys->insert(akey: QMediaMetaData::Duration, GST_TAG_DURATION); |
| 75 | |
| 76 | // Audio |
| 77 | metadataKeys->insert(akey: QMediaMetaData::AudioBitRate, GST_TAG_BITRATE); |
| 78 | metadataKeys->insert(akey: QMediaMetaData::AudioCodec, GST_TAG_AUDIO_CODEC); |
| 79 | //metadataKeys->insert(QMediaMetaData::ChannelCount, 0); |
| 80 | //metadataKeys->insert(QMediaMetaData::SampleRate, 0); |
| 81 | |
| 82 | // Music |
| 83 | metadataKeys->insert(akey: QMediaMetaData::AlbumTitle, GST_TAG_ALBUM); |
| 84 | metadataKeys->insert(akey: QMediaMetaData::AlbumArtist, GST_TAG_ARTIST); |
| 85 | metadataKeys->insert(akey: QMediaMetaData::ContributingArtist, GST_TAG_PERFORMER); |
| 86 | metadataKeys->insert(akey: QMediaMetaData::Composer, GST_TAG_COMPOSER); |
| 87 | //metadataKeys->insert(QMediaMetaData::Conductor, 0); |
| 88 | //metadataKeys->insert(QMediaMetaData::Lyrics, 0); |
| 89 | //metadataKeys->insert(QMediaMetaData::Mood, 0); |
| 90 | metadataKeys->insert(akey: QMediaMetaData::TrackNumber, GST_TAG_TRACK_NUMBER); |
| 91 | |
| 92 | //metadataKeys->insert(QMediaMetaData::CoverArtUrlSmall, 0); |
| 93 | //metadataKeys->insert(QMediaMetaData::CoverArtUrlLarge, 0); |
| 94 | |
| 95 | // Image/Video |
| 96 | //metadataKeys->insert(QMediaMetaData::Resolution, 0); |
| 97 | //metadataKeys->insert(QMediaMetaData::PixelAspectRatio, 0); |
| 98 | |
| 99 | // Video |
| 100 | //metadataKeys->insert(QMediaMetaData::VideoFrameRate, 0); |
| 101 | //metadataKeys->insert(QMediaMetaData::VideoBitRate, 0); |
| 102 | metadataKeys->insert(akey: QMediaMetaData::VideoCodec, GST_TAG_VIDEO_CODEC); |
| 103 | |
| 104 | //metadataKeys->insert(QMediaMetaData::PosterUrl, 0); |
| 105 | |
| 106 | // Movie |
| 107 | //metadataKeys->insert(QMediaMetaData::ChapterNumber, 0); |
| 108 | //metadataKeys->insert(QMediaMetaData::Director, 0); |
| 109 | metadataKeys->insert(akey: QMediaMetaData::LeadPerformer, GST_TAG_PERFORMER); |
| 110 | //metadataKeys->insert(QMediaMetaData::Writer, 0); |
| 111 | |
| 112 | // Photos |
| 113 | //metadataKeys->insert(QMediaMetaData::CameraManufacturer, 0); |
| 114 | //metadataKeys->insert(QMediaMetaData::CameraModel, 0); |
| 115 | //metadataKeys->insert(QMediaMetaData::Event, 0); |
| 116 | //metadataKeys->insert(QMediaMetaData::Subject, 0 } |
| 117 | } |
| 118 | |
| 119 | return metadataKeys; |
| 120 | } |
| 121 | |
| 122 | QGstreamerCaptureMetaDataControl::QGstreamerCaptureMetaDataControl(QObject *parent) |
| 123 | :QMetaDataWriterControl(parent) |
| 124 | { |
| 125 | } |
| 126 | |
| 127 | QVariant QGstreamerCaptureMetaDataControl::metaData(const QString &key) const |
| 128 | { |
| 129 | QGstreamerMetaDataKeyLookup::const_iterator it = qt_gstreamerMetaDataKeys()->find(akey: key); |
| 130 | if (it != qt_gstreamerMetaDataKeys()->constEnd()) |
| 131 | return m_values.value(akey: it.value()); |
| 132 | |
| 133 | return QVariant(); |
| 134 | } |
| 135 | |
| 136 | void QGstreamerCaptureMetaDataControl::setMetaData(const QString &key, const QVariant &value) |
| 137 | { |
| 138 | QGstreamerMetaDataKeyLookup::const_iterator it = qt_gstreamerMetaDataKeys()->find(akey: key); |
| 139 | if (it != qt_gstreamerMetaDataKeys()->constEnd()) { |
| 140 | m_values.insert(akey: it.value(), avalue: value); |
| 141 | |
| 142 | emit QMetaDataWriterControl::metaDataChanged(); |
| 143 | emit QMetaDataWriterControl::metaDataChanged(key, value); |
| 144 | emit metaDataChanged(m_values); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | QStringList QGstreamerCaptureMetaDataControl::availableMetaData() const |
| 149 | { |
| 150 | QStringList res; |
| 151 | for (auto it = m_values.keyBegin(), end = m_values.keyEnd(); it != end; ++it) { |
| 152 | QString tag = qt_gstreamerMetaDataKeys()->key(avalue: *it); |
| 153 | if (!tag.isEmpty()) |
| 154 | res.append(t: tag); |
| 155 | } |
| 156 | |
| 157 | return res; |
| 158 | } |
| 159 | |