#include "Ipc/IpcMoudle.h" #include #define STB_IMAGE_WRITE_IMPLEMENTATION #include //#include "Core/Core.h" #include "Ipc/ipclib.h" //#include "ImageBuffer.h" //#include "VHI/VHI.h" //IpcMoudle* Singleton::instance_ = nullptr; void OnParseImageData(const char* data, size_t size) { if (size < 13) { // Minimum size check: 1 byte identifier + 4 bytes width + 4 bytes height + 4 bytes bit depth std::cerr << "Invalid data size" << std::endl; return; } // Extract identifier char identifier = data[0]; const char* buffer = data + 1; /* if (0x01 == identifier) { IpcMoudle::Get()->PushImage(buffer, size - 1); } else if (0x02 == identifier) { IpcMoudle::Get()->PushVoice(buffer, size - 1); } INFOLOG("identifier {}", static_cast(identifier));*/ } bool IpcMoudle::Initialize() { //if (!initialize("human_render", "human_product")) { // ERRORLOG("ipc initialize failed"); // return false; //} //setReaderCallback([](const char* data, unsigned int size) { // //INFOLOG("ipc recive data:{}", size); // OnParseImageData(data, size); // } //); //if (!listen()) { // ERRORLOG("ipc listen failed"); // return false; //} ////auto callback = [](const char* data, unsigned int size) { //// //INFOLOG("ipc recive data:{}", size); //// OnParseImageData(data, size); ////}; ////zmqMoudle_ = std::make_unique(callback); ////zmqMoudle_->Start(); //lastHeartbeatTime_ = std::chrono::steady_clock::now(); return true; } void IpcMoudle::Uninitialize() { //zmqMoudle_->Stop(); uninitialize(); } bool IpcMoudle::Send(const char* data, unsigned int size) { return send(data, size); return false; } void IpcMoudle::OnFrame() { auto now = std::chrono::steady_clock::now(); auto duration = std::chrono::duration_cast(now - lastHeartbeatTime_); if (duration.count() >= 2) { /* constexpr char heartbeat[] = "heartbeat"; if (!send("heartbeat", sizeof(heartbeat) / sizeof(heartbeat[0]))) { ERRORLOG("send heartbeat failed"); reConnect(); }*/ lastHeartbeatTime_ = now; } } void IpcMoudle::PushImage(const char* data, uint32 size) { // Extract width int width; std::memcpy(&width, data, sizeof(int)); // Extract height int height; std::memcpy(&height, data + 4, sizeof(int)); // Extract bit depth int bit_depth; std::memcpy(&bit_depth, data + 8, sizeof(int)); // Extract image bytes const char* img_bytes = data + 12; size_t img_size = size - 12; //std::vector img_data(img_size); //memcpy(img_data.data(), img_bytes, img_size); //ImageBuffer::Get()->PushImage(ImageBuffer::IBType::Human, std::move(img_data), width, height, bit_depth); } void IpcMoudle::PushVoice(const char* data, uint32 size) { /* IAudioRender* audioRender = VHI::Get()->GetAudioRender(); if (nullptr == audioRender) { return; } audioRender->Write(data, size);*/ }