#include "PipeLine.h"
|
#include "PL_RTSPServer.h"
|
#include "PL_RaspiVid.h"
|
|
#include "logger.h"
|
#include <iostream>
|
|
#include <signal.h>
|
#include <time.h>
|
#include <unistd.h>
|
|
#include <cmdhub/client.h>
|
|
#define CLOCKID CLOCK_REALTIME
|
|
Logger g_logger(std::cout);
|
|
time_t g_last_pipe_finished = 0;
|
|
my_id_t get_my_id()
|
{
|
return 123;
|
}
|
|
std::string cmdhub_send_cmd(const std::string client_cmd)
|
{
|
CmdhubClientSession session;
|
session.recv_retry = 5;
|
if (!cmdhub_client_init(session))
|
{
|
LOG_ERROR << "cam_ir_timer cmdhub_client_init error" << LOG_ENDL;
|
return "";
|
}
|
if (!cmdhub_client_connect(session))
|
{
|
LOG_ERROR << "cam_ir_timer cmdhub_client_connect error" << LOG_ENDL;
|
return "";
|
}
|
|
std::string result;
|
int exit_code;
|
if (cmdhub_client_command(session, client_cmd, result, exit_code))
|
{
|
LOG_INFO << "exit_code:" << exit_code << ", result:" << result.c_str();
|
|
cmdhub_client_destory(session);
|
return result;
|
}
|
|
cmdhub_client_destory(session);
|
return "";
|
}
|
|
static void cam_ir_timer(union sigval v)
|
{
|
LOGP(DEBUG, "checking IR %d", v.sival_int);
|
|
if (time(nullptr) - g_last_pipe_finished < 5)
|
{
|
// camera should be closed
|
cmdhub_send_cmd("exec/camirlighting camera_enable");
|
}
|
else
|
{
|
cmdhub_send_cmd("exec/camirlighting camera_disable");
|
}
|
}
|
|
void start_cam_ir_timer()
|
{
|
timer_t timerid;
|
struct sigevent evp;
|
memset(&evp, 0, sizeof(struct sigevent));
|
|
evp.sigev_value.sival_int = 123;
|
evp.sigev_notify = SIGEV_THREAD;
|
evp.sigev_notify_function = cam_ir_timer;
|
|
if (timer_create(CLOCKID, &evp, &timerid) == -1)
|
{
|
LOG_ERROR << "fail to timer_create" << LOG_ENDL;
|
exit(EXIT_FAILURE);
|
}
|
|
struct itimerspec it;
|
it.it_interval.tv_sec = 5;
|
it.it_interval.tv_nsec = 0;
|
it.it_value.tv_sec = 5;
|
it.it_value.tv_nsec = 0;
|
|
if (timer_settime(timerid, 0, &it, NULL) == -1)
|
{
|
LOG_ERROR << "fail to timer_settime" << LOG_ENDL;
|
exit(EXIT_FAILURE);
|
}
|
}
|
|
int main(int argc, char** argv)
|
{
|
g_logger.set_level(INFO);
|
|
PipeLine pipeLine;
|
|
PipeLine::register_global_elem_creator("PL_RaspiVid", create_PL_RaspiVid);
|
PipeLine::register_global_elem_creator("PL_RTSPServer", create_PL_RTSPServer);
|
|
{
|
PL_RaspiVid* raspiVid = (PL_RaspiVid*)pipeLine.push_elem("PL_RaspiVid");
|
PL_RaspiVid_Config config;
|
config.vflip = true;
|
//config.profile = "baseline";
|
//config.level = "4";
|
bool ret = raspiVid->init(&config);
|
if (!ret)
|
{
|
LOG_ERROR << "raspiVid.init error" << std::endl;
|
exit(EXIT_FAILURE);
|
}
|
}
|
|
{
|
PL_RTSPServer* rtspServer = (PL_RTSPServer*)pipeLine.push_elem("PL_RTSPServer");
|
bool ret = rtspServer->init(nullptr);
|
if (!ret)
|
{
|
LOG_ERROR << "rtspServer.init error" << std::endl;
|
exit(EXIT_FAILURE);
|
}
|
}
|
|
cmdhub_send_cmd("exec/camirlighting bh1750_value");
|
cmdhub_send_cmd("exec/camirlighting cam_ir_threshold 5");
|
|
start_cam_ir_timer();
|
|
while(true)
|
{
|
//LOG_ERROR << "begin pipe" << std::endl;
|
pipeLine.pipe();
|
//LOG_ERROR << "end pipe" << std::endl;
|
|
g_last_pipe_finished = time(nullptr);
|
}
|
}
|