| | |
| | | package sdk |
| | | |
| | | import ( |
| | | "fmt" |
| | | // "golang.org/x/sys/unix" |
| | | |
| | | "github.com/gogo/protobuf/proto" |
| | | "taskpubsub/tasktag" |
| | | "taskpubsub/util" |
| | | |
| | | "github.com/gogo/protobuf/proto" |
| | | |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/valib/deliver.git" |
| | | "taskpubsub/logger" |
| | | "basic.com/valib/logger.git" |
| | | ) |
| | | |
| | | const ( |
| | |
| | | } |
| | | |
| | | func initInnerTopic() { |
| | | for _, sendTopic := range innerSendTopic { |
| | | createSdkSendServerAndListen(sendTopic) |
| | | } |
| | | // for _, sendTopic := range innerSendTopic { |
| | | // createSdkSendServerAndListen(sendTopic) |
| | | // } |
| | | |
| | | for _, recvTopic := range innerRecvTopic { |
| | | createSdkRecvServerAndListen(recvTopic) |
| | | } |
| | | // for _, recvTopic := range innerRecvTopic { |
| | | // createSdkRecvServerAndListen(recvTopic) |
| | | // } |
| | | } |
| | | |
| | | func Init(useShm bool) { |
| | |
| | | logger.Info("create", id) |
| | | } |
| | | |
| | | url := fmt.Sprintf("ipc:///tmp/%s%s.ipc", id, postPush) |
| | | url := "ipc:///tmp/" + id + postPush + ".ipc" |
| | | m := deliver.PushPull |
| | | if shm{ |
| | | if shm { |
| | | m = deliver.Shm |
| | | url = id + postPush |
| | | // unix.Unlink("/dev/shm/" + url) |
| | | } |
| | | |
| | | logger.Info("SDK URL: ", url) |
| | | |
| | | socket, err := util.NewSocketListen(int(m), url, shm) |
| | | if err != nil { |
| | | delete(SdkMap, id) |
| | |
| | | logger.Info("create", id) |
| | | } |
| | | |
| | | url := fmt.Sprintf("ipc:///tmp/%s%s.ipc", id, postPull) |
| | | url := "ipc:///tmp/" + id + postPull + ".ipc" |
| | | m := deliver.PushPull |
| | | if shm{ |
| | | if shm { |
| | | m = deliver.Shm |
| | | url = id + postPull |
| | | |
| | | // unix.Unlink("/dev/shm/" + url) |
| | | } |
| | | |
| | | socket, err := util.NewSocketListen(int(m), url, shm) |
| | |
| | | func GetSdkSendTopic(sdkmsg protomsg.SdkMessage) (sendTopic string) { |
| | | if int(sdkmsg.Tasklab.Index) < len(sdkmsg.Tasklab.Sdkinfos) { |
| | | sendTopic = sdkmsg.Tasklab.Sdkinfos[sdkmsg.Tasklab.Index].Ipcid |
| | | if "Yolo" != sdkmsg.Tasklab.Sdkinfos[sdkmsg.Tasklab.Index].Sdktype && |
| | | "FaceDetect" != sdkmsg.Tasklab.Sdkinfos[sdkmsg.Tasklab.Index].Sdktype && |
| | | "FaceCompare" != sdkmsg.Tasklab.Sdkinfos[sdkmsg.Tasklab.Index].Sdktype { |
| | | //if sdkmsg.Tasklab.Sdkinfos[sdkmsg.Tasklab.Index].Sdktype == "" { |
| | | logger.Info("----------Sdktype:yitusoutu") |
| | | logger.Info("分发的主题:", sendTopic, "!Sdktype:", sdkmsg.Tasklab.Sdkinfos[sdkmsg.Tasklab.Index].Sdktype) |
| | | } |
| | | } else { |
| | | sendTopic = "es" |
| | | } |
| | | logger.Debug("分发的主题: ", sendTopic, "位置:", int(sdkmsg.Tasklab.Index)+1, "/", len(sdkmsg.Tasklab.Sdkinfos)) |
| | | return |
| | | |
| | | return sendTopic |
| | | } |
| | | |
| | | func Recv(socket util.SocketContext) { |
| | | |
| | | tryCount := 0 |
| | | |
| | | var repsdkmsg = protomsg.SdkMessage{} |
| | | for { |
| | | select { |
| | | case <-socket.Context.Done(): |
| | | socket.Sock.Close() |
| | | |
| | | logger.Info("socket close") |
| | | return |
| | | default: |
| | | if msg, err := socket.Sock.Recv(); err != nil { |
| | | |
| | | // tryCount++ |
| | | // socket = util.MaybeRestartSocket(socket, &tryCount) |
| | | |
| | | if socket.UseSHM { |
| | | if tryCount > util.ShmMaxTryCount { |
| | | socket.Sock.Close() |
| | | socket, err = util.NewSocketListen(socket.Mode, socket.URL, socket.UseSHM) |
| | | logger.Info("SDK SEND SHM TRY :", util.ShmMaxTryCount, " RESTART IT") |
| | | tryCount = 0 |
| | | continue |
| | | } |
| | | tryCount++ |
| | | } |
| | | continue |
| | | } else { |
| | | err = proto.Unmarshal(msg, &repsdkmsg) |
| | |
| | | repsdkmsg.Tasklab.Index++ |
| | | //调用计算函数, 分发给下一个主题 |
| | | nexttopic := GetSdkSendTopic(repsdkmsg) |
| | | if "facedetect-sdk-no-track" == nexttopic || "virtual-faceextract-sdk-pull" == nexttopic { |
| | | logger.Info("nexttopic:", nexttopic) |
| | | } |
| | | SdkMap[nexttopic] <- repsdkmsg |
| | | } |
| | | } |
| | |
| | | |
| | | func Send(sdkid string, socket util.SocketContext, in chan protomsg.SdkMessage) { |
| | | |
| | | tryCount := 0 |
| | | |
| | | for { |
| | | select { |
| | | case <-socket.Context.Done(): |
| | | socket.Sock.Close() |
| | | |
| | | logger.Info("socket is close") |
| | | return |
| | | case v, ok := <-in: |
| | |
| | | } |
| | | |
| | | if err := socket.Sock.Send(data); err != nil { |
| | | logger.Error("failed send:sdkid=", sdkid) |
| | | if "facedetect-sdk-no-track" == sdkid || "virtual-faceextract-sdk-pull" == sdkid { |
| | | logger.Error("failed send:sdkid=", sdkid) |
| | | } |
| | | |
| | | // tryCount++ |
| | | // socket = util.MaybeRestartSocket(socket, &tryCount) |
| | | |
| | | if socket.UseSHM { |
| | | if tryCount > util.ShmMaxTryCount { |
| | | socket.Sock.Close() |
| | | socket, err = util.NewSocketListen(socket.Mode, socket.URL, socket.UseSHM) |
| | | logger.Info("SDK SEND SHM TRY :", util.ShmMaxTryCount, " RESTART IT") |
| | | tryCount = 0 |
| | | continue |
| | | } |
| | | tryCount++ |
| | | } |
| | | |
| | | continue |
| | | } |
| | | logger.Debug(sdkid, " send success: ", len(data)) |
| | | if "facedetect-sdk-no-track" == sdkid || "virtual-faceextract-sdk-pull" == sdkid { |
| | | logger.Info(sdkid, " send success: ", len(data)) |
| | | } |
| | | } else { |
| | | logger.Debug(sdkid, " 主题关闭, 关闭send()") |
| | | return |