2018-11-26 18:41:18 +00:00
|
|
|
#ifndef MpvPlayerBackend_H
|
|
|
|
#define MpvPlayerBackend_H
|
|
|
|
|
2018-11-26 19:03:37 +00:00
|
|
|
#include <mpv/client.h>
|
|
|
|
#include <mpv/qthelper.hpp>
|
2018-11-26 16:50:25 +00:00
|
|
|
|
2018-11-06 07:39:42 +00:00
|
|
|
#include <mpv/render_gl.h>
|
2018-10-13 15:38:31 +01:00
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QOpenGLContext>
|
|
|
|
#include <QQuickFramebufferObject>
|
|
|
|
|
2018-11-18 19:23:31 +00:00
|
|
|
#include "backendinterface.hpp"
|
2018-11-17 15:45:21 +00:00
|
|
|
#include "enums.hpp"
|
2018-11-26 16:50:25 +00:00
|
|
|
#include "utils.hpp"
|
2018-11-17 15:45:21 +00:00
|
|
|
|
2018-10-13 15:38:31 +01:00
|
|
|
class MpvRenderer;
|
|
|
|
|
2018-11-18 19:23:31 +00:00
|
|
|
class MpvPlayerBackend
|
|
|
|
: public QQuickFramebufferObject
|
|
|
|
, public BackendInterface
|
2018-10-13 15:38:31 +01:00
|
|
|
{
|
2018-11-18 19:23:31 +00:00
|
|
|
Q_INTERFACES(BackendInterface)
|
|
|
|
|
2018-11-06 07:39:42 +00:00
|
|
|
Q_OBJECT
|
2018-11-18 19:23:31 +00:00
|
|
|
|
2018-11-06 07:39:42 +00:00
|
|
|
mpv_handle* mpv;
|
|
|
|
mpv_render_context* mpv_gl;
|
2018-11-07 11:10:38 +00:00
|
|
|
bool onTop = false;
|
2018-11-19 05:07:22 +00:00
|
|
|
QString totalDurationString;
|
2018-10-13 15:38:31 +01:00
|
|
|
|
2018-11-06 07:39:42 +00:00
|
|
|
friend class MpvRenderer;
|
2018-10-13 15:38:31 +01:00
|
|
|
|
|
|
|
public:
|
2018-11-06 07:39:42 +00:00
|
|
|
static void on_update(void* ctx);
|
2018-10-13 15:38:31 +01:00
|
|
|
|
2018-11-06 07:39:42 +00:00
|
|
|
MpvPlayerBackend(QQuickItem* parent = 0);
|
|
|
|
virtual ~MpvPlayerBackend();
|
|
|
|
virtual Renderer* createRenderer() const;
|
2018-10-13 15:38:31 +01:00
|
|
|
|
|
|
|
public slots:
|
2018-11-17 19:33:32 +00:00
|
|
|
QVariant playerCommand(const Enums::Commands& command, const QVariant& args);
|
|
|
|
QVariant playerCommand(const Enums::Commands& command);
|
2018-11-06 07:39:42 +00:00
|
|
|
void launchAboutQt();
|
2018-11-07 11:10:38 +00:00
|
|
|
void toggleOnTop();
|
2018-11-18 12:48:41 +00:00
|
|
|
void updateAppImage();
|
2018-11-17 19:33:32 +00:00
|
|
|
// Optional but handy for MPV or custom backend settings.
|
2018-11-06 07:39:42 +00:00
|
|
|
void command(const QVariant& params);
|
|
|
|
void setProperty(const QString& name, const QVariant& value);
|
|
|
|
void setOption(const QString& name, const QVariant& value);
|
|
|
|
QVariant getProperty(const QString& name) const;
|
2018-11-24 14:35:34 +00:00
|
|
|
// Just used for adding missing audio devices to list.
|
|
|
|
QVariantMap getAudioDevices() const;
|
2018-11-24 21:00:04 +00:00
|
|
|
bool event(QEvent* event);
|
2018-10-13 15:38:31 +01:00
|
|
|
|
|
|
|
signals:
|
2018-11-06 07:39:42 +00:00
|
|
|
void onUpdate();
|
|
|
|
void mpv_events();
|
2018-11-24 21:00:04 +00:00
|
|
|
void onMpvEvent(mpv_event* event);
|
|
|
|
|
2018-11-17 19:33:32 +00:00
|
|
|
// All below required for Player API
|
2018-11-17 15:45:21 +00:00
|
|
|
void playStatusChanged(const Enums::PlayStatus& status);
|
|
|
|
void volumeStatusChanged(const Enums::VolumeStatus& status);
|
|
|
|
void volumeChanged(const int& volume);
|
|
|
|
void durationChanged(const double& duration);
|
|
|
|
void positionChanged(const double& position);
|
|
|
|
void cachedDurationChanged(const double& duration);
|
|
|
|
void playlistPositionChanged(const double& position);
|
|
|
|
void titleChanged(const QString& title);
|
|
|
|
void subtitlesChanged(const QString& subtitles);
|
|
|
|
void durationStringChanged(const QString& string);
|
2018-11-24 14:35:34 +00:00
|
|
|
void tracksChanged(const QVariantList& tracks);
|
|
|
|
void audioDevicesChanged(const QVariantMap& devices);
|
|
|
|
void playlistChanged(const QVariantList& devices);
|
|
|
|
void chaptersChanged(const QVariantList& devices);
|
2018-11-22 20:59:01 +00:00
|
|
|
|
2018-10-13 15:38:31 +01:00
|
|
|
private slots:
|
2018-11-06 07:39:42 +00:00
|
|
|
void doUpdate();
|
|
|
|
void on_mpv_events();
|
2018-11-17 15:45:21 +00:00
|
|
|
void updateDurationString();
|
2018-10-13 15:38:31 +01:00
|
|
|
|
|
|
|
private:
|
2018-11-06 07:39:42 +00:00
|
|
|
void handle_mpv_event(mpv_event* event);
|
2018-11-17 19:33:32 +00:00
|
|
|
#ifdef DISCORD
|
|
|
|
void updateDiscord();
|
|
|
|
#endif
|
2018-10-13 15:38:31 +01:00
|
|
|
};
|
|
|
|
|
2018-10-21 13:00:25 +01:00
|
|
|
#endif
|