summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-11-15 03:35:35 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2021-11-15 03:36:30 +0100
commit61d2d1c665d3d21dcea83363c8229f220b56f4dd (patch)
tree078bf6969fd92de0ed0f1809a650449737d0e75b
parentTranslated using Weblate (Indonesian) (diff)
downloadnheko-61d2d1c665d3d21dcea83363c8229f220b56f4dd.tar.xz
Support exif rotation on received videos
fixes #674
-rw-r--r--resources/qml/delegates/PlayableMediaMessage.qml1
-rw-r--r--src/ui/MxcMediaProxy.cpp32
-rw-r--r--src/ui/MxcMediaProxy.h23
3 files changed, 40 insertions, 16 deletions
diff --git a/resources/qml/delegates/PlayableMediaMessage.qml b/resources/qml/delegates/PlayableMediaMessage.qml
index c738e5b4..351313fe 100644
--- a/resources/qml/delegates/PlayableMediaMessage.qml
+++ b/resources/qml/delegates/PlayableMediaMessage.qml
@@ -67,6 +67,7 @@ Item {
                 fillMode: VideoOutput.PreserveAspectFit
                 source: mxcmedia
                 flushMode: VideoOutput.FirstFrame
+                orientation: mxcmedia.orientation
             }
 
         }
diff --git a/src/ui/MxcMediaProxy.cpp b/src/ui/MxcMediaProxy.cpp
index df0298da..a93d0fc0 100644
--- a/src/ui/MxcMediaProxy.cpp
+++ b/src/ui/MxcMediaProxy.cpp
@@ -7,6 +7,7 @@
 #include <QDir>
 #include <QFile>
 #include <QFileInfo>
+#include <QMediaMetaData>
 #include <QMediaObject>
 #include <QMediaPlayer>
 #include <QMimeDatabase>
@@ -23,6 +24,28 @@
 #include "MatrixClient.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
 MxcMediaProxy::setVideoSurface(QAbstractVideoSurface *surface)
 {
@@ -37,6 +60,15 @@ MxcMediaProxy::getVideoSurface()
     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
 MxcMediaProxy::startDownload()
 {
diff --git a/src/ui/MxcMediaProxy.h b/src/ui/MxcMediaProxy.h
index 18152c75..e33fc105 100644
--- a/src/ui/MxcMediaProxy.h
+++ b/src/ui/MxcMediaProxy.h
@@ -25,23 +25,10 @@ class MxcMediaProxy : public QMediaPlayer
     Q_PROPERTY(QString eventId READ eventId WRITE setEventId NOTIFY eventIdChanged)
     Q_PROPERTY(QAbstractVideoSurface *videoSurface READ getVideoSurface WRITE setVideoSurface)
     Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)
+    Q_PROPERTY(int orientation READ orientation NOTIFY orientationChanged)
+
 public:
-    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());
-        });
-    }
+    MxcMediaProxy(QObject *parent = nullptr);
 
     bool loaded() const { return buffer.size() > 0; }
     QString eventId() const { return eventId_; }
@@ -59,12 +46,16 @@ public:
     void setVideoSurface(QAbstractVideoSurface *surface);
     QAbstractVideoSurface *getVideoSurface();
 
+    int orientation() const;
+
 signals:
     void roomChanged();
     void eventIdChanged();
     void loadedChanged();
     void newBuffer(QMediaContent, QIODevice *buf);
 
+    void orientationChanged();
+
 private slots:
     void startDownload();