From db20b766e2020950ed64a89065c8599a2ad69ff2 Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期二, 14 一月 2020 18:01:12 +0800 Subject: [PATCH] update --- run.go | 61 +++++++++++++++++------------- 1 files changed, 34 insertions(+), 27 deletions(-) diff --git a/run.go b/run.go index bda030f..50cf58f 100644 --- a/run.go +++ b/run.go @@ -6,14 +6,14 @@ "sync" "time" - "basic.com/libgowrapper/sdkhelper.git" + "face/common" "basic.com/libgowrapper/sdkstruct.git" "basic.com/pubsub/protomsg.git" "basic.com/valib/gogpu.git" ) -const maxTryBeforeReboot = 30 +const maxTryBeforeReboot = 10 type face struct { handle *SDKFace @@ -57,7 +57,9 @@ } else { f.rebootUntil++ + f.fnLogger("Face No Running: ", f.rebootUntil) if f.rebootUntil > maxTryBeforeReboot { + f.fnLogger("Face Too Long Running, Reboot") os.Exit(0) } } @@ -74,7 +76,7 @@ fn("Face SDK Create Error When New SDK") return nil } - cfg, err := sdkhelper.ReadConfig(config) + cfg, err := common.ReadConfig(config) if err != nil { fn("Face SDK Create Error When Read Config: ", err) return nil @@ -102,9 +104,9 @@ } w, h, detThrd, detNum, detAngle, propThrd, extThrd, trckInterval, trckSmpl, maxChan, gpuM := - 1280, 720, sdkhelper.Atoi(cfg.Param[dt]), sdkhelper.Atoi(cfg.Param[dn]), sdkhelper.Atoi(cfg.Param[da]), - sdkhelper.Atoi(cfg.Param[pt]), sdkhelper.Atoi(cfg.Param[et]), sdkhelper.Atoi(cfg.Param[ti]), sdkhelper.Atoi(cfg.Param[ts]), - sdkhelper.Atoi(cfg.Param[mc]), sdkhelper.Atoi(cfg.Param[gm]) + 1280, 720, common.Atoi(cfg.Param[dt]), common.Atoi(cfg.Param[dn]), common.Atoi(cfg.Param[da]), + common.Atoi(cfg.Param[pt]), common.Atoi(cfg.Param[et]), common.Atoi(cfg.Param[ti]), common.Atoi(cfg.Param[ts]), + common.Atoi(cfg.Param[mc]), common.Atoi(cfg.Param[gm]) if detAngle > 0 { } @@ -155,6 +157,12 @@ } } +func (f *face) release() { + if f.handle != nil { + f.handle.Free() + } +} + // Run run func Run(ctx context.Context, i interface{}) { s := i.(*face) @@ -163,14 +171,14 @@ postPull = `_1` postPush = `_2` ) - ipcRcv := sdkhelper.GetIpcAddress(s.shm, s.id+postPull) - ipcSnd := sdkhelper.GetIpcAddress(s.shm, s.id+postPush) - chRcv := make(chan []byte) - chSnd := make(chan sdkstruct.MsgSDK) + ipcRcv := common.GetIpcAddress(s.shm, s.id+postPull) + ipcSnd := common.GetIpcAddress(s.shm, s.id+postPush) + chRcv := make(chan []byte, s.maxChannel) + chSnd := make(chan sdkstruct.MsgSDK, s.maxChannel) - rcver := sdkhelper.NewReciever(ipcRcv, chRcv, s.shm, s.fnLogger) - snder := sdkhelper.NewSender(ipcSnd, chSnd, s.shm, s.fnLogger) - torule := sdkhelper.NewToRule(s.ipc2Rule, s.ruleMsgMaxCacheSize, s.fnLogger) + rcver := common.NewReciever(ipcRcv, chRcv, s.shm, s.fnLogger) + snder := common.NewSender(ipcSnd, chSnd, s.shm, s.fnLogger) + torule := common.NewToRule(s.ipc2Rule, s.ruleMsgMaxCacheSize, s.fnLogger) snder.ApplyCallbackFunc(torule.Push) @@ -185,7 +193,6 @@ ////////////////////////////////////////////////////////////////// const ( - cacheFrameNum = 3 trackChnTimeout = time.Duration(10) ) @@ -218,8 +225,8 @@ func (f *face) run(ctx context.Context, in <-chan []byte, out chan<- sdkstruct.MsgSDK) { - chMsg := make(chan protomsg.SdkMessage) - go sdkhelper.UnserilizeProto(ctx, in, chMsg, f.fnLogger) + chMsg := make(chan protomsg.SdkMessage, f.maxChannel) + go common.UnserilizeProto(ctx, in, chMsg, f.fnLogger) for { select { @@ -227,9 +234,9 @@ f.handle.Free() return case rMsg := <-chMsg: - if !sdkhelper.ValidRemoteMessage(rMsg, f.typ, f.fnLogger) { + if !common.ValidRemoteMessage(rMsg, f.typ, f.fnLogger) { f.fnLogger("FACE TRACK VALIDREMOTEMESSAGE INVALID") - sdkhelper.EjectResult(nil, rMsg, out) + common.EjectResult(nil, rMsg, out) continue } @@ -238,18 +245,18 @@ f.ftrackChans[rMsg.Cid] <- rMsg } else { - f.ftrackChans[rMsg.Cid] = make(chan protomsg.SdkMessage, cacheFrameNum) + f.ftrackChans[rMsg.Cid] = make(chan protomsg.SdkMessage, f.maxChannel) chn := f.getAvailableChn() if chn < 0 { f.fnLogger("TOO MUCH CHANNEL") - sdkhelper.EjectResult(nil, rMsg, out) + common.EjectResult(nil, rMsg, out) continue } f.ftrackChannels[rMsg.Cid] = chn - i := sdkhelper.UnpackImage(rMsg, f.typ, f.fnLogger) + i := common.UnpackImage(rMsg, f.typ, f.fnLogger) if i == nil { - sdkhelper.EjectResult(nil, rMsg, out) + common.EjectResult(nil, rMsg, out) continue } // conv to bgr24 and resize @@ -278,14 +285,14 @@ case rMsg := <-in: - if !sdkhelper.ValidRemoteMessage(rMsg, f.typ, f.fnLogger) { - sdkhelper.EjectResult(nil, rMsg, out) + if !common.ValidRemoteMessage(rMsg, f.typ, f.fnLogger) { + common.EjectResult(nil, rMsg, out) continue } - i := sdkhelper.UnpackImage(rMsg, f.typ, f.fnLogger) + i := common.UnpackImage(rMsg, f.typ, f.fnLogger) if i == nil || i.Data == nil || i.Width <= 0 || i.Height <= 0 { - sdkhelper.EjectResult(nil, rMsg, out) + common.EjectResult(nil, rMsg, out) continue } @@ -298,7 +305,7 @@ count, data, _ := f.handle.Run(i.Data, imgW, imgH, 3, dtchn) - sdkhelper.EjectResult(data, rMsg, out) + common.EjectResult(data, rMsg, out) f.mtxRunning.Lock() f.running = true f.mtxRunning.Unlock() -- Gitblit v1.8.0