Created
May 14, 2019 14:03
-
-
Save towc/e8f2c71886faa1bac9913738e104f02e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "pipeline.h" | |
#include <QApplication> | |
#include <QQmlApplicationEngine> | |
#include <QQuickWindow> | |
#include <QQuickItem> | |
#include <QRunnable> | |
#include <gst/gst.h> | |
int main(int argc, char *argv[]) | |
{ | |
int ret; | |
gst_init (&argc, &argv); | |
{ | |
QGuiApplication app(argc, argv); | |
qmlRegisterType<QPipeline>("Pipeline", 1, 0, "Pipeline"); | |
QQmlApplicationEngine engine; | |
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); | |
ret = app.exec(); | |
} | |
gst_deinit (); | |
return ret; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "pipeline.h" | |
#include <QPainter> | |
QPipeline::QPipeline(QQuickItem *parent) | |
: QQuickPaintedItem(parent) | |
{ | |
} | |
QVariant QPipeline::video() const | |
{ | |
return m_video; | |
} | |
void QPipeline::setVideo(const QVariant &video) | |
{ | |
m_video = video; | |
if (m_pipe) { | |
linkPipeToVideo(); | |
} | |
} | |
QString QPipeline::pipe() const | |
{ | |
return m_pipe; | |
} | |
void QPipeline::setPipe(const QString &pipe) | |
{ | |
m_pipe = pipe; | |
pipeline = gst_parse_bin_from_description(pipe); | |
if (m_video) { | |
linkPipeToVideo(); | |
} | |
} | |
void QPipeline::linkPipeToVideo() | |
{ | |
GstElement *sink = gst_bin_get_by_name(m_pipe, "sink"); | |
QQuickItem *item = qvariant_cast<QQuickItem*>(m_video); | |
g_object_set(sink, "widget", item, NULL); | |
} | |
void QPipeline::play() | |
{ | |
gst_element_set_state (pipeline, GST_STATE_PLAYING); | |
emit playing(); | |
} | |
void QPipeline::pause() | |
{ | |
gst_element_set_state (pipeline, GST_STATE_PAUSED); | |
emit paused(); | |
} | |
void QPipeline::paint(QPainter *painter) | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QtQuick/QQuickPaintedItem> | |
#include <QColor> | |
#include <gst/gst.h> | |
class QPipeline : public QQuickPaintedItem | |
{ | |
Q_OBJECT | |
Q_PROPERTY(QVariant video READ video WRITE setVideo) | |
Q_PROPERTY(QString pipe READ pipe WRITE setPipe) | |
public: | |
QPipeline(QQuickItem *parent = 0); | |
QVariant video() const; | |
void setVideo(const QVariant &video); | |
QString pipe() const; | |
void setPipe(const QString &pipe); | |
void paint(QPainter *painter); | |
Q_INVOKABLE void pause(); | |
Q_INVOKABLE void play(); | |
signals: | |
void playing(); | |
void paused(); | |
private: | |
QVariant m_video; | |
QString m_pipe; | |
GstElement pipeline; | |
void linkPipeToVideo(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment