视频分析2.0 多进程拆分仓库
zhangmeng
2019-05-07 1875d1339590ca97de50bd8f19a22e8801631263
decoder/work/service/ipcsender.go
@@ -24,6 +24,8 @@
func NewSender(cameraID, streamURL, ipcURL string) *Sender {
   ctx, cancel := context.WithCancel(context.Background())
   fmt.Printf("create ipc %s for decode : %s, on camera id %s\n", ipcURL, streamURL, cameraID)
   return &Sender{
      ctxIPC: &ContextIPC{ctx, cancel},
@@ -49,6 +51,7 @@
         }
         b := buf.Bytes()
         data <- b
         fmt.Printf("send %d length data ipc address %s\n", len(b), s.ipcURL)
      }
   }
@@ -66,26 +69,29 @@
   gf.ActiveDecoder(func(d *[]byte, w, h *int) {
      if *w > 0 && *h > 0 {
         i := ImageInfo{*d, *w, *h, s.cameraID}
         imageChan <- i
         img := ImageInfo{*d, *w, *h}
         imageChan <- img
      } else {
         fmt.Println("decode jpg error")
      }
   })
   gf.Run(s.streamURL)
   i.SendFromChannel(dataChan)
}
// RunAsServer run a IPC server
func (s *Sender) RunAsServer() {
   s.run(ipc.NewServer(s.ctxIPC.ctx, s.ipcURL))
   i := ipc.NewServer(s.ctxIPC.ctx, s.ipcURL)
   fmt.Println("ipc :", s.ipcURL, " cameraid:", s.cameraID)
   s.run(i)
}
// RunAsClient run as a IPC client
func (s *Sender) RunAsClient() {
   s.run(ipc.NewClient(s.ctxIPC.ctx, s.ipcURL))
   i := ipc.NewClient(s.ctxIPC.ctx, s.ipcURL)
   fmt.Println("ipc :", s.ipcURL, " cameraid:", s.cameraID)
   s.run(i)
}
// Stop stop run decoder, must run in goroutine