提交 3c7c2d91 authored 作者: tobyfan1980's avatar tobyfan1980

evcamera: refine log message

上级 2ca2ac3c
......@@ -26,3 +26,9 @@
*.out
*.app
CMakeFiles/
# workspace
*.code-workspace
.DS_Store
# vendor
vendor/**
......@@ -47,5 +47,14 @@ source /root/setenv.sh
- server用到的库的安装路径是 <source_path>/vendor/x64
### 编译
- evcamera
在 hi3518 下运行 make 就可以编译出一个独立的可执行文件 evcamera.
- vgw
在 server 下运行 make 就可以编译出一个独立的可执行文件 vgw.
vgw 运行只需要依赖两个环境变量
* DARWIN_URL easy darwin 的 url, 如果没有, 使用默认的 rtsp://evcloudsvc.ilabservice.cloud:554
* LOG_LEVEL 日志输出等级. 如果没有, 日志 level 为 debug
\ No newline at end of file
......@@ -32,7 +32,7 @@ unsigned short crc16(const unsigned char* data_p, unsigned char length)
}
namespace evutils {
const char consts::version[] = "EVC20200429";
const char consts::version[] = "v20200722";
const string consts::kMsgCmd = "cmd";
const string consts::kMsgCmdConfig = "config";
const string consts::kMsgConfigVgw = "vgw";
......
......@@ -310,7 +310,7 @@ void frame_send_entry(void *args)
while(1) {
rlogger->info("perpare for pusher");
if(!gConfigSystem.module.sys.push) {
gPusherFailsFlag |= 1 >> 2;
gPusherFailsFlag |= 1 << 2;
this_thread::sleep_for(4s);
continue;
}
......@@ -1097,12 +1097,12 @@ int main(int argc, char *argv[])
MaQueStartParam_s startParam = {MAQUE_VIDEO_STANDARD_PAL, {MAQUE_VIDEO_COMPRESS_H264, MAQUE_VIDEO_COMPRESS_H265}};
::memcpy(startParam.aWritableDir, strMaQuePath.c_str(), sizeof(startParam.aWritableDir));
ret = LibXmMaQue_System_startUp(&startParam);
rlogger->info("ret: {}", ret);
rlogger->info("LibXmMaQue_System_startUp ret: {}", ret);
//
MaQueMemoryApi_s memApi = {MaQue_Demo_Mem_alloc, MaQue_Demo_Mem_release, MaQue_Demo_Mem_addRef, MaQue_Demo_Mem_setLength};
ret = LibXmMaQue_Mem_init(&memApi);
rlogger->info("mem ret: {}", ret);
rlogger->info("LibXmMaQue_Mem_init ret: {}", ret);
MaQueSystemTime_s tm;
LibXmMaQue_Time_getCurrentTime(&tm);
......@@ -1110,9 +1110,9 @@ int main(int argc, char *argv[])
//
MaQueCodeAbilities_s capb;
ret = LibXmMaQue_VideoEnc_getAbilities(0, &capb);
rlogger->info("abt ret: {}", ret);
rlogger->info("LibXmMaQue_VideoEnc_getAbilities ret: {}", ret);
if (XM_SUCCESS == ret) {
rlogger->info(fmt::format("capbilities: supported codecs {0:#b},"
rlogger->info(fmt::format("VideoEncode capbilities: supported codecs {0:#b},"
"max fhd/s {0:d}, max res: {0:d}, per ch mres: {0:d}, {0:d}, {0:d}, {0:d}",
int(capb.videoEncTypeMask),
int(capb.maxEncPowerX1080P), int(capb.eDecImageSizeMax), int(capb.astVidEncChnAbility[0].eCapSizeMax),
......@@ -1157,11 +1157,11 @@ int main(int argc, char *argv[])
int64_t delta = 0;
while(delta < dura||always) {
string result;
rlogger->info("got qr job");
rlogger->info("scanning qr code");
string res = qr_analysis(result);
if(res.empty()) {
/// TODO: handle result
rlogger->info("processing qr event");
rlogger->info("processing qr code: {}", result);
process_qr_event(result);
if(!always) {
// set to stop
......@@ -1205,7 +1205,7 @@ int main(int argc, char *argv[])
bGotTime = true;
}
else {
rlogger->warn("failed to get ntp time");
rlogger->warn("failed to get ntp time, start scanning QR for 10 seconds, and retry ntp 3 seconds later");
// enable QR
gQRCodeDuration.store(10, memory_order_relaxed);
}
......@@ -1219,6 +1219,7 @@ int main(int argc, char *argv[])
/// subscribe to mqtt
while(gMqttClient == nullptr) {
rlogger->info("enter qr mode, to scan MQ host url and retry connection");
gQRCodeDuration.store(-1, memory_order_relaxed);
/// TODO: handle result
gMqttClient = start_mqtt(nullptr);
......@@ -1249,11 +1250,11 @@ int main(int argc, char *argv[])
}
/// TODO: configuration issues handling
if(msg_field(gJsonConfig, consts::kMsgConfigVgw).empty()) {
rlogger->error("missing vgw config");
rlogger->error("missing vgw config, won't be able to live streaming");
}
thread thPush = thread(frame_send_entry, &args);
rlogger->info("sizeof pkt header {}, sizeof tv {}", sizeof(evpacket_t), sizeof(timeval));
rlogger->info("sizeof pkt header {}, sizeof timeval {}", sizeof(evpacket_t), sizeof(timeval));
if(thPush.joinable()) {
thPush.detach();
}
......@@ -1277,10 +1278,12 @@ int main(int argc, char *argv[])
rlogger->info("started video upload service");
}
// start motion detection
start_md_bd(&gConfigSystem);
gQRCodeDuration.store(0);
// start human detection
thread thSmart = thread(maq_smart_task_entry, &gConfigSystem);
if(thSmart.joinable()) {
thSmart.detach();
......
......@@ -43,14 +43,14 @@ namespace md{
/// helpers
auto event_inspection(auto e, std::map<const std::string, int> &m){
if(std::is_same<decltype(e), people>::value){
rlogger->info("type is people: {}", ++m[kKeyP]);
rlogger->info("event type is people: count {}", ++m[kKeyP]);
}else if(std::is_same<decltype(e), motion>::value){
rlogger->info("type is motion: {}", ++m[kKeyM]);
rlogger->info("event type is motion: count {}", ++m[kKeyM]);
}else if(std::is_same<decltype(e), mpboth>::value){
rlogger->info("type is mpboth");
rlogger->info("event type is mpboth");
return true;
}else if(std::is_same<decltype(e), none>::value){
rlogger->info("type is none: {}", ++m[kKeyN]);
rlogger->info("event type is none: count {}", ++m[kKeyN]);
}
return false;
}
......@@ -89,9 +89,9 @@ namespace md{
hasMotion = 0;
timeStart = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
if(std::is_same<decltype(e), people>::value){
rlogger->info("none -p-> in, {}", timeStart/1000);
rlogger->info("event state transition: none (people) --> in, {}", timeStart/1000);
}else if(std::is_same<decltype(e), mpboth>::value){
rlogger->info("none -b-> in, {}", timeStart/1000);
rlogger->info("event state transition: none (both) --> in, {}", timeStart/1000);
hasMotion++;
}
......@@ -102,9 +102,9 @@ namespace md{
if(timeStart==0)
timeStart = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
if(std::is_same<decltype(e), people>::value){
rlogger->info("pre -p-> in: time {}", timeStart/1000);
rlogger->info("event state transition: pre (people) --> in, time {}", timeStart/1000);
}else if(std::is_same<decltype(e), mpboth>::value){
rlogger->info("pre -b-> in: time {}", timeStart/1000);
rlogger->info("event state transition: pre (both) --> in, time {}", timeStart/1000);
hasMotion++;
}
};
......@@ -122,12 +122,12 @@ namespace md{
const auto action_post2none = [this](auto e){
auto timeEnd = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
if(std::is_same<decltype(e), people>::value){
rlogger->info("post -p-> none, {}", timeEnd/1000);
rlogger->info("event state transition: post (people) --> none, {}", timeEnd/1000);
}else if(std::is_same<decltype(e), motion>::value){
hasMotion++;
rlogger->info("post -m-> none, {}", timeEnd/1000);
rlogger->info("event state transition: post (motion) --> none, {}", timeEnd/1000);
}else if(std::is_same<decltype(e), none>::value){
rlogger->info("post -n-> none, {}", timeEnd/1000);
rlogger->info("event state transition: post (none) --> none, {}", timeEnd/1000);
}
if(hasMotion >= 1) {
......@@ -183,21 +183,21 @@ namespace md{
using namespace sml;
return make_transition_table(
*"init"_s = "none"_s,
"none"_s + event<none>/[]{rlogger->info("none -> none");} = "none"_s,
"none"_s + event<motion>/[]{rlogger->info("none -m-> pre");} = "pre"_s,
"none"_s + event<none>/[]{/* don't print this transition */} = "none"_s,
"none"_s + event<motion>/[]{rlogger->info("event state transition: none (motion) --> pre");} = "pre"_s,
"none"_s + event<people>/action_none2in = "in"_s,
"none"_s + event<mpboth>/action_none2in = "in"_s,
// pre
"pre"_s + event<none>/[]{rlogger->info("pre -n-> none");} = "none"_s,
"pre"_s + event<none>/[]{rlogger->info("event state transition: pre (none) --> none");} = "none"_s,
"pre"_s + event<motion>/action_pre2pre = "pre"_s,
"pre"_s + event<people>/action_pre2in = "in"_s,
"pre"_s + event<mpboth>/action_pre2in = "in"_s,
// in
"in"_s + event<none> [guard_in2post]/[]{rlogger->info("in -n-> post");} = "post"_s,
"in"_s + event<motion> [guard_in2post]/[]{rlogger->info("in -m-> post");} = "post"_s,
"in"_s + event<people> [guard_in2post]/[]{rlogger->info("in -p-> post");} = "post"_s,
"in"_s + event<none> [guard_in2post]/[]{rlogger->info("event state transition: in (none) --> post");} = "post"_s,
"in"_s + event<motion> [guard_in2post]/[]{rlogger->info("event state transition: in (motion) --> post");} = "post"_s,
"in"_s + event<people> [guard_in2post]/[]{rlogger->info("event state transition: in (people) --> post");} = "post"_s,
"in"_s + event<mpboth>/guard_in2post,
"in"_s + sml::on_entry<_> / may_generate_event,
......
......@@ -31,7 +31,7 @@ extern "C" {
#define MAGIC_TAIL2 ((uint8_t)0xDE)
#define MAGIC_TAIL3 ((uint8_t)0xAD)
#define EV_UPLOAD_MAX_BUF_SIZE 1200
#define EV_UPLOAD_MAX_BUF_SIZE 1024
static const int kMaxHeapSize = 1 * 1024 * 1024;
using namespace std;
......@@ -53,6 +53,7 @@ string upload_video(string hostUrl, char* dev_sn, int64_t tss, int64_t tse, set<
{
string rc;
uint8_t * buf = (uint8_t *)malloc(EV_UPLOAD_MAX_BUF_SIZE);
rlogger->info("start uploading video of camera {} from {} to {}, total {} slices, type {}", dev_sn, tss, tse, slices.size(), type);
int s = 0;
try {
......@@ -66,10 +67,29 @@ string upload_video(string hostUrl, char* dev_sn, int64_t tss, int64_t tse, set<
rc = fmt::format("failed to connect to {}", hostUrl);
}
else {
/**
* META := SN_LEN, SN, START_TS, END_TS, TYPE, NUM, {FILE_META*NUM} # 元数据
SN_LEN := UINT16 # 摄像头SN长度 一般8字节
SN := {UINT8*SN_LEN} # 摄像头SN, 长度为SN_LEN
START_TS := TS # 事件开始时间
END_TS := TS # 事件结束时间
TYPE := UINT8 # 0 - 未定义, 1 - AI人形, 2 - AI人脸, 3 - 移动侦测,
# 4 - 覆盖, 5 - 覆盖解除, 6 - 视频获取
# 其他 - 由发起请求的微服务自定义
FILE_META := FILE_TS,SIZE
FILE_TS := TS # 文件开始时间
SIZE := UINT32 # 文件字节数
NUM := UINT32 # 4-byte unsigned int. 视频文件数目
TS := INT64 # 8-byte long. 时间戳
注意: 目前, 代码中写死了, SN 为 12 个字节.
**/
auto metaLen = 2 + 12 + 8 + 8 + 1 + 4 + (8 + 4)*slices.size();
// head : MAGIC_HEADD + META + CRC
auto headLen = 2 + metaLen + 2;
if(headLen > EV_UPLOAD_MAX_BUF_SIZE) {
rc = fmt::format("too many files to upload, ignored: {}", slices.size());
rc = fmt::format("too many files ({}) to upload such that header ({}) is too large, ignore uploading.", slices.size(), headLen);
}
else {
vector<uint32_t> fsize;
......@@ -122,9 +142,14 @@ string upload_video(string hostUrl, char* dev_sn, int64_t tss, int64_t tse, set<
totalLen +=2;
assert(totalLen = headLen);
rlogger->info("header len: {}, crc: {}", totalLen, crc_);
bool file_transfer_failed = false;
// send header
rc = raw_send(s, buf, totalLen);
if(!rc.empty()) {
file_transfer_failed = true;
rlogger->error("failed to send file header. err: " + rc);
rc = fmt::format("{}, {}:{}", rc, uri.Host, uri.Port);
}
else {
......@@ -135,13 +160,14 @@ string upload_video(string hostUrl, char* dev_sn, int64_t tss, int64_t tse, set<
uint32_t total_sent = 0;
auto fpath = string(consts::recFilePath) + to_string(k) + ".h264";
memcpy(buf, &fsize[idx], 4);
file_transfer_failed = false;
FILE *fp = fopen(fpath.c_str(), "rb");
if(!fp) {
rc = fmt::format("failed open file : {}", fpath);
break;
}
else {
rlogger->info("sending file {}: {}", fpath, fsize[idx]);
rlogger->info("sending file {}: size {}", fpath, fsize[idx]);
for(int i = 0; readsize > 0; i++) {
if(i == 0) {
readsize = ::fread(buf+4, 1, EV_UPLOAD_MAX_BUF_SIZE - 4, fp) + 4;
......@@ -153,6 +179,8 @@ string upload_video(string hostUrl, char* dev_sn, int64_t tss, int64_t tse, set<
if((i == 0 && readsize > 4) ||(i !=0 && readsize > 0)) {
rc = raw_send(s, buf, readsize);
if(!rc.empty()) {
file_transfer_failed = true;
rlogger->error("failed to send file data via socket. err: {}", rc);
break;
}
}
......@@ -169,6 +197,9 @@ string upload_video(string hostUrl, char* dev_sn, int64_t tss, int64_t tse, set<
rc = fmt::format("error read file: {}", strerror(errno));
rlogger->error(rc);
break;
} else if (file_transfer_failed){
rlogger->error("file transfer failed, skip rest file upload");
break;
}
else {
rlogger->info("sent file {}: total {}, sent {}", fpath, fsize[idx], total_sent - 4);
......@@ -177,18 +208,28 @@ string upload_video(string hostUrl, char* dev_sn, int64_t tss, int64_t tse, set<
idx++;
}
}
// construct tail
buf[0] = MATIC_TAIL0;
buf[1] = MAGIC_TAIL1;
buf[2] = MAGIC_TAIL2;
buf[3] = MAGIC_TAIL3;
rc = raw_send(s, buf, 4);
if (!file_transfer_failed){
rlogger->info("sending upload tail");
// construct tail
buf[0] = MATIC_TAIL0;
buf[1] = MAGIC_TAIL1;
buf[2] = MAGIC_TAIL2;
buf[3] = MAGIC_TAIL3;
rc = raw_send(s, buf, 4);
if(!rc.empty()){
rlogger->error("failed to send upload tail. err: {}", rc);
rc = fmt::format("upload tail error: {}", rc);
}
}
}
}
}
}
catch(exception &e) {
rc = fmt::format("failed to send to {}: {}, {}:{}", hostUrl, e.what(), __FILE__, __LINE__);
rc = fmt::format("exception sending file to {}: {}, {}:{}", hostUrl, e.what(), __FILE__, __LINE__);
}
free(buf);
......@@ -320,7 +361,7 @@ void upload_svc_entry(thread_upload_args_t *pArg)
bUpload = true;
}
if(bUpload) {
rlogger->info("waiting for job");
rlogger->debug("waiting for job");
}
{
unique_lock<mutex> lk(*pArg->mut);
......@@ -328,7 +369,7 @@ void upload_svc_entry(thread_upload_args_t *pArg)
}// lock released
if(got && pArg->que->size()> 0) {
rlogger->info("process one job, total left {}", pArg->que->size());
rlogger->info("process one upload job, total left {}", pArg->que->size());
auto elem = pArg->que->front();
pArg->que->pop();
......@@ -473,7 +514,13 @@ void remove_ts_file(int64_t ts)
fs::remove(fname);
}
// 0 - OK, -1: exception;
/**
* write to sd
* if immediate is false, copy to heap buffer, dump heap to file when the heap if full
* if immediate is true, directly write to file.
* return: 0 - OK, -1: exception;
*/
static int cached_sd_write(fstream *fp, char *buf, int sz, bool immediate = false)
{
int ret = 0;
......@@ -483,9 +530,9 @@ static int cached_sd_write(fstream *fp, char *buf, int sz, bool immediate = fals
try {
if(!immediate) {
if(current_heap_size + sz > kMaxHeapSize) {
rlogger->info("write full cached buffer to recording file. size {}", current_heap_size);
fp->write(heap_buff, current_heap_size);
current_heap_size = 0;
rlogger->info("cached_sd_write");
}
memcpy(heap_buff + current_heap_size, buf, sz);
......@@ -493,9 +540,11 @@ static int cached_sd_write(fstream *fp, char *buf, int sz, bool immediate = fals
}
else {
if(current_heap_size > 0) {
rlogger->info("write cached buffer to recording file. size {}", current_heap_size);
fp->write(heap_buff, current_heap_size);
current_heap_size = 0;
}
rlogger->info("write to recording file. size {}", sz);
fp->write(buf, sz);
}
}
......
......@@ -175,7 +175,7 @@ void maq_smart_task_entry(ev_module_config_t *pArg)
return;
}
rlogger->info("finished smart init");
rlogger->info("finished smart human detection initialization");
stCallback.eType = MAQUE_SMART_JPEG_ENCODE_LARGE;//MAQUE_SMART_JPEG_ENCODE_CUTOUT;
stCallback.eClass = MAQUE_SMART_JPEG_CLASS_PD;//MAQUE_SMART_JPEG_CLASS_FD;
......@@ -250,7 +250,7 @@ void maq_smart_task_entry(ev_module_config_t *pArg)
fsm.process_event(md::people{});
}
else {
rlogger->info("ai_task: deltaTimeMs {}, none", deltaTimeMs);
rlogger->debug("ai_task: deltaTimeMs {}, none", deltaTimeMs);
fsm.process_event(md::none{});
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论