mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
implement webui live video (#340)
* implement webui live video * add missing german translation
This commit is contained in:
@@ -88,10 +88,10 @@ void V4L2Wrapper::set3D(VideoMode mode)
|
||||
void V4L2Wrapper::newFrame(const Image<ColorRgb> &image)
|
||||
{
|
||||
// forward to other hyperions
|
||||
if ( _forward )
|
||||
{
|
||||
//if ( _forward )
|
||||
//{
|
||||
emit emitImage(_priority, image, _timeout_ms);
|
||||
}
|
||||
//}
|
||||
|
||||
// process the new image
|
||||
_processor->process(image, _ledColors);
|
||||
|
@@ -64,10 +64,10 @@ void X11Wrapper::action()
|
||||
// Grab frame into the allocated image
|
||||
_grabber->grabFrame(_image);
|
||||
|
||||
if ( _forward )
|
||||
{
|
||||
//if ( _forward )
|
||||
//{
|
||||
emit emitImage(_priority, _image, _timeout_ms);
|
||||
}
|
||||
//}
|
||||
|
||||
_processor->process(_image, _ledColors);
|
||||
setColors(_ledColors, _timeout_ms);
|
||||
|
@@ -56,7 +56,6 @@ void GrabberWrapper::componentStateChanged(const hyperion::Components component,
|
||||
|
||||
_forward = _hyperion->getForwarder()->protoForwardingEnabled();
|
||||
|
||||
|
||||
if ( enable == _timer.isActive() )
|
||||
{
|
||||
Info(_log, "grabber change state to %s", (_timer.isActive() ? "enabled" : "disabled") );
|
||||
|
@@ -739,6 +739,14 @@ void Hyperion::setColors(int priority, const std::vector<ColorRgb>& ledColors, c
|
||||
}
|
||||
}
|
||||
|
||||
void Hyperion::setImage(int priority, const Image<ColorRgb> & image, int duration_ms)
|
||||
{
|
||||
if (priority == getCurrentPriority())
|
||||
{
|
||||
emit emitImage(priority, image, duration_ms);
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<std::string> & Hyperion::getTransformIds() const
|
||||
{
|
||||
return _raw2ledTransform->getTransformIds();
|
||||
|
@@ -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
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user