File indexing completed on 2025-01-05 03:53:05

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2021-07-24
0007  * Description : a MJPEG Stream server to export items on the network.
0008  *
0009  * SPDX-FileCopyrightText: 2021-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_MJPEG_SERVER_H
0016 #define DIGIKAM_MJPEG_SERVER_H
0017 
0018 // Qt includes
0019 
0020 #include <QDebug>
0021 #include <QImage>
0022 #include <QObject>
0023 
0024 namespace DigikamGenericMjpegStreamPlugin
0025 {
0026 
0027 /// A kind of map of albums with urls contents to share with MJPEG server.
0028 typedef QMap<QString, QList<QUrl> > MjpegServerMap;
0029 
0030 class MjpegServer : public QObject
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035 
0036     /**
0037      * Create an instance of MJPEG server listening on 'address'
0038      * and 'port'. Default address is 'any' (an empty string), as server listen on all
0039      * network interfaces. You can pass a literal address as "localhost"
0040      * or an IPV4 based one as "192.168.1.1".
0041      */
0042     explicit MjpegServer(const QString& address = QString(),
0043                          int port = 8080,
0044                          QObject* const parent = nullptr);
0045     ~MjpegServer();
0046 
0047 public:
0048 
0049     /**
0050      * Handle rate of frame per seconds dispatched to the network [1 - 30].
0051      * A low value reduce network bandwidth use.
0052      * Default = 15 img/s.
0053      */
0054     bool setRate(int);
0055     int  rate() const;
0056 
0057     /**
0058      * Limit the number of clients connected to the server [1 - 30].
0059      * Default = 10 clients.
0060      */
0061     bool setMaxClients(int);
0062     int  maxClients() const;
0063 
0064     /**
0065      * Handle the list of clients IP address to ban from the stream server.
0066      */
0067     void setBlackList(const QStringList& lst);
0068     QStringList blackList() const;
0069 
0070     /**
0071      * Start and stop the server to listen on the network.
0072      * for a new client connection.
0073      */
0074     void start();
0075     void stop();
0076 
0077 public Q_SLOTS:
0078 
0079     /**
0080      * Slot to push an update of JPEG frame to
0081      * the remote client connected on server.
0082      * Use a direct signal/slot connection to optimize
0083      * time latency.
0084      */
0085     void slotWriteFrame(const QByteArray& frame);
0086 
0087 private:
0088 
0089     class Private;
0090     Private* const d;
0091 };
0092 
0093 } // namespace DigikamGenericMjpegStreamPlugin
0094 
0095 #endif // DIGIKAM_MJPEG_SERVER_H