diff options
author | Yoann Lopes <yoann.lopes@digia.com> | 2014-06-03 16:32:46 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-06-06 11:12:21 +0200 |
commit | eadf1c8c41a41509a7c87b44d66b48cb8345acdb (patch) | |
tree | 3f05e4a81c6d6b8eb451c7c9cd63027b2781cccc /src/plugins/gstreamer/mediacapture | |
parent | 8a66559e0b7d94d6b2ffe613b61194407031730c (diff) | |
download | qtmultimedia-eadf1c8c41a41509a7c87b44d66b48cb8345acdb.tar.gz |
Fix static initialization order fiasco in some plugins.
Some static variables were initialized using QMediaMetaData
values, which are also statically initialized.
Task-number: QTBUG-39202
Change-Id: Ibedc0a77d96cdfa575aad122c4ec654e6830e1f7
Reviewed-by: Andrew den Exter <andrew.den.exter@qinetic.com.au>
Diffstat (limited to 'src/plugins/gstreamer/mediacapture')
-rw-r--r-- | src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.cpp | 182 |
1 files changed, 82 insertions, 100 deletions
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.cpp b/src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.cpp index fd7fb7d82..1080a5875 100644 --- a/src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.cpp +++ b/src/plugins/gstreamer/mediacapture/qgstreamercapturemetadatacontrol.cpp @@ -46,80 +46,82 @@ #include <gst/gst.h> #include <gst/gstversion.h> -struct QGstreamerMetaDataKeyLookup -{ - QString key; - const char *token; -}; -static const QGstreamerMetaDataKeyLookup qt_gstreamerMetaDataKeys[] = +typedef QMap<QString, QByteArray> QGstreamerMetaDataKeyLookup; +Q_GLOBAL_STATIC(QGstreamerMetaDataKeyLookup, metadataKeys) + +static const QGstreamerMetaDataKeyLookup *qt_gstreamerMetaDataKeys() { - { QMediaMetaData::Title, GST_TAG_TITLE }, - //{ QMediaMetaData::SubTitle, 0 }, - //{ QMediaMetaData::Author, 0 }, - { QMediaMetaData::Comment, GST_TAG_COMMENT }, - { QMediaMetaData::Description, GST_TAG_DESCRIPTION }, - //{ QMediaMetaData::Category, 0 }, - { QMediaMetaData::Genre, GST_TAG_GENRE }, - //{ QMediaMetaData::Year, 0 }, - //{ QMediaMetaData::UserRating, 0 }, - - { QMediaMetaData::Language, GST_TAG_LANGUAGE_CODE }, - - { QMediaMetaData::Publisher, GST_TAG_ORGANIZATION }, - { QMediaMetaData::Copyright, GST_TAG_COPYRIGHT }, - //{ QMediaMetaData::ParentalRating, 0 }, - //{ QMediaMetaData::RatingOrganisation, 0 }, - - // Media - //{ QMediaMetaData::Size, 0 }, - //{ QMediaMetaData::MediaType, 0 }, - { QMediaMetaData::Duration, GST_TAG_DURATION }, - - // Audio - { QMediaMetaData::AudioBitRate, GST_TAG_BITRATE }, - { QMediaMetaData::AudioCodec, GST_TAG_AUDIO_CODEC }, - //{ QMediaMetaData::ChannelCount, 0 }, - //{ QMediaMetaData::SampleRate, 0 }, - - // Music - { QMediaMetaData::AlbumTitle, GST_TAG_ALBUM }, - { QMediaMetaData::AlbumArtist, GST_TAG_ARTIST}, - { QMediaMetaData::ContributingArtist, GST_TAG_PERFORMER }, + if (metadataKeys->isEmpty()) { + metadataKeys->insert(QMediaMetaData::Title, GST_TAG_TITLE); + metadataKeys->insert(QMediaMetaData::SubTitle, 0); + //metadataKeys->insert(QMediaMetaData::Author, 0); + metadataKeys->insert(QMediaMetaData::Comment, GST_TAG_COMMENT); + metadataKeys->insert(QMediaMetaData::Description, GST_TAG_DESCRIPTION); + //metadataKeys->insert(QMediaMetaData::Category, 0); + metadataKeys->insert(QMediaMetaData::Genre, GST_TAG_GENRE); + //metadataKeys->insert(QMediaMetaData::Year, 0); + //metadataKeys->insert(QMediaMetaData::UserRating, 0); + + metadataKeys->insert(QMediaMetaData::Language, GST_TAG_LANGUAGE_CODE); + + metadataKeys->insert(QMediaMetaData::Publisher, GST_TAG_ORGANIZATION); + metadataKeys->insert(QMediaMetaData::Copyright, GST_TAG_COPYRIGHT); + //metadataKeys->insert(QMediaMetaData::ParentalRating, 0); + //metadataKeys->insert(QMediaMetaData::RatingOrganisation, 0); + + // Media + //metadataKeys->insert(QMediaMetaData::Size, 0); + //metadataKeys->insert(QMediaMetaData::MediaType, 0); + metadataKeys->insert(QMediaMetaData::Duration, GST_TAG_DURATION); + + // Audio + metadataKeys->insert(QMediaMetaData::AudioBitRate, GST_TAG_BITRATE); + metadataKeys->insert(QMediaMetaData::AudioCodec, GST_TAG_AUDIO_CODEC); + //metadataKeys->insert(QMediaMetaData::ChannelCount, 0); + //metadataKeys->insert(QMediaMetaData::SampleRate, 0); + + // Music + metadataKeys->insert(QMediaMetaData::AlbumTitle, GST_TAG_ALBUM); + metadataKeys->insert(QMediaMetaData::AlbumArtist, GST_TAG_ARTIST); + metadataKeys->insert(QMediaMetaData::ContributingArtist, GST_TAG_PERFORMER); #if (GST_VERSION_MAJOR >= 0) && (GST_VERSION_MINOR >= 10) && (GST_VERSION_MICRO >= 19) - { QMediaMetaData::Composer, GST_TAG_COMPOSER }, + metadataKeys->insert(QMediaMetaData::Composer, GST_TAG_COMPOSER); #endif - //{ QMediaMetaData::Conductor, 0 }, - //{ QMediaMetaData::Lyrics, 0 }, - //{ QMediaMetaData::Mood, 0 }, - { QMediaMetaData::TrackNumber, GST_TAG_TRACK_NUMBER }, - - //{ QMediaMetaData::CoverArtUrlSmall, 0 }, - //{ QMediaMetaData::CoverArtUrlLarge, 0 }, - - // Image/Video - //{ QMediaMetaData::Resolution, 0 }, - //{ QMediaMetaData::PixelAspectRatio, 0 }, - - // Video - //{ QMediaMetaData::VideoFrameRate, 0 }, - //{ QMediaMetaData::VideoBitRate, 0 }, - { QMediaMetaData::VideoCodec, GST_TAG_VIDEO_CODEC }, - - //{ QMediaMetaData::PosterUrl, 0 }, - - // Movie - //{ QMediaMetaData::ChapterNumber, 0 }, - //{ QMediaMetaData::Director, 0 }, - { QMediaMetaData::LeadPerformer, GST_TAG_PERFORMER }, - //{ QMediaMetaData::Writer, 0 }, - - // Photos - //{ QMediaMetaData::CameraManufacturer, 0 }, - //{ QMediaMetaData::CameraModel, 0 }, - //{ QMediaMetaData::Event, 0 }, - //{ QMediaMetaData::Subject, 0 } -}; + //metadataKeys->insert(QMediaMetaData::Conductor, 0); + //metadataKeys->insert(QMediaMetaData::Lyrics, 0); + //metadataKeys->insert(QMediaMetaData::Mood, 0); + metadataKeys->insert(QMediaMetaData::TrackNumber, GST_TAG_TRACK_NUMBER); + + //metadataKeys->insert(QMediaMetaData::CoverArtUrlSmall, 0); + //metadataKeys->insert(QMediaMetaData::CoverArtUrlLarge, 0); + + // Image/Video + //metadataKeys->insert(QMediaMetaData::Resolution, 0); + //metadataKeys->insert(QMediaMetaData::PixelAspectRatio, 0); + + // Video + //metadataKeys->insert(QMediaMetaData::VideoFrameRate, 0); + //metadataKeys->insert(QMediaMetaData::VideoBitRate, 0); + metadataKeys->insert(QMediaMetaData::VideoCodec, GST_TAG_VIDEO_CODEC); + + //metadataKeys->insert(QMediaMetaData::PosterUrl, 0); + + // Movie + //metadataKeys->insert(QMediaMetaData::ChapterNumber, 0); + //metadataKeys->insert(QMediaMetaData::Director, 0); + metadataKeys->insert(QMediaMetaData::LeadPerformer, GST_TAG_PERFORMER); + //metadataKeys->insert(QMediaMetaData::Writer, 0); + + // Photos + //metadataKeys->insert(QMediaMetaData::CameraManufacturer, 0); + //metadataKeys->insert(QMediaMetaData::CameraModel, 0); + //metadataKeys->insert(QMediaMetaData::Event, 0); + //metadataKeys->insert(QMediaMetaData::Subject, 0 } + } + + return metadataKeys; +} QGstreamerCaptureMetaDataControl::QGstreamerCaptureMetaDataControl(QObject *parent) :QMetaDataWriterControl(parent) @@ -128,50 +130,30 @@ QGstreamerCaptureMetaDataControl::QGstreamerCaptureMetaDataControl(QObject *pare QVariant QGstreamerCaptureMetaDataControl::metaData(const QString &key) const { - static const int count = sizeof(qt_gstreamerMetaDataKeys) / sizeof(QGstreamerMetaDataKeyLookup); - - for (int i = 0; i < count; ++i) { - if (qt_gstreamerMetaDataKeys[i].key == key) { - const char *name = qt_gstreamerMetaDataKeys[i].token; + QGstreamerMetaDataKeyLookup::const_iterator it = qt_gstreamerMetaDataKeys()->find(key); + if (it != qt_gstreamerMetaDataKeys()->constEnd()) + return m_values.value(it.value()); - return m_values.value(QByteArray::fromRawData(name, qstrlen(name))); - } - } return QVariant(); } void QGstreamerCaptureMetaDataControl::setMetaData(const QString &key, const QVariant &value) { - static const int count = sizeof(qt_gstreamerMetaDataKeys) / sizeof(QGstreamerMetaDataKeyLookup); - - for (int i = 0; i < count; ++i) { - if (qt_gstreamerMetaDataKeys[i].key == key) { - const char *name = qt_gstreamerMetaDataKeys[i].token; - - m_values.insert(QByteArray::fromRawData(name, qstrlen(name)), value); + QGstreamerMetaDataKeyLookup::const_iterator it = qt_gstreamerMetaDataKeys()->find(key); + if (it != qt_gstreamerMetaDataKeys()->constEnd()) { + m_values.insert(it.value(), value); - emit QMetaDataWriterControl::metaDataChanged(); - emit QMetaDataWriterControl::metaDataChanged(key, value); - emit metaDataChanged(m_values); - - return; - } + emit QMetaDataWriterControl::metaDataChanged(); + emit QMetaDataWriterControl::metaDataChanged(key, value); + emit metaDataChanged(m_values); } } QStringList QGstreamerCaptureMetaDataControl::availableMetaData() const { - static QMap<QByteArray, QString> keysMap; - if (keysMap.isEmpty()) { - const int count = sizeof(qt_gstreamerMetaDataKeys) / sizeof(QGstreamerMetaDataKeyLookup); - for (int i = 0; i < count; ++i) { - keysMap[QByteArray(qt_gstreamerMetaDataKeys[i].token)] = qt_gstreamerMetaDataKeys[i].key; - } - } - QStringList res; foreach (const QByteArray &key, m_values.keys()) { - QString tag = keysMap.value(key); + QString tag = qt_gstreamerMetaDataKeys()->key(key); if (!tag.isEmpty()) res.append(tag); } |