2018-12-20 14:37:29 +00:00
|
|
|
#ifndef MPVBackend_H
|
|
|
|
#define MPVBackend_H
|
2018-11-26 18:41:18 +00:00
|
|
|
|
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-12-03 08:17:57 +00:00
|
|
|
#include <QSettings>
|
2018-10-13 15:38:31 +01:00
|
|
|
|
2018-12-20 14:37:29 +00:00
|
|
|
#include "src/backendinterface.hpp"
|
|
|
|
#include "src/enums.hpp"
|
|
|
|
#include "src/utils.hpp"
|
2018-11-17 15:45:21 +00:00
|
|
|
|
2018-10-13 15:38:31 +01:00
|
|
|
class MpvRenderer;
|
|
|
|
|
2018-12-20 14:37:29 +00:00
|
|
|
class MPVBackend
|
2018-11-18 19:23:31 +00:00
|
|
|
: 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-12-12 08:28:53 +00:00
|
|
|
Q_PROPERTY(bool logging READ logging WRITE setLogging)
|
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-12-03 08:17:57 +00:00
|
|
|
QSettings settings;
|
2018-11-07 11:10:38 +00:00
|
|
|
bool onTop = false;
|
2018-12-12 08:28:53 +00:00
|
|
|
bool m_logging = true;
|
|
|
|
|
2018-11-30 08:21:34 +00:00
|
|
|
int lastTime = 0;
|
|
|
|
double lastSpeed = 0;
|
2018-11-19 05:07:22 +00:00
|
|
|
QString totalDurationString;
|
2018-11-30 08:21:34 +00:00
|
|
|
QString lastPositionString;
|
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-12-20 14:37:29 +00:00
|
|
|
MPVBackend(QQuickItem* parent = 0);
|
|
|
|
virtual ~MPVBackend();
|
2018-11-06 07:39:42 +00:00
|
|
|
virtual Renderer* createRenderer() const;
|
2018-10-13 15:38:31 +01:00
|
|
|
|
2018-12-12 08:28:53 +00:00
|
|
|
void setLogging(bool a)
|
|
|
|
{
|
|
|
|
if (a != m_logging) {
|
|
|
|
m_logging = a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool logging() const { return m_logging; }
|
|
|
|
|
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-07 11:10:38 +00:00
|
|
|
void toggleOnTop();
|
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.
|
2018-12-03 08:17:57 +00:00
|
|
|
QVariantMap getAudioDevices(const QVariant& drivers) 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-12-03 08:17:57 +00:00
|
|
|
void speedChanged(const double& speed);
|
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-30 08:21:34 +00:00
|
|
|
void updateDurationString(int numTime);
|
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-10-13 15:38:31 +01:00
|
|
|
};
|
|
|
|
|
2018-10-21 13:00:25 +01:00
|
|
|
#endif
|