| | |
| | | |
| | | import ( |
| | | "context" |
| | | "decoder/valib/goffmpeg" |
| | | "decoder/valib/ipc" |
| | | srv "decoder/work/service" |
| | | "encoding/json" |
| | |
| | | flag.BoolVar(&asServer, "server", false, "run ipc as server") |
| | | } |
| | | |
| | | // cameraInfo camera info |
| | | // CameraInfo camera info |
| | | type CameraInfo struct { |
| | | ID string `json:"Cameraid"` |
| | | URL string `json:"Rtsp"` |
| | |
| | | |
| | | var ( |
| | | mapCameraInfo = make(map[string]CameraInfo) |
| | | |
| | | tcp = `tcp://192.168.1.124:` |
| | | port = 7001 |
| | | ) |
| | | |
| | | func recvCameraInfoFromIPC(ctx context.Context, url string, ch chan<- CameraInfo) { |
| | |
| | | |
| | | ch <- c |
| | | |
| | | msgIpc := MsgIPC{"new decoder", port} |
| | | msgIpc := MsgIPC{"new decoder", 0} |
| | | if b, err := json.Marshal(msgIpc); err == nil { |
| | | ipc.Send(b) |
| | | } |
| | |
| | | func main() { |
| | | flag.Parse() |
| | | |
| | | if testIt { |
| | | test() |
| | | } |
| | | goffmpeg.InitFFmpeg() |
| | | |
| | | ctx, cancel := context.WithCancel(context.Background()) |
| | | |
| | | if testIt { |
| | | test(ctx) |
| | | } |
| | | |
| | | ch := make(chan CameraInfo) |
| | | // tcpURL := tcp + strconv.Itoa(port) |
| | | // port++ |
| | | |
| | | tcp := `` |
| | | port := 7001 |
| | | |
| | | if strings.Index(ipcURL, "tcp://") == 0 { |
| | | i := strings.LastIndex(ipcURL, ":") |
| | | tcp = ipcURL[0 : i+1] |
| | | |
| | | strPort := ipcURL[i+1:] |
| | | port, _ = strconv.Atoi(strPort) |
| | | port++ |
| | | } |
| | | |
| | | go recvCameraInfoFromIPC(ctx, ipcURL, ch) |
| | | |
| | | for { |
| | |
| | | url := strings.TrimSpace(c.URL) |
| | | id := strings.TrimSpace(c.ID) |
| | | addr := strings.TrimSpace(ipcAddr) |
| | | go runSender(id, url, addr) |
| | | go runSender(ctx, id, url, addr) |
| | | } |
| | | } |
| | | } |
| | | |
| | | goffmpeg.FreeFFmpeg() |
| | | cancel() |
| | | } |
| | | |
| | | func runSender(cameraID, rtspURL, ipcLabel string) { |
| | | d := srv.NewSender(cameraID, rtspURL, ipcLabel) |
| | | func runSender(ctx context.Context, cameraID, rtspURL, ipcLabel string) { |
| | | d := srv.NewSender(ctx, cameraID, rtspURL, ipcLabel) |
| | | if asServer { |
| | | d.RunAsServer() |
| | | } |
| | | d.RunAsClient() |
| | | } |
| | | |
| | | func test() { |
| | | func test(ctx context.Context) { |
| | | fmt.Println("start test") |
| | | |
| | | fmt.Println(picFolder) |
| | | |
| | | runSender("cameraid", streamURL, ipcURL) |
| | | runSender(ctx, "cameraid", streamURL, ipcURL) |
| | | } |