From 91bcfe2c50c8732c1ccf792ca1f8964966808352 Mon Sep 17 00:00:00 2001 From: houxiao <houxiao@454eff88-639b-444f-9e54-f578c98de674> Date: 星期二, 10 一月 2017 17:25:40 +0800 Subject: [PATCH] add face daemon --- RtspFace/main_face_daemon.cpp | 114 +++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 75 insertions(+), 39 deletions(-) diff --git a/RtspFace/main_face_daemon.cpp b/RtspFace/main_face_daemon.cpp index 84901f4..9ee5d4a 100644 --- a/RtspFace/main_face_daemon.cpp +++ b/RtspFace/main_face_daemon.cpp @@ -1,4 +1,5 @@ #include "PipeLine.h" +#include "MaterialBuffer.h" #include "PL_RTSPClient.h" #include "PL_RTSPServer.h" #include "PL_H264Decoder.h" @@ -8,6 +9,8 @@ #include "PL_Queue.h" #include "PL_Scale.h" #include "PL_Fork.h" +#include "PL_Payer.h" +#include "PL_Gainer.h" #include "PL_SensetimeFaceTrack.h" #include "PL_DlibFaceTrack.h" @@ -15,6 +18,7 @@ #include "ev_server.h" #include "ev_proto.h" +#include "face_daemon_proto.h" #include "logger.h" @@ -22,18 +26,24 @@ evclient_proc_t evclient_proc; -bool ev_proc_SensetimeFaceDetect(EVClientStub& client) +void send_SensetimeFaceDetectResult(PipeMaterial& lastPm) { + if (lastPm.type == PipeMaterial::PMT_PM_LIST) + { + PipeMaterial& facePM = ((PipeMaterial*)(lastPm.buffer))[1]; + st_ff_vect_t& faceFeatures = *((st_ff_vect_t*)facePM.buffer); + LOG_NOTICE << "faceFeatures " << faceFeatures.size(); + //#todo send result packet + } } -bool ev_proc(EVClientStub& client) +bool ev_proc_SensetimeFaceDetect(EVClientStub& client) { - EVPHeader* evpHeader = (EVPHeader*)client.recvBuff; - //#todo check cmd and size - //#test send 01000B0000004142434445 //LOG_DEBUG << "cmd=" << evpHeader->cmd << ", size=" << evpHeader->size << ", \t" << (char*)(evpHeader + sizeof(EVPHeader)); //return true; + + FDP_Image* fdpImage = (FDP_Image*)(client.recvBuff + sizeof(EVPHeader)); PipeLine* pipeLine = nullptr; if (g_PipeLinePool.wait_free()) @@ -41,37 +51,69 @@ if (pipeLine == nullptr) { - LOG_WARN << "can't get free pipeline";//#todo send err packet + LOG_WARN << "can't get free pipeline"; + ev_send_status_packet(client, EVPStatus::EVPS_INTERNAL_ERROR); return false; } - PipeMaterial pm; // fill + MB_Frame frame; + frame.type = (MB_Frame::MBFType)(fdpImage->mb_type); + frame.buffer = fdpImage->buff; + frame.buffSize = client.recvBuffSize - sizeof(EVPHeader) - sizeof(FDP_Image); + frame.width = fdpImage->width; + frame.height = fdpImage->height; - PipeLineElem* plElem = pipeLine.pipe(&pm); - if (! pipeLine.check_pipe_complete(plElem)) + PipeMaterial pm; + pm.type = PipeMaterial::PMT_FRAME; + pm.buffer = &frame; + pm.buffSize = 0; + + PipeLineElem* plElem = pipeLine->pipe(&pm); + if (! pipeLine->check_pipe_complete(plElem)) { LOG_WARN << "pipeline not complete"; - g_PipeLinePool.release(pipeLine);//#todo send err packet + g_PipeLinePool.release(pipeLine); + ev_send_status_packet(client, EVPStatus::EVPS_INTERNAL_ERROR); return false; } if (!plElem->gain(pm)) { LOG_WARN << "pipeline gain error"; - g_PipeLinePool.release(pipeLine);//#todo send err packet + g_PipeLinePool.release(pipeLine); + ev_send_status_packet(client, EVPStatus::EVPS_INTERNAL_ERROR); + return false; + } + + send_SensetimeFaceDetectResult(pm); + + g_PipeLinePool.release(pipeLine); + return false; +} + +bool ev_proc(EVClientStub& client) +{ + EVPHeader* evpHeader = (EVPHeader*)client.recvBuff; + if (evpHeader->size != client.recvBuffSize) + { + LOG_WARN << "Truncated buffer " << (evpHeader->size - client.recvBuffSize) << " bytes"; return false; } - if (pm.type == PipeMaterial::PMT_PM_LIST) + switch(evpHeader->cmd) { - PipeMaterial& facePM = ((PipeMaterial*)(pm.buffer))[1]; - st_ff_vect_t& faceFeatures = *((st_ff_vect_t*)facePM.buffer); - LOG_NOTICE << "faceFeatures " << faceFeatures.size(); - //#todo send result packet + case EVPCommand::EVPC_USER_DEFINE + 1: + return ev_proc_SensetimeFaceDetect(client); + break; + default: + LOG_WARN << "Unknown command"; + ev_send_status_packet(client, EVPStatus::EVPS_PARAMETER_ERROR); + return false; + break; } - g_PipeLinePool.release(pipeLine); + // return false to disconnect return false; } @@ -80,6 +122,7 @@ initLogger(LV_DEBUG); PipeLine::register_global_elem_creator("PL_SensetimeFaceTrack", create_PL_SensetimeFaceTrack); + PipeLine::register_global_elem_creator("PL_Gainer", create_PL_Gainer); g_PipeLinePool = new PipeLinePool(true); @@ -87,17 +130,28 @@ { PipeLine* pipeLine = new PipeLine; - {//payer//#todo + { + PL_Payer_Config config; + config.copyData = true; + PL_Gainer* ple = (PL_Gainer*)pipeLine->push_elem("PL_Gainer"); + bool ret = ple->init(&config); + if (!ret) + { + LOG_ERROR << "ple init error"; + exit(EXIT_FAILURE); + } } { SensetimeFaceTrackConfig config; + config.draw_face_rect = false; + config.draw_face_feature_point = false; config.generate_face_feature = true; - PL_SensetimeFaceTrack* sensetimeFaceTrack = (PL_SensetimeFaceTrack*)pipeLine->push_elem("PL_SensetimeFaceTrack"); - bool ret = sensetimeFaceTrack->init(&config); + PL_SensetimeFaceTrack* ple = (PL_SensetimeFaceTrack*)pipeLine->push_elem("PL_SensetimeFaceTrack"); + bool ret = ple->init(&config); if (!ret) { - LOG_ERROR << "sensetimeFaceTrack init error"; + LOG_ERROR << "ple init error"; exit(EXIT_FAILURE); } } @@ -107,22 +161,4 @@ evclient_proc = ev_proc; return server_main(argc, argv); - - while(true) - { - //LOG_ERROR << "begin pipe"; - - PipeMaterial pm; - if (pipeLine.pipe(&pm) == sensetimeFaceTrack); - sensetimeFaceTrack->gain(pm); - - if (pm.type == PipeMaterial::PMT_PM_LIST) - { - PipeMaterial& facePM = ((PipeMaterial*)(pm.buffer))[1]; - st_ff_vect_t& faceFeatures = *((st_ff_vect_t*)facePM.buffer); - LOG_NOTICE << "faceFeatures " << faceFeatures.size(); - } - - //LOG_ERROR << "end pipe"; - } } -- Gitblit v1.8.0