视频分析2.0 多进程拆分仓库
zhangmeng
2019-05-08 19445d14e73f4bb96e218a65e126ae526f89537d
decoder/work/service/ipcsender.go
@@ -12,7 +12,7 @@
// Sender decoder ingo
type Sender struct {
   ctxIPC *ContextIPC
   ctx context.Context
   cameraID  string
   streamURL string
@@ -22,13 +22,12 @@
}
// NewSender Sender
func NewSender(cameraID, streamURL, ipcURL string) *Sender {
   ctx, cancel := context.WithCancel(context.Background())
func NewSender(ctx context.Context, cameraID, streamURL, ipcURL string) *Sender {
   fmt.Printf("create ipc %s for decode : %s, on camera id %s\n", ipcURL, streamURL, cameraID)
   return &Sender{
      ctxIPC: &ContextIPC{ctx, cancel},
      ctx: ctx,
      cameraID:  cameraID,
      streamURL: streamURL,
@@ -39,7 +38,7 @@
func (s *Sender) serializeImageInfo(img <-chan ImageInfo, data chan<- []byte) {
   for {
      select {
      case <-s.ctxIPC.ctx.Done():
      case <-s.ctx.Done():
         fmt.Println("stop Sender")
         return
      case i := <-img:
@@ -80,10 +79,9 @@
            img := ImageInfo{Data: data, Width: wid, Height: hei}
            ch <- img
         } else {
            time.Sleep(time.Millisecond * time.Duration(10))
            time.Sleep(time.Millisecond * time.Duration(20))
         }
      }
   }(gf, imageChan)
   gf.Run(s.streamURL)
@@ -93,7 +91,7 @@
// RunAsServer run a IPC server
func (s *Sender) RunAsServer() {
   i := ipc.NewServer(s.ctxIPC.ctx, s.ipcURL)
   i := ipc.NewServer(s.ctx, s.ipcURL)
   fmt.Println("ipc :", s.ipcURL, " cameraid:", s.cameraID)
   s.run(i)
@@ -101,13 +99,7 @@
// RunAsClient run as a IPC client
func (s *Sender) RunAsClient() {
   i := ipc.NewClient(s.ctxIPC.ctx, s.ipcURL)
   i := ipc.NewClient(s.ctx, s.ipcURL)
   fmt.Println("ipc :", s.ipcURL, " cameraid:", s.cameraID)
   s.run(i)
}
// Stop stop run decoder, must run in goroutine
func (s *Sender) Stop() {
   s.ffmpeg.Free()
   s.ctxIPC.cancel()
}