update.
This commit is contained in:
@ -7,6 +7,7 @@ add_executable(PassengerStatistics main.cpp
|
||||
Application.h Application.cpp
|
||||
Camera.h Camera.cpp
|
||||
ImageUtilities.h ImageUtilities.cpp
|
||||
NngServer.h NngServer.cpp
|
||||
RtspServer.h RtspServer.cpp
|
||||
Settings.h Settings.cpp
|
||||
VideoInput.h VideoInput.cpp
|
||||
@ -38,6 +39,7 @@ target_link_directories(PassengerStatistics
|
||||
target_link_libraries(PassengerStatistics
|
||||
PRIVATE Kylin::Core
|
||||
PRIVATE Kylin::Router
|
||||
PRIVATE Kylin::Nng
|
||||
PRIVATE LibDataChannel::LibDataChannel
|
||||
PRIVATE OpenSSL::SSL
|
||||
PRIVATE OpenSSL::Crypto
|
||||
|
@ -82,7 +82,7 @@ bool Camera::zoom(Zoom type) {
|
||||
autolens_param.Params.Param_Base.nSpeed = 10;
|
||||
int status = SensorSdk_AutoLens_SetParam(0, zoomType, &autolens_param);
|
||||
|
||||
std::this_thread::sleep_for(10ms);
|
||||
std::this_thread::sleep_for(20ms);
|
||||
|
||||
autolens_param.Params.Param_Base.nStop = 1;
|
||||
autolens_param.Params.Param_Base.nSpeed = 0;
|
||||
|
54
Main/NngServer.cpp
Normal file
54
Main/NngServer.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#include "NngServer.h"
|
||||
#include "Camera.h"
|
||||
#include "Core/Logger.h"
|
||||
#include "Nng/SocketAisoWrapper.h"
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/json/object.hpp>
|
||||
#include <boost/json/parse.hpp>
|
||||
#include <sstream>
|
||||
|
||||
NngServer::NngServer(boost::asio::io_context &ioContex) {
|
||||
m_socket = std::make_shared<Nng::Asio::Socket>(ioContex, Nng::Reply);
|
||||
}
|
||||
|
||||
void NngServer::asyncRead() {
|
||||
m_socket->asyncReceive([ptr{weak_from_this()}](const boost::system::error_code &error, const Nng::Buffer &buffer) {
|
||||
if (error) {
|
||||
LOG(error) << error.message();
|
||||
return;
|
||||
}
|
||||
if (ptr.expired()) return;
|
||||
auto self = ptr.lock();
|
||||
std::error_code jsonError;
|
||||
auto value = boost::json::parse(buffer.data<char>(), jsonError);
|
||||
if (jsonError) {
|
||||
LOG(error) << jsonError.message();
|
||||
} else {
|
||||
auto &request = value.as_object();
|
||||
auto command = request.at("command").as_string();
|
||||
LOG(info) << "command: " << command;
|
||||
auto camera = Core::Singleton<Camera>::instance();
|
||||
if (command == "ZeroCheck") {
|
||||
|
||||
camera->zeroCheck();
|
||||
} else if (command == "Zoom") {
|
||||
auto direction = request.at("direction").as_string();
|
||||
camera->zoom(direction == "In" ? Camera::Zoom::In : Camera::Zoom::Out);
|
||||
} else if (command == "Focus") {
|
||||
auto direction = request.at("direction").as_string();
|
||||
camera->focus(direction == "Far" ? Camera::Focus::Far : Camera::Focus::Near);
|
||||
}
|
||||
}
|
||||
|
||||
LOG(info) << "nng received: " << buffer.data<char>();
|
||||
self->m_socket->send((void *)"world", strlen("world") + 1);
|
||||
self->asyncRead();
|
||||
});
|
||||
}
|
||||
|
||||
void NngServer::start(uint16_t replyPort) {
|
||||
std::ostringstream oss;
|
||||
oss << "tcp://0.0.0.0:" << replyPort;
|
||||
m_socket->listen(oss.str());
|
||||
asyncRead();
|
||||
}
|
34
Main/NngServer.h
Normal file
34
Main/NngServer.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef __NNGSERVER_H__
|
||||
#define __NNGSERVER_H__
|
||||
|
||||
#include "Core/Singleton.h"
|
||||
|
||||
namespace boost {
|
||||
namespace asio {
|
||||
class io_context;
|
||||
}
|
||||
} // namespace boost
|
||||
|
||||
namespace Nng {
|
||||
|
||||
namespace Asio {
|
||||
|
||||
class Socket;
|
||||
}
|
||||
} // namespace Nng
|
||||
|
||||
class NngServer : public std::enable_shared_from_this<NngServer> {
|
||||
friend class Core::Singleton<NngServer>;
|
||||
|
||||
public:
|
||||
void start(uint16_t replyPort);
|
||||
|
||||
protected:
|
||||
NngServer(boost::asio::io_context &ioContex);
|
||||
void asyncRead();
|
||||
|
||||
private:
|
||||
std::shared_ptr<Nng::Asio::Socket> m_socket;
|
||||
};
|
||||
|
||||
#endif // __NNGSERVER_H__
|
@ -67,4 +67,8 @@ std::string Settings::sqlitePath() const {
|
||||
return m_sqlitePath;
|
||||
}
|
||||
|
||||
uint16_t Settings::nngReplyPort() const {
|
||||
return m_nngReplyPort;
|
||||
}
|
||||
|
||||
} // namespace Danki
|
@ -16,6 +16,7 @@ public:
|
||||
uint16_t port() const;
|
||||
std::string documentRoot() const;
|
||||
std::string sqlitePath() const;
|
||||
uint16_t nngReplyPort() const;
|
||||
|
||||
private:
|
||||
uint32_t m_threads = 1;
|
||||
@ -24,6 +25,8 @@ private:
|
||||
|
||||
std::string m_documentRoot = "/data/sdcard/PassengerStatistics/web";
|
||||
std::string m_sqlitePath = "database.sqlite";
|
||||
|
||||
uint16_t m_nngReplyPort = 8000;
|
||||
};
|
||||
} // namespace Danki
|
||||
|
||||
|
@ -163,6 +163,7 @@ void Streamer::start(const std::string &signalServerAddress, uint16_t signalServ
|
||||
|
||||
void Streamer::push(const uint8_t *data, uint32_t size) {
|
||||
using namespace std::chrono;
|
||||
if (m_d->m_clients.empty()) return;
|
||||
boost::asio::post(m_d->strand, [this, frame = rtc::binary(reinterpret_cast<const rtc::byte *>(data),
|
||||
reinterpret_cast<const rtc::byte *>(data) + size)]() {
|
||||
for (auto &[id, client] : m_d->m_clients) {
|
||||
|
@ -4,7 +4,9 @@
|
||||
#include "Core/IoContext.h"
|
||||
#include "Core/Logger.h"
|
||||
#include "Core/Singleton.h"
|
||||
#include "NngServer.h"
|
||||
#include "RtspServer.h"
|
||||
#include "Settings.h"
|
||||
#include "VideoInput.h"
|
||||
#include "WebRTC/Streamer.h"
|
||||
#include "rw_mpp_api.h"
|
||||
@ -27,12 +29,16 @@ int main(int argc, char const *argv[]) try {
|
||||
});
|
||||
|
||||
auto application = Singleton<Application>::construct();
|
||||
auto settings = Singleton<Settings>::instance();
|
||||
|
||||
auto camera = Singleton<Camera>::construct();
|
||||
auto rtsp = std::make_shared<RtspServer>(application->ioContext());
|
||||
auto streamer = std::make_shared<Streamer>(application->ioContext());
|
||||
streamer->start("127.0.0.1", 80);
|
||||
|
||||
auto nng = Singleton<NngServer>::construct(application->ioContext());
|
||||
nng->start(settings->nngReplyPort());
|
||||
|
||||
auto video = std::make_shared<VideoInput>(2592, 1536);
|
||||
video->setPacketHandler([&](const uint8_t *data, uint32_t size) {
|
||||
rtsp->push(data, size);
|
||||
|
Reference in New Issue
Block a user