File indexing completed on 2024-04-28 03:43:20
0001 /* 0002 SPDX-FileCopyrightText: 2018 Jasem Mutlaq <mutlaqja@ikarustech.com> 0003 0004 Media Channel 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include <QtWebSockets/QWebSocket> 0012 #include <memory> 0013 0014 #include "ekos/manager.h" 0015 #include "nodemanager.h" 0016 0017 class FITSView; 0018 0019 namespace EkosLive 0020 { 0021 class Media : public QObject 0022 { 0023 Q_OBJECT 0024 0025 public: 0026 explicit Media(Ekos::Manager * manager, QVector<QSharedPointer<NodeManager>> &nodeManagers); 0027 virtual ~Media() = default; 0028 0029 bool isConnected() const; 0030 void sendResponse(const QString &command, const QJsonObject &payload); 0031 void sendResponse(const QString &command, const QJsonArray &payload); 0032 0033 void registerCameras(); 0034 0035 // Ekos Media Message to User 0036 void sendFile(const QString &filename, const QString &uuid); 0037 void sendData(const QSharedPointer<FITSData> &data, const QString &uuid); 0038 void sendView(const QSharedPointer<FITSView> &view, const QString &uuid); 0039 void sendUpdatedFrame(const QSharedPointer<FITSView> &view); 0040 void sendModuleFrame(const QSharedPointer<FITSView> &view); 0041 0042 // Convenience functions 0043 void sendDarkLibraryData(const QSharedPointer<FITSData> &data); 0044 0045 signals: 0046 void connected(); 0047 void disconnected(); 0048 0049 void newBoundingRect(QRect rect, QSize view, double currentZoom); 0050 void newMetadata(const QByteArray &metadata); 0051 void newImage(const QByteArray &image); 0052 0053 public slots: 0054 // Capture 0055 void sendVideoFrame(const QSharedPointer<QImage> &frame); 0056 0057 // Correction Vector 0058 void setCorrectionVector(QLineF correctionVector) 0059 { 0060 this->correctionVector = correctionVector; 0061 } 0062 0063 // Polar View 0064 void resetPolarView(); 0065 0066 void processNewBLOB(IBLOB *bp); 0067 0068 private slots: 0069 // Connection 0070 void onConnected(); 0071 void onDisconnected(); 0072 0073 // Communication 0074 void onTextReceived(const QString &message); 0075 void onBinaryReceived(const QByteArray &message); 0076 0077 // Metadata and Image upload 0078 void uploadMetadata(const QByteArray &metadata); 0079 void uploadImage(const QByteArray &image); 0080 0081 private: 0082 void upload(const QSharedPointer<FITSView> &view); 0083 0084 Ekos::Manager * m_Manager { nullptr }; 0085 QVector<QSharedPointer<NodeManager>> m_NodeManagers; 0086 QString m_UUID; 0087 QString extension; 0088 QStringList temporaryFiles; 0089 QLineF correctionVector; 0090 QSharedPointer<FITSView> m_TemporaryView; 0091 0092 bool m_sendBlobs { true}; 0093 0094 // Image width for high-bandwidth setting 0095 static const uint16_t HB_IMAGE_WIDTH = 1920; 0096 // Video width for high-bandwidth setting 0097 static const uint16_t HB_VIDEO_WIDTH = 1280; 0098 // Image high bandwidth image quality (jpg) 0099 static const uint8_t HB_IMAGE_QUALITY = 90; 0100 // Video high bandwidth video quality (jpg) 0101 static const uint8_t HB_VIDEO_QUALITY = 64; 0102 // Image high bandwidth image quality (jpg) for PAH 0103 static const uint8_t HB_PAH_IMAGE_QUALITY = 50; 0104 // Video high bandwidth video quality (jpg) for PAH 0105 static const uint8_t HB_PAH_VIDEO_QUALITY = 24; 0106 0107 // Retry every 5 seconds in case remote server is down 0108 static const uint16_t RECONNECT_INTERVAL = 5000; 0109 // Retry for 1 hour before giving up 0110 static const uint16_t RECONNECT_MAX_TRIES = 720; 0111 0112 // Binary Metadata Size 0113 static const uint16_t METADATA_PACKET = 512; 0114 0115 // HIPS Tile Width and Height 0116 static const uint16_t HIPS_TILE_WIDTH = 512; 0117 static const uint16_t HIPS_TILE_HEIGHT = 512; 0118 }; 0119 }