From 09c041c8ac40d2d3608c7224614fde69e1e4f08b Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 28 Aug 2021 00:38:33 +0200 Subject: Use in memory media player instead of storing unencrypted files on disk --- src/ui/MxcMediaProxy.h | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/ui/MxcMediaProxy.h (limited to 'src/ui/MxcMediaProxy.h') diff --git a/src/ui/MxcMediaProxy.h b/src/ui/MxcMediaProxy.h new file mode 100644 index 00000000..14541815 --- /dev/null +++ b/src/ui/MxcMediaProxy.h @@ -0,0 +1,80 @@ +// SPDX-FileCopyrightText: 2021 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include "Logging.h" + +class TimelineModel; + +// I failed to get my own buffer into the MediaPlayer in qml, so just make our own. For that we just +// need the videoSurface property, so that part is really easy! +class MxcMediaProxy : public QMediaPlayer +{ + Q_OBJECT + Q_PROPERTY(TimelineModel *roomm READ room WRITE setRoom NOTIFY roomChanged REQUIRED) + 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) +public: + MxcMediaProxy(QObject *parent = nullptr) + : QMediaPlayer(parent) + { + connect(this, &MxcMediaProxy::eventIdChanged, &MxcMediaProxy::startDownload); + connect(this, &MxcMediaProxy::roomChanged, &MxcMediaProxy::startDownload); + connect(this, + qOverload(&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; } + QString eventId() const { return eventId_; } + TimelineModel *room() const { return room_; } + void setEventId(QString newEventId) + { + eventId_ = newEventId; + emit eventIdChanged(); + } + void setRoom(TimelineModel *room) + { + room_ = room; + emit roomChanged(); + } + void setVideoSurface(QAbstractVideoSurface *surface); + QAbstractVideoSurface *getVideoSurface(); + +signals: + void roomChanged(); + void eventIdChanged(); + void loadedChanged(); + void newBuffer(QMediaContent, QIODevice *buf); + +private slots: + void startDownload(); + +private: + TimelineModel *room_ = nullptr; + QString eventId_; + QString filename_; + QBuffer buffer; + QAbstractVideoSurface *m_surface = nullptr; +}; -- cgit 1.5.1