mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-30 04:45:36 +00:00
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:
parent
ddb40e9e39
commit
2b3fc175c2
16 changed files with 133 additions and 27 deletions
39
playback/player/qt/extension/extension.pro
Normal file
39
playback/player/qt/extension/extension.pro
Normal 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
|
||||
}
|
|
@ -35,7 +35,9 @@ Player::Player(QObject *parent, QuickRenderer *renderer)
|
|||
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);
|
||||
}
|
|
@ -32,10 +32,13 @@ class Player : public QGstPlayer::Player
|
|||
Q_OBJECT
|
||||
public:
|
||||
Player(QObject *parent = 0);
|
||||
void setVideoOutput(QQuickItem *output);
|
||||
Q_PROPERTY(QVariant videoOutput WRITE setVideoOutput)
|
||||
|
||||
private:
|
||||
Player(QObject *parent, QuickRenderer *renderer);
|
||||
|
||||
void setVideoOutput(QVariant output);
|
||||
|
||||
QuickRenderer *renderer_;
|
||||
};
|
||||
|
2
playback/player/qt/extension/qmldir
Normal file
2
playback/player/qt/extension/qmldir
Normal file
|
@ -0,0 +1,2 @@
|
|||
module extension
|
||||
plugin qmlplayerextension
|
33
playback/player/qt/extension/qplayerextension.cpp
Normal file
33
playback/player/qt/extension/qplayerextension.cpp
Normal 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");
|
||||
}
|
30
playback/player/qt/extension/qplayerextension.h
Normal file
30
playback/player/qt/extension/qplayerextension.h
Normal 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;
|
||||
};
|
|
@ -20,12 +20,12 @@
|
|||
|
||||
#include <QApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlProperty>
|
||||
#include <QQuickItem>
|
||||
#include <QCommandLineParser>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
|
||||
#include "player.h"
|
||||
#include "imagesample.h"
|
||||
#include <gst/gst.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -48,9 +48,6 @@ int main(int argc, char *argv[])
|
|||
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
|
||||
* GstGLVideoItem qml item
|
||||
* FIXME Add a QQmlExtensionPlugin into qmlglsink to register GstGLVideoItem
|
||||
|
@ -65,13 +62,17 @@ int main(int argc, char *argv[])
|
|||
|
||||
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");
|
||||
player->setVideoOutput(videoItem);
|
||||
|
||||
if (!media_files.isEmpty())
|
||||
player->setPlaylist(media_files);
|
||||
if (!media_files.isEmpty()) {
|
||||
QVariant v;
|
||||
v.setValue<QList<QUrl>>(media_files);
|
||||
QQmlProperty(player, "playlist").write(QVariant (v));
|
||||
}
|
||||
|
||||
result = app.exec();
|
||||
|
||||
|
|
|
@ -23,9 +23,8 @@ import QtQuick.Controls 1.1
|
|||
import QtQuick.Controls.Styles 1.3
|
||||
import QtQuick.Dialogs 1.2
|
||||
import QtQuick.Window 2.1
|
||||
import Player 1.0
|
||||
import extension 1.0
|
||||
import org.freedesktop.gstreamer.GLVideoItem 1.0
|
||||
import ImageSample 1.0
|
||||
|
||||
import "fontawesome.js" as FontAwesome
|
||||
|
||||
|
|
|
@ -33,16 +33,8 @@ macx {
|
|||
-F/Library/Frameworks -framework GStreamer
|
||||
}
|
||||
|
||||
HEADERS += \
|
||||
qgstplayer.h \
|
||||
player.h \
|
||||
quickrenderer.h \
|
||||
imagesample.h
|
||||
HEADERS +=
|
||||
|
||||
SOURCES += main.cpp \
|
||||
qgstplayer.cpp \
|
||||
player.cpp \
|
||||
quickrenderer.cpp \
|
||||
imagesample.cpp
|
||||
SOURCES += main.cpp
|
||||
|
||||
DISTFILES +=
|
||||
|
|
5
playback/player/qt/qt.pro
Normal file
5
playback/player/qt/qt.pro
Normal file
|
@ -0,0 +1,5 @@
|
|||
TEMPLATE = subdirs
|
||||
SUBDIRS = extension play
|
||||
|
||||
play.depends = extension
|
||||
play.file = play.pro
|
Loading…
Reference in a new issue