-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathmjpegstreamerclient.h
149 lines (125 loc) · 3.77 KB
/
mjpegstreamerclient.h
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/****************************************************************************
**
** Copyright (C) 2014 Alexander Rössler
** License: LGPL version 2.1
**
** This file is part of QtQuickVcp.
**
** All rights reserved. This program and the accompanying materials
** are made available under the terms of the GNU Lesser General Public License
** (LGPL) version 2.1 which accompanies this distribution, and is available at
** http://www.gnu.org/licenses/lgpl-2.1.html
**
** 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
** Lesser General Public License for more details.
**
** Contributors:
** Alexander Rössler @ The Cool Tool GmbH <mail DOT aroessler AT gmail DOT com>
**
****************************************************************************/
#ifndef MJPEGSTREAMER2_H
#define MJPEGSTREAMER2_H
#include <QQuickPaintedItem>
#include <QTime>
#include <QQueue>
#include <QImage>
#include <nzmqt/nzmqt.hpp>
#include "package.pb.h"
namespace qtquickvcp {
class MjpegStreamerClient : public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY(QString videoUri READ videoUri WRITE setVideoUri NOTIFY videoUriChanged)
Q_PROPERTY(int fps READ fps NOTIFY fpsChanged)
Q_PROPERTY(bool ready READ isReady WRITE setReady NOTIFY readyChanged)
Q_PROPERTY(double timestamp READ timestamp NOTIFY timestampChanged)
Q_PROPERTY(QTime time READ time NOTIFY timeChanged)
Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode NOTIFY aspectRatioModeChanged)
public:
typedef struct {
QImage image;
double timestamp;
QTime time;
} StreamBufferItem;
explicit MjpegStreamerClient(QQuickPaintedItem *parent = 0);
~MjpegStreamerClient();
virtual void componentComplete();
void paint(QPainter* painter);
QString videoUri() const
{
return m_videoUri;
}
bool isReady() const
{
return m_running;
}
int fps() const
{
return m_fps;
}
double timestamp() const
{
return m_timestamp;
}
QTime time() const
{
return m_time;
}
Qt::AspectRatioMode aspectRatioMode() const
{
return m_aspectRatioMode;
}
signals:
void videoUriChanged(QString arg);
void readyChanged(bool arg);
void fpsChanged(double arg);
void timestampChanged(double arg);
void timeChanged(QTime arg);
void aspectRatioModeChanged(Qt::AspectRatioMode arg);
public slots:
void setVideoUri(QString arg)
{
if (m_videoUri != arg) {
m_videoUri = arg;
emit videoUriChanged(arg);
}
}
void setReady(bool arg);
void setAspectRatioMode(Qt::AspectRatioMode arg)
{
if (m_aspectRatioMode == arg)
return;
m_aspectRatioMode = arg;
emit aspectRatioModeChanged(arg);
}
private:
bool m_componentCompleted;
StreamBufferItem m_currentStreamBufferItem;
QQueue<StreamBufferItem> m_streamBuffer;
QImage m_frameImg;
QTimer *m_framerateTimer;
QTimer *m_streamBufferTimer;
nzmqt::ZMQContext *m_context;
nzmqt::ZMQSocket *m_updateSocket;
pb::Package m_rx; // more efficient to reuse a protobuf Message
QString m_videoUri;
bool m_running;
int m_fps;
int m_frameCount;
double m_timestamp;
QTime m_time;
Qt::AspectRatioMode m_aspectRatioMode;
private slots:
void start();
void stop();
void connectSocket();
void disconnectSocket();
void updateMessageReceived(const QList<QByteArray> &messageList);
void updateFramerate();
void updateStreamBuffer();
void updateStreamBufferItem();
}; // class MjpegStreamerClient
} // namespace qtquickvcp
#endif // MJPEGSTREAMER2_H