player/qt: move player api wrapper into a qml extension library

A further step is moving the qmlglsink element into an extension so
there is no need for writing any c++ code!
This commit is contained in:
Matthew Waters 2018-12-12 13:56:07 +11:00
parent ddb40e9e39
commit 2b3fc175c2
16 changed files with 133 additions and 27 deletions

View file

@ -0,0 +1,39 @@
TEMPLATE = lib
CONFIG += qt plugin
QT += qml quick
CONFIG += c++11
DEFINES += GST_USE_UNSTABLE_API
TARGET = qmlplayerextension
# Additional import path used to resolve QML modules in Qt Creator's code model
# QML_IMPORT_PATH =
HEADERS += qplayerextension.h \
qgstplayer.h \
player.h \
quickrenderer.h \
imagesample.h
SOURCES += qplayerextension.cpp \
qgstplayer.cpp \
player.cpp \
quickrenderer.cpp \
imagesample.cpp
unix:!macx {
QT_CONFIG -= no-pkg-config
CONFIG += link_pkgconfig
PKGCONFIG = \
gstreamer-1.0 \
gstreamer-player-1.0 \
gstreamer-tag-1.0
}
macx {
QMAKE_MAC_SDK = macosx10.9
INCLUDEPATH += /Library/Frameworks/GStreamer.framework/Headers
LIBS += \
-framework AppKit \
-F/Library/Frameworks -framework GStreamer
}

View file

@ -35,7 +35,9 @@ Player::Player(QObject *parent, QuickRenderer *renderer)
renderer_->setParent(this); renderer_->setParent(this);
} }
void Player::setVideoOutput(QQuickItem *output) void Player::setVideoOutput(QVariant output)
{ {
renderer_->setVideoItem(output); QQuickItem *item = qvariant_cast<QQuickItem*>(output);
renderer_->setVideoItem(item);
} }

View file

@ -32,10 +32,13 @@ class Player : public QGstPlayer::Player
Q_OBJECT Q_OBJECT
public: public:
Player(QObject *parent = 0); Player(QObject *parent = 0);
void setVideoOutput(QQuickItem *output); Q_PROPERTY(QVariant videoOutput WRITE setVideoOutput)
private: private:
Player(QObject *parent, QuickRenderer *renderer); Player(QObject *parent, QuickRenderer *renderer);
void setVideoOutput(QVariant output);
QuickRenderer *renderer_; QuickRenderer *renderer_;
}; };

View file

@ -0,0 +1,2 @@
module extension
plugin qmlplayerextension

View file

@ -0,0 +1,33 @@
/* GStreamer
*
* Copyright (C) 2018 Matthew Waters <matthew@cenricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "qplayerextension.h"
#include "qgstplayer.h"
#include "imagesample.h"
#include <iostream>
void QGstPlayerPlayerExtension::registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("extension"));
std::cout << "register uri: " << uri << std::endl;
qmlRegisterType<Player>(uri, 1, 0, "Player");
qmlRegisterType<ImageSample>("extension", 1, 0, "ImageSample");
}

View file

@ -0,0 +1,30 @@
/* GStreamer
*
* Copyright (C) 2018 Matthew Waters <matthew@cenricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <QQmlExtensionPlugin>
class QGstPlayerPlayerExtension : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
public:
void registerTypes(const char *uri) override;
};

View file

@ -20,12 +20,12 @@
#include <QApplication> #include <QApplication>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <QQmlProperty>
#include <QQuickItem>
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QStringList> #include <QStringList>
#include <QUrl> #include <QUrl>
#include <gst/gst.h>
#include "player.h"
#include "imagesample.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -48,9 +48,6 @@ int main(int argc, char *argv[])
media_files << QUrl::fromUserInput(file); media_files << QUrl::fromUserInput(file);
} }
qmlRegisterType<Player>("Player", 1, 0, "Player");
qmlRegisterType<ImageSample>("ImageSample", 1, 0, "ImageSample");
/* the plugin must be loaded before loading the qml file to register the /* the plugin must be loaded before loading the qml file to register the
* GstGLVideoItem qml item * GstGLVideoItem qml item
* FIXME Add a QQmlExtensionPlugin into qmlglsink to register GstGLVideoItem * FIXME Add a QQmlExtensionPlugin into qmlglsink to register GstGLVideoItem
@ -65,13 +62,17 @@ int main(int argc, char *argv[])
QObject *rootObject = engine.rootObjects().first(); QObject *rootObject = engine.rootObjects().first();
Player *player = rootObject->findChild<Player*>("player"); QObject *player = rootObject->findChild<QObject*>("player");
QObject *videoItem = rootObject->findChild<QObject*>("videoItem");
QVariant v;
v.setValue<QObject*>(videoItem);
QQmlProperty(player, "videoOutput").write(v);
QQuickItem *videoItem = rootObject->findChild<QQuickItem*>("videoItem"); if (!media_files.isEmpty()) {
player->setVideoOutput(videoItem); QVariant v;
v.setValue<QList<QUrl>>(media_files);
if (!media_files.isEmpty()) QQmlProperty(player, "playlist").write(QVariant (v));
player->setPlaylist(media_files); }
result = app.exec(); result = app.exec();

View file

@ -23,9 +23,8 @@ import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.3 import QtQuick.Controls.Styles 1.3
import QtQuick.Dialogs 1.2 import QtQuick.Dialogs 1.2
import QtQuick.Window 2.1 import QtQuick.Window 2.1
import Player 1.0 import extension 1.0
import org.freedesktop.gstreamer.GLVideoItem 1.0 import org.freedesktop.gstreamer.GLVideoItem 1.0
import ImageSample 1.0
import "fontawesome.js" as FontAwesome import "fontawesome.js" as FontAwesome

View file

@ -33,16 +33,8 @@ macx {
-F/Library/Frameworks -framework GStreamer -F/Library/Frameworks -framework GStreamer
} }
HEADERS += \ HEADERS +=
qgstplayer.h \
player.h \
quickrenderer.h \
imagesample.h
SOURCES += main.cpp \ SOURCES += main.cpp
qgstplayer.cpp \
player.cpp \
quickrenderer.cpp \
imagesample.cpp
DISTFILES += DISTFILES +=

View file

@ -0,0 +1,5 @@
TEMPLATE = subdirs
SUBDIRS = extension play
play.depends = extension
play.file = play.pro