Support exif rotation on received videos

fixes #674
This commit is contained in:
Nicolas Werner 2021-11-15 03:35:35 +01:00
parent 131c64ecde
commit 61d2d1c665
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
3 changed files with 40 additions and 16 deletions

View file

@ -67,6 +67,7 @@ Item {
fillMode: VideoOutput.PreserveAspectFit fillMode: VideoOutput.PreserveAspectFit
source: mxcmedia source: mxcmedia
flushMode: VideoOutput.FirstFrame flushMode: VideoOutput.FirstFrame
orientation: mxcmedia.orientation
} }
} }

View file

@ -7,6 +7,7 @@
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QMediaMetaData>
#include <QMediaObject> #include <QMediaObject>
#include <QMediaPlayer> #include <QMediaPlayer>
#include <QMimeDatabase> #include <QMimeDatabase>
@ -23,6 +24,28 @@
#include "MatrixClient.h" #include "MatrixClient.h"
#include "timeline/TimelineModel.h" #include "timeline/TimelineModel.h"
MxcMediaProxy::MxcMediaProxy(QObject *parent)
: QMediaPlayer(parent)
{
connect(this, &MxcMediaProxy::eventIdChanged, &MxcMediaProxy::startDownload);
connect(this, &MxcMediaProxy::roomChanged, &MxcMediaProxy::startDownload);
connect(this,
qOverload<QMediaPlayer::Error>(&MxcMediaProxy::error),
[this](QMediaPlayer::Error error) {
nhlog::ui()->info("Media player error {} and errorStr {}",
error,
this->errorString().toStdString());
});
connect(this, &MxcMediaProxy::mediaStatusChanged, [this](QMediaPlayer::MediaStatus status) {
nhlog::ui()->info("Media player status {} and error {}", status, this->error());
});
connect(this,
qOverload<const QString &, const QVariant &>(&MxcMediaProxy::metaDataChanged),
[this](QString t, QVariant) {
if (t == QMediaMetaData::Orientation)
emit orientationChanged();
});
}
void void
MxcMediaProxy::setVideoSurface(QAbstractVideoSurface *surface) MxcMediaProxy::setVideoSurface(QAbstractVideoSurface *surface)
{ {
@ -37,6 +60,15 @@ MxcMediaProxy::getVideoSurface()
return m_surface; return m_surface;
} }
int
MxcMediaProxy::orientation() const
{
nhlog::ui()->debug("metadata: {}", availableMetaData().join(",").toStdString());
auto orientation = metaData(QMediaMetaData::Orientation).toInt();
nhlog::ui()->debug("Video orientation: {}", orientation);
return orientation;
}
void void
MxcMediaProxy::startDownload() MxcMediaProxy::startDownload()
{ {

View file

@ -25,23 +25,10 @@ class MxcMediaProxy : public QMediaPlayer
Q_PROPERTY(QString eventId READ eventId WRITE setEventId NOTIFY eventIdChanged) Q_PROPERTY(QString eventId READ eventId WRITE setEventId NOTIFY eventIdChanged)
Q_PROPERTY(QAbstractVideoSurface *videoSurface READ getVideoSurface WRITE setVideoSurface) Q_PROPERTY(QAbstractVideoSurface *videoSurface READ getVideoSurface WRITE setVideoSurface)
Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged) Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)
Q_PROPERTY(int orientation READ orientation NOTIFY orientationChanged)
public: public:
MxcMediaProxy(QObject *parent = nullptr) MxcMediaProxy(QObject *parent = nullptr);
: QMediaPlayer(parent)
{
connect(this, &MxcMediaProxy::eventIdChanged, &MxcMediaProxy::startDownload);
connect(this, &MxcMediaProxy::roomChanged, &MxcMediaProxy::startDownload);
connect(this,
qOverload<QMediaPlayer::Error>(&MxcMediaProxy::error),
[this](QMediaPlayer::Error error) {
nhlog::ui()->info("Media player error {} and errorStr {}",
error,
this->errorString().toStdString());
});
connect(this, &MxcMediaProxy::mediaStatusChanged, [this](QMediaPlayer::MediaStatus status) {
nhlog::ui()->info("Media player status {} and error {}", status, this->error());
});
}
bool loaded() const { return buffer.size() > 0; } bool loaded() const { return buffer.size() > 0; }
QString eventId() const { return eventId_; } QString eventId() const { return eventId_; }
@ -59,12 +46,16 @@ public:
void setVideoSurface(QAbstractVideoSurface *surface); void setVideoSurface(QAbstractVideoSurface *surface);
QAbstractVideoSurface *getVideoSurface(); QAbstractVideoSurface *getVideoSurface();
int orientation() const;
signals: signals:
void roomChanged(); void roomChanged();
void eventIdChanged(); void eventIdChanged();
void loadedChanged(); void loadedChanged();
void newBuffer(QMediaContent, QIODevice *buf); void newBuffer(QMediaContent, QIODevice *buf);
void orientationChanged();
private slots: private slots:
void startDownload(); void startDownload();