提交 0b173acb authored 作者: blu's avatar blu

video upload prototype

上级 5e950222
No preview for this file type
......@@ -79,3 +79,7 @@ payload: {
```json
{ "time":1567669674, "cmd":"upload_video", "rid":"001231554A20", "data":{ "start":1590542800, "end":1590542900, "type":6 } }
```
......@@ -33,7 +33,7 @@ sequenceDiagram
## 数据格式定义(DD)
### STREAM_DATA_T: 端在前
### STREAM_DATA_T: 端在前
```BNF
STREAM_DATA_T := MAGIC_HEAD, {PAYLOAD}-, MAGIC_TAIL # 总体定义
......
差异被折叠。
......@@ -22,8 +22,10 @@ namespace md{
const string kKeyM= "m";
const string kKeyN= "n";
const string kKeyP= "p";
const int kMaxCntMotionInPre = 5; // about 20s
/// helpers
auto event_inspection(auto e, std::map<std::string,int> &m){
auto event_inspection(auto e, std::map<const std::string, int> &m){
if(std::is_same<decltype(e), people>::value){
spdlog::info("type is people: {}", ++m[kKeyP]);
}else if(std::is_same<decltype(e), motion>::value){
......@@ -37,9 +39,9 @@ namespace md{
return false;
}
auto make_guard_fn(const std::map<const std::string, int> &konst){
return [&konst](auto e){
static std::map<const std::string, int>guards = {{"m", 0}, {"p", 0}, {"n", 0}};
auto make_guard_fn(const std::map<const std::string, int> &konst, std::map<const std::string, int> &guards ){
return [&konst, &guards](auto e){
//static std::map<const std::string, int>guards = {{"m", 0}, {"p", 0}, {"n", 0}};
bool trans = false;
bool reset = true;
if(event_inspection(e, guards)||(guards[kKeyM] != 0 && guards[kKeyP] != 0)){
......@@ -63,82 +65,56 @@ namespace md{
};
}
typedef bool (*fn_guard_t)(auto e);
struct fsm {
const fn_guard_t guard_in2post = make_guard_fn(kNumIn2Post);
const bool guard_post2none = make_guard_fn(kNumPost2None);
const void action_none2in = [this](auto e){
this->timeStart = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
if(std::is_same<decltype(e), people>::value){
spdlog::info("none -p-> in, {}", this->timeStart/1000);
}else if(std::is_same<decltype(e), mpboth>::value){
spdlog::info("none -b-> in, {}", this->timeStart/1000);
this->hasMotion = true;
}
};
const void action_pre2in = [this](auto e){
if(this->timeStart==0)
this->timeStart = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
if(std::is_same<decltype(e), people>::value){
spdlog::info("pre -p-> in: time {}", this->timeStart/1000);
}else if(std::is_same<decltype(e), mpboth>::value){
spdlog::info("pre -b-> in: time {}", this->timeStart/1000);
}
this->hasMotion = true;
};
const void 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){
spdlog::info("post -p-> none, {}", timeEnd/1000);
}else if(std::is_same<decltype(e), motion>::value){
spdlog::info("post -m-> none, {}", timeEnd/1000);
}else if(std::is_same<decltype(e), none>::value){
spdlog::info("post -n-> none, {}", timeEnd/1000);
}
};
const void action_pre2pre = [this](auto e){
static int cntMotionOnly = 0;
cntMotionOnly++;
if(cntMotionOnly >= kMaxCntMotionInPre) {
cntMotionOnly = 0;
this->timeStart = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
}
};
auto operator()() noexcept{
const auto guard_in2post = make_guard_fn(kNumIn2Post, guards);
const auto guard_post2none = make_guard_fn(kNumPost2None, guards);
const auto action_none2in = [this](auto e){
hasMotion = false;
timeStart = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
if(std::is_same<decltype(e), people>::value){
spdlog::info("none -p-> in, {}", timeStart/1000);
}else if(std::is_same<decltype(e), mpboth>::value){
spdlog::info("none -b-> in, {}", timeStart/1000);
hasMotion = true;
}
inline auto operator()() noexcept{
using namespace sml;
=======
}else if(std::is_same<decltype(e), none>::value){
spdlog::info("type is none: {}", ++m[kKeyN]);
}
}
/// TODO: force event generation when max time duration reached
auto make_guard_fn(const std::map<std::string,int> &konst){
return [&konst](auto e){
static std::map<std::string, int>guards = {{"m", 0}, {"p", 0}, {"n", 0}};
event_inspection(e, guards);
if(guards[kKeyM] != 0 && guards[kKeyP] != 0){
guards[kKeyM] = guards[kKeyP] = guards[kKeyN] = 0;
return false;
}else if(guards[kKeyP] >= konst[kKeyP]){
guards[kKeyP]=guards[kKeyN]= 0;
return true;
}else if(guards[kKeyM] >= konst[kKeyM]){
guards[kKeyM]=guards[kKeyN] = 0;
return true;
}else if(guards[kKeyN] >= konst[kKeyN]){
guards[kKeyN] = 0;
return true;
}
return false;
};
}
};
const auto action_pre2in = [this](auto e){
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){
spdlog::info("pre -p-> in: time {}", timeStart/1000);
}else if(std::is_same<decltype(e), mpboth>::value){
spdlog::info("pre -b-> in: time {}", timeStart/1000);
}
hasMotion = true;
};
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){
spdlog::info("post -p-> none, {}", timeEnd/1000);
}else if(std::is_same<decltype(e), motion>::value){
spdlog::info("post -m-> none, {}", timeEnd/1000);
}else if(std::is_same<decltype(e), none>::value){
spdlog::info("post -n-> none, {}", timeEnd/1000);
}
struct fsm {
auto operator()()const noexcept {
/// TODO: force event generation when max time duration reached
spdlog::info("event start:{}, end:{}, hasMotion: {}", timeStart, timeEnd, hasMotion);
/// TODO: generate event for uploading
};
const auto action_pre2pre = [this](auto e){
cntMotionOnly++;
if(cntMotionOnly >= kMaxCntMotionInPre) {
cntMotionOnly = 0;
timeStart = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
}
};
using namespace sml;
const auto guard_in2post = make_guard_fn(kNumIn2Post);
const auto guard_post2none = make_guard_fn(kNumPost2None);
return make_transition_table(
*"init"_s = "none"_s,
"none"_s + event<none>/[]{spdlog::info("none -> none");} = "none"_s,
......@@ -163,9 +139,11 @@ namespace md{
"none"_s + sml::on_entry<_> / [this]{hasMotion = false,timeStart = 0;}
);
}
public:
bool hasMotion = false;
uint64_t timeStart =0;
private:
bool hasMotion{false};
int cntMotionOnly = 0;
uint64_t timeStart{0};
std::map<const std::string, int>guards{{"m", 0}, {"p", 0}, {"n", 0}};
};
}
......
......@@ -40,7 +40,6 @@ XM_S32 MaQue_JpegEnc_getFrame_callback (XM_VOID *pUserArg, MaQueSmartJpegFrame_s
}
void maq_smart_task_entry(ev_module_config_t *pArg)
{
if(!pArg->module.ai.enabled) {
......@@ -173,7 +172,6 @@ void maq_smart_task_entry(ev_module_config_t *pArg)
extern atomic<uint64_t> frameCntTotal;
uint64_t frameCntLast = frameCntTotal.load(memory_order_relaxed);
uint64_t motionCntLast = gMotionCounter.load(memory_order_relaxed);
<<<<<<< HEAD
const float kMotionPerSecondThresh = 2.5;
const int kMotionDetectWindowSeconds = 4;
const float kMsPerMotion = 1000.0/kMotionPerSecondThresh;
......@@ -181,15 +179,6 @@ void maq_smart_task_entry(ev_module_config_t *pArg)
int windowSecs = kMotionDetectWindowSeconds;
ev_region_t last_region = {0};
sml::sm<md::fsm> fsm{md::fsm{}};
=======
const int kMotionPerSecondThresh = 3;
const int kMotionDetectWindowSeconds = 4;
const float kMsPerMotion = kMotionDetectWindowSeconds*1000.0/kMotionPerSecondThresh;
int state = 0;
int windowSecs = kMotionDetectWindowSeconds;
ev_region_t last_region = {0};
sml::sm<md::fsm> fsm;
>>>>>>> 5b92158f6b6f54d698af4a1f24b2fcd7b03b5f5d
bool hasHuman = false;
bool hasMotion = false;
while(1) {
......@@ -207,11 +196,7 @@ void maq_smart_task_entry(ev_module_config_t *pArg)
}
if (stMaQueSmartTarget.targetFDNum > 0) {
hasHuman = true;
<<<<<<< HEAD
//last_region = {stMaQueSmartTarget.aFDRect[0].s16X1, stMaQueSmartTarget.aFDRect[0].s16Y1, stMaQueSmartTarget.aFDRect[0].s16X2, stMaQueSmartTarget.aFDRect[0].s16Y2};
=======
last_region = {stMaQueSmartTarget.aFDRect[0].s16X1, stMaQueSmartTarget.aFDRect[0].s16Y1, stMaQueSmartTarget.aFDRect[0].s16X2, stMaQueSmartTarget.aFDRect[0].s16Y2};
>>>>>>> 5b92158f6b6f54d698af4a1f24b2fcd7b03b5f5d
}
if(windowSecs > 0) {
windowSecs--;
......@@ -219,19 +204,15 @@ void maq_smart_task_entry(ev_module_config_t *pArg)
else {
auto frameCntTotal_ = frameCntTotal.load(memory_order_relaxed);
auto motionCnt_ = gMotionCounter.load(memory_order_relaxed);
float deltaTimeMs = (frameCntTotal_ - frameCntLast) * 1000/pArg->module.sys.fps;
<<<<<<< HEAD
spdlog::info("deltaTimeMs {}", deltaTimeMs);
=======
>>>>>>> 5b92158f6b6f54d698af4a1f24b2fcd7b03b5f5d
frameCntLast = frameCntTotal_;
int motionCntThresh = deltaTimeMs / kMsPerMotion;
int deltaMotionCnt = motionCnt_ - motionCntLast;
motionCntLast = motionCnt_;
spdlog::info("deltaTimeMs {}", deltaTimeMs);
if(deltaMotionCnt >= motionCntThresh) {
hasMotion = true;
<<<<<<< HEAD
}
if(hasMotion && hasHuman) {
fsm.process_event(md::mpboth{});
......@@ -243,26 +224,13 @@ void maq_smart_task_entry(ev_module_config_t *pArg)
fsm.process_event(md::people{});
}
else {
=======
}
if(hasMotion && hasHuman){
fsm.process_event(md::mpboth{});
}else if(hasMotion){
fsm.process_event(md::motion{});
}else if(hasHuman){
fsm.process_event(md::people{});
}else{
>>>>>>> 5b92158f6b6f54d698af4a1f24b2fcd7b03b5f5d
fsm.process_event(md::none{});
}
// reset
windowSecs = kMotionDetectWindowSeconds;
hasHuman = false;
hasMotion = false;
<<<<<<< HEAD
last_region = {0,0,0,0};
=======
>>>>>>> 5b92158f6b6f54d698af4a1f24b2fcd7b03b5f5d
}
}
......
......@@ -18,6 +18,8 @@ link_directories(${COMMON_LIB_DIR})
add_executable(vgw videogateway.cc)
target_link_libraries(vgw PUBLIC ${VGW_LIBS} ${COMM_LIBS})
add_executable(test_curl test_curl.cc)
target_link_libraries(vgw curl})
# add_executable(test_mqtt test_mqtt_rd.cc)
# target_link_libraries(test_mqtt PUBLIC ${COMM_LIBS})
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论