-
Notifications
You must be signed in to change notification settings - Fork 0
/
videoqml.cpp
107 lines (96 loc) · 2.24 KB
/
videoqml.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "videoqml.h"
#include <gst/app/gstappsink.h>
#include <clutter-gst-3.0/clutter-gst/clutter-gst.h>
#include <QGst/Init>
#include <QGst/Pipeline>
#include <QGst/Utils/ApplicationSink>
#include <QQmlApplicationEngine>
#include <QGst/Message>
#include <QGst/Query>
#include <QGst/Event>
#include <QGst/Bus>
#include <QGlib/Connect>
VideoQML::VideoQML(QWidget *parent):
QObject(parent)
{
if(mPipeline)
{
mPipeline->setState(QGst::StateNull);
}
}
VideoQML::~VideoQML()
{
}
void VideoQML::setFileName(const QString &fileName)
{
if (!mPipeline)
{
mPipeline = QGst::ElementFactory::make("playbin").dynamicCast<QGst::Pipeline>();
if (mPipeline)
{
QGst::ElementPtr src = QGst::ElementFactory::make("videotestsrc");
QGst::ElementPtr appsink = QGst::ElementFactory::make("appsink", "appsink");//приемник
mPipeline->setProperty("video-sink", mVideoSink);
mPipeline->add(src);
mPipeline->add(appsink);
src->link(appsink);
QGst::BusPtr bus = mPipeline->bus();
bus->addSignalWatch();
QGlib::connect(bus, "message", this, &VideoQML::onBusMessage);
}
else
{
qCritical() << "Failed to create the pipeline";
}
}
if (mPipeline)
{
mPipeline->setProperty("uri", fileName);
}
play();
}
void VideoQML::setVideoSink(const QGst::ElementPtr &sink)
{
mVideoSink = sink;
}
QGst::State VideoQML::state() const
{
return mPipeline ? mPipeline->currentState() : QGst::StateNull;
}
void VideoQML::play()
{
if(mPipeline)
{
mPipeline->setState(QGst::StatePlaying);
}
}
void VideoQML::pause()
{
if (mPipeline)
{
mPipeline->setState(QGst::StatePaused);
}
}
void VideoQML::stop()
{
if (mPipeline)
{
mPipeline->setState(QGst::StateNull);
Q_EMIT stateChanged();
}
}
void VideoQML::onBusMessage(const QGst::MessagePtr &message)
{
switch (message->type())
{
case QGst::MessageEos:
stop();
break;
case QGst::MessageError:
qCritical() << message.staticCast<QGst::ErrorMessage>()->error();
stop();
break;
default:
break;
}
}