Kstars

media.h
1 /*
2  SPDX-FileCopyrightText: 2018 Jasem Mutlaq <[email protected]>
3 
4  Media Channel
5 
6  SPDX-License-Identifier: GPL-2.0-or-later
7 */
8 
9 #pragma once
10 
11 #include <QtWebSockets/QWebSocket>
12 #include <memory>
13 
14 #include "ekos/ekos.h"
15 #include "ekos/manager.h"
16 
17 class FITSView;
18 
19 namespace EkosLive
20 {
21 class Media : public QObject
22 {
23  Q_OBJECT
24 
25  public:
26  explicit Media(Ekos::Manager * manager);
27  virtual ~Media() = default;
28 
29  void sendResponse(const QString &command, const QJsonObject &payload);
30  void sendResponse(const QString &command, const QJsonArray &payload);
31 
32  void setAuthResponse(const QJsonObject &response)
33  {
34  m_AuthResponse = response;
35  }
36  void setURL(const QUrl &url)
37  {
38  m_URL = url;
39  }
40 
41  void registerCameras();
42 
43  // Ekos Media Message to User
44  void sendFile(const QString &filename, const QString &uuid);
45  void sendData(const QSharedPointer<FITSData> &data, const QString &uuid);
46  void sendView(const QSharedPointer<FITSView> &view, const QString &uuid);
47  void sendUpdatedFrame(const QSharedPointer<FITSView> &view);
48  void sendModuleFrame(const QSharedPointer<FITSView> &view);
49 
50  signals:
51  void connected();
52  void disconnected();
53 
54  void newBoundingRect(QRect rect, QSize view, double currentZoom);
55  void newMetadata(const QByteArray &metadata);
56  void newImage(const QByteArray &image);
57 
58  public slots:
59  void connectServer();
60  void disconnectServer();
61 
62  // Capture
63  void sendVideoFrame(const QSharedPointer<QImage> &frame);
64 
65  // Options
66  void setOptions(QMap<int, bool> options)
67  {
68  m_Options = options;
69  }
70 
71  // Correction Vector
72  void setCorrectionVector(QLineF correctionVector)
73  {
74  this->correctionVector = correctionVector;
75  }
76 
77  // Polar View
78  void resetPolarView();
79 
80  void processNewBLOB(IBLOB *bp);
81 
82  private slots:
83  // Connection
84  void onConnected();
85  void onDisconnected();
86  void onError(QAbstractSocket::SocketError error);
87 
88  // Communication
89  void onTextReceived(const QString &message);
90  void onBinaryReceived(const QByteArray &message);
91 
92  // Metadata and Image upload
93  void uploadMetadata(const QByteArray &metadata);
94  void uploadImage(const QByteArray &image);
95 
96  private:
97  void upload(const QSharedPointer<FITSView> &view);
98 
99  QWebSocket m_WebSocket;
100  QJsonObject m_AuthResponse;
101  uint16_t m_ReconnectTries {0};
102  Ekos::Manager * m_Manager { nullptr };
103  QUrl m_URL;
104  QString m_UUID;
105 
106  QMap<int, bool> m_Options;
107 
108  QString extension;
109  QStringList temporaryFiles;
110  QLineF correctionVector;
111  QSharedPointer<FITSView> m_TemporaryView;
112 
113  bool m_isConnected { false };
114  bool m_sendBlobs { true};
115 
116  // Image width for high-bandwidth setting
117  static const uint16_t HB_IMAGE_WIDTH = 1920;
118  // Video width for high-bandwidth setting
119  static const uint16_t HB_VIDEO_WIDTH = 1280;
120  // Image high bandwidth image quality (jpg)
121  static const uint8_t HB_IMAGE_QUALITY = 90;
122  // Video high bandwidth video quality (jpg)
123  static const uint8_t HB_VIDEO_QUALITY = 64;
124  // Image high bandwidth image quality (jpg) for PAH
125  static const uint8_t HB_PAH_IMAGE_QUALITY = 50;
126  // Video high bandwidth video quality (jpg) for PAH
127  static const uint8_t HB_PAH_VIDEO_QUALITY = 24;
128 
129  // Retry every 5 seconds in case remote server is down
130  static const uint16_t RECONNECT_INTERVAL = 5000;
131  // Retry for 1 hour before giving up
132  static const uint16_t RECONNECT_MAX_TRIES = 720;
133 
134  // Binary Metadata Size
135  static const uint16_t METADATA_PACKET = 512;
136 
137  // HIPS Tile Width and Height
138  static const uint16_t HIPS_TILE_WIDTH = 512;
139  static const uint16_t HIPS_TILE_HEIGHT = 512;
140 };
141 }
Q_OBJECTQ_OBJECT
Generic record interfaces and implementations.
Definition: cloud.cpp:23
QString message
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Aug 14 2022 04:13:58 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.