digiKam
mjpegserver_p.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2021-07-24
7  * Description : a MJPEG Stream server to export items on the network.
8  *
9  * Copyright (C) 2021-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * ============================================================ */
22 
23 #ifndef DIGIKAM_MJPEG_SERVER_P_H
24 #define DIGIKAM_MJPEG_SERVER_P_H
25 
26 // Qt includes
27 
28 #include <QList>
29 #include <QStringList>
30 #include <QFuture>
31 #include <QMutex>
32 #include <QTcpSocket>
33 #include <QTcpServer>
34 #include <QByteArray>
35 
36 // Local includes
37 
38 #include "mjpegserver.h"
39 #include "digikam_debug.h"
40 
42 {
43 
48 class Q_DECL_HIDDEN MjpegServer::Private : public QObject
49 {
50  Q_OBJECT
51 
52 public:
53 
54  explicit Private(QObject* const parent);
55  ~Private();
56 
60  void setMaxClients(int);
61  int maxClients() const;
62 
68  int writeInSocket(int sock, const QByteArray& data) const;
69 
73  QString clientDescription(QTcpSocket* const client) const;
74 
78  bool isOpened() const;
79 
83  bool open(const QString& address, int port);
84 
88  void start();
89 
93  void stop();
94 
98  void close();
99 
100 public:
101 
102  QTcpServer* server;
103  int rate;
104  int delay;
106  QByteArray lastFrame;
107  QFuture<void> srvTask;
108  QMutex mutexClients;
109  QMutex mutexFrame;
110  QStringList blackList;
111 
112 private Q_SLOTS:
113 
117  void slotNewConnection();
118 
122  void slotClientDisconnected();
123 
124 private:
125 
129  void writerThread();
130 
136  void clientWriteMultithreaded(int client, const QByteArray& data);
137 };
138 
139 } // namespace DigikamGenericMjpegStreamPlugin
140 
141 #endif // DIGIKAM_MJPEG_SERVER_P_H
QStringList blackList
Clients Ip address list to ban.
Definition: mjpegserver_p.h:110
QByteArray lastFrame
the current JPEG frame to dispatch to all connected clients.
Definition: mjpegserver_p.h:106
QFuture< void > srvTask
server threaded task used to stream on clients.
Definition: mjpegserver_p.h:107
QMutex mutexFrame
to protect current frame data.
Definition: mjpegserver_p.h:109
QList< QTcpSocket * > clients
list of client connected sockets.
Definition: mjpegserver_p.h:105
QMutex mutexClients
to protect current clients list.
Definition: mjpegserver_p.h:108
int rate
stream frames rate per secs [1...30].
Definition: mjpegserver_p.h:103
QTcpServer * server
main tcp/ip server.
Definition: mjpegserver_p.h:102
int delay
delay between frames in us (1E6/rate).
Definition: mjpegserver_p.h:104
Definition: mjpegframeosd.cpp:45