implement webui live video (#340)

* implement webui live video

* add missing german translation
This commit is contained in:
redPanther
2016-12-18 19:00:14 +01:00
committed by GitHub
parent 23194730c2
commit 721668fc85
15 changed files with 156 additions and 20 deletions

View File

@@ -33,7 +33,7 @@ add_library(jsonserver
${JsonServer_RESOURCES_RCC}
)
qt5_use_modules(jsonserver Network)
qt5_use_modules(jsonserver Network Gui)
target_link_libraries(jsonserver
hyperion

View File

@@ -22,6 +22,11 @@
#include <QJsonDocument>
#include <QVariantMap>
#include <QDir>
#include <QImage>
#include <QBuffer>
#include <QByteArray>
#include <QIODevice>
#include <QDateTime>
// hyperion util includes
#include <hyperion/ImageProcessorFactory.h>
@@ -50,6 +55,7 @@ JsonClientConnection::JsonClientConnection(QTcpSocket *socket)
, _log(Logger::getInstance("JSONCLIENTCONNECTION"))
, _forwarder_enabled(true)
, _streaming_logging_activated(false)
, _image_stream_timeout(0)
{
// connect internal signals and slots
connect(_socket, SIGNAL(disconnected()), this, SLOT(socketClosed()));
@@ -58,6 +64,7 @@ JsonClientConnection::JsonClientConnection(QTcpSocket *socket)
_timer_ledcolors.setSingleShot(false);
connect(&_timer_ledcolors, SIGNAL(timeout()), this, SLOT(streamLedcolorsUpdate()));
_image_stream_mutex.unlock();
}
@@ -1197,22 +1204,32 @@ void JsonClientConnection::handleLedColorsCommand(const QJsonObject& message, co
{
// create result
QString subcommand = message["subcommand"].toString("");
_streaming_leds_reply["success"] = true;
_streaming_leds_reply["command"] = command;
_streaming_leds_reply["tan"] = tan;
if (subcommand == "ledstream-start")
{
_streaming_leds_reply["success"] = true;
_streaming_leds_reply["command"] = command+"-ledstream-update";
_streaming_leds_reply["tan"] = tan;
_timer_ledcolors.start(125);
}
else if (subcommand == "ledstream-stop")
{
_timer_ledcolors.stop();
}
else if (subcommand == "imagestream-start")
{
_streaming_image_reply["success"] = true;
_streaming_image_reply["command"] = command+"-imagestream-update";
_streaming_image_reply["tan"] = tan;
connect(_hyperion, SIGNAL(emitImage(int, const Image<ColorRgb>&, const int)), this, SLOT(setImage(int, const Image<ColorRgb>&, const int)) );
}
else if (subcommand == "imagestream-stop")
{
disconnect(_hyperion, SIGNAL(emitImage(int, const Image<ColorRgb>&, const int)), this, 0 );
}
else
{
sendErrorReply("unknown subcommand",command,tan);
sendErrorReply("unknown subcommand \""+subcommand+"\"",command,tan);
return;
}
@@ -1482,5 +1499,28 @@ void JsonClientConnection::streamLedcolorsUpdate()
// send the result
sendMessage(_streaming_leds_reply);
}
void JsonClientConnection::setImage(int priority, const Image<ColorRgb> & image, int duration_ms)
{
if ( (_image_stream_timeout+250) < QDateTime::currentMSecsSinceEpoch() && _image_stream_mutex.tryLock(0) )
{
_image_stream_timeout = QDateTime::currentMSecsSinceEpoch();
QImage jpgImage((const uint8_t *) image.memptr(), image.width(), image.height(), 3*image.width(), QImage::Format_RGB888);
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
jpgImage.save(&buffer, "jpg");
QJsonObject result;
result["image"] = "data:image/jpg;base64,"+QString(ba.toBase64());
_streaming_image_reply["result"] = result;
sendMessage(_streaming_image_reply);
_image_stream_mutex.unlock();
}
}

View File

@@ -6,6 +6,7 @@
// Qt includes
#include <QByteArray>
#include <QTcpSocket>
#include <QMutex>
// Hyperion includes
#include <hyperion/Hyperion.h>
@@ -116,6 +117,7 @@ public slots:
void componentStateChanged(const hyperion::Components component, bool enable);
void streamLedcolorsUpdate();
void incommingLogMessage(Logger::T_LOG_MESSAGE);
void setImage(int priority, const Image<ColorRgb> & image, int duration_ms);
signals:
///
@@ -338,12 +340,21 @@ private:
/// timer for ledcolors streaming
QTimer _timer_ledcolors;
// streaming buffers
QJsonObject _streaming_leds_reply;
QJsonObject _streaming_image_reply;
QJsonObject _streaming_logging_reply;
/// flag to determine state of log streaming
bool _streaming_logging_activated;
/// mutex to determine state of image streaming
QMutex _image_stream_mutex;
/// timeout for live video refresh
volatile qint64 _image_stream_timeout;
// masks for fields in the basic header
static uint8_t const BHB0_OPCODE = 0x0F;
static uint8_t const BHB0_RSV3 = 0x10;