diff options
author | Lars Knoll <lars.knoll@qt.io> | 2021-02-17 17:35:00 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2021-03-02 14:51:13 +0000 |
commit | f5ae5377805c3541fa19fe6c8001113f36f86bc4 (patch) | |
tree | 0ad947bedcffa232022b9675cdb904d83d5d22d2 /src/multimedia/qmediametadata.cpp | |
parent | 5ae52a8e075e002293a29c238bee4608b6596ee3 (diff) |
Implement basic metadata support for QMediaPlayer
Unfortunately, GstDiscover has a crappy API that doesn't
allow us to retrieve the data from a running decoder
session (we'd be forced to create a separate decoder session
just to get the data). So let's do things more manually
and parse the topology data from decodebin ourselves.
Change-Id: I0aca195265763f838d21df6814d4edfb3aace2d2
Reviewed-by: Doris Verria <doris.verria@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/multimedia/qmediametadata.cpp')
-rw-r--r-- | src/multimedia/qmediametadata.cpp | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/src/multimedia/qmediametadata.cpp b/src/multimedia/qmediametadata.cpp index 11002d96f..2e4f335ce 100644 --- a/src/multimedia/qmediametadata.cpp +++ b/src/multimedia/qmediametadata.cpp @@ -40,6 +40,9 @@ #include "qmediametadata.h" #include <qvariant.h> #include <qobject.h> +#include <qdatetime.h> +#include <qmediaformat.h> +#include <qsize.h> QT_BEGIN_NAMESPACE @@ -78,12 +81,13 @@ QT_BEGIN_NAMESPACE Media attributes \row \li Size \li The size in bytes of the media. \li qint64 \row \li MediaType \li The type of the media (audio, video, etc). \li QString + \row \li FileFormat \li The file format of the media. \li QMediaFormat::FileFormat \row \li Duration \li The duration in millseconds of the media. \li qint64 \header \li {3,1} Audio attributes \row \li AudioBitRate \li The bit rate of the media's audio stream in bits per second. \li int - \row \li AudioCodec \li The codec of the media's audio stream. \li QString + \row \li AudioCodec \li The codec of the media's audio stream. \li QMediaForma::AudioCodec \row \li AverageLevel \li The average volume level of the media. \li int \row \li ChannelCount \li The number of channels in the media's audio stream. \li int \row \li PeakValue \li The peak volume of the media's audio stream. \li int @@ -115,7 +119,7 @@ QT_BEGIN_NAMESPACE Video attributes \row \li VideoFrameRate \li The frame rate of the media's video stream. \li qreal \row \li VideoBitRate \li The bit rate of the media's video stream in bits per second. \li int - \row \li VideoCodec \li The codec of the media's video stream. \li QString + \row \li VideoCodec \li The codec of the media's video stream. \li QMediaFormat::VideoCodec \row \li PosterUrl \li The URL of a poster image. \li QUrl \row \li PosterImage \li An embedded poster image. \li QImage @@ -233,6 +237,57 @@ void QMediaMetaData::insert(QMediaMetaData::Key k, const QVariant &value) data.insert(k, value); } +QString QMediaMetaData::stringValue(QMediaMetaData::Key k) const +{ + QVariant value = data.value(k); + if (value.isNull()) + return QString(); + + switch (k) { + // string based or convertible to string + case Title: + case Author: + case Comment: + case Description: + case Genre: + case Year: + case Language: + case Publisher: + case Copyright: + case Date: + case Url: + case MediaType: + case AudioBitRate: + case VideoBitRate: + case VideoFrameRate: + case AlbumTitle: + case AlbumArtist: + case ContributingArtist: + case TrackNumber: + case Composer: + case Orientation: + case LeadPerformer: + return value.toString(); + case Duration: { + QTime time = QTime::fromMSecsSinceStartOfDay(value.toInt()); + return time.toString(); + } + case FileFormat: + return QMediaFormat::fileFormatName(value.value<QMediaFormat::FileFormat>()); + case AudioCodec: + return QMediaFormat::audioCodecName(value.value<QMediaFormat::AudioCodec>()); + case VideoCodec: + return QMediaFormat::videoCodecName(value.value<QMediaFormat::VideoCodec>()); + case Resolution: { + QSize size = value.toSize(); + return QString::fromUtf8("%1 x %2").arg(size.width()).arg(size.height()); + } + case ThumbnailImage: + case CoverArtImage: + return QString(); + } +} + QString QMediaMetaData::metaDataKeyToString(QMediaMetaData::Key k) { switch (k) { @@ -262,6 +317,8 @@ QString QMediaMetaData::metaDataKeyToString(QMediaMetaData::Key k) return (QObject::tr("Duration")); case QMediaMetaData::MediaType: return (QObject::tr("Media type")); + case QMediaMetaData::FileFormat: + return (QObject::tr("Container Format")); case QMediaMetaData::AudioBitRate: return (QObject::tr("Audio bit rate")); case QMediaMetaData::AudioCodec: @@ -270,6 +327,8 @@ QString QMediaMetaData::metaDataKeyToString(QMediaMetaData::Key k) return (QObject::tr("Video bit rate")); case QMediaMetaData::VideoCodec: return (QObject::tr("Video codec")); + case QMediaMetaData::VideoFrameRate: + return (QObject::tr("Video frame rate")); case QMediaMetaData::AlbumTitle: return (QObject::tr("Album title")); case QMediaMetaData::AlbumArtist: |