diff --git a/cmd/rc-display/rc-display.go b/cmd/rc-display/rc-display.go index dc90648..b6179a4 100644 --- a/cmd/rc-display/rc-display.go +++ b/cmd/rc-display/rc-display.go @@ -4,6 +4,7 @@ import ( "flag" "github.com/cyrilix/robocar-base/cli" "github.com/cyrilix/robocar-display/part" + "github.com/cyrilix/robocar-display/video" "log" "os" ) @@ -14,6 +15,8 @@ const ( func main() { var mqttBroker, username, password, clientId string + var framePath string + var fps int var frameTopic, objectsTopic, roadTopic string var withObjects, withRoad bool @@ -23,6 +26,8 @@ func main() { cli.InitMqttFlags(DefaultClientId, &mqttBroker, &username, &password, &clientId, &mqttQos, &mqttRetain) flag.StringVar(&frameTopic, "mqtt-topic-frame", os.Getenv("MQTT_TOPIC_FRAME"), "Mqtt topic that contains frame to display, use MQTT_TOPIC_FRAME if args not set") + flag.StringVar(&framePath, "frame-path", "", "Directory path where to read jpeg frame to inject in frame topic") + flag.IntVar(&fps, "frame-per-second", 25, "Video frame per second of frame to publish") flag.StringVar(&objectsTopic, "mqtt-topic-objects", os.Getenv("MQTT_TOPIC_OBJECTS"), "Mqtt topic that contains detected objects, use MQTT_TOPIC_OBJECTS if args not set") flag.BoolVar(&withObjects, "with-objects", false, "Display detected objects") @@ -42,6 +47,17 @@ func main() { } defer client.Disconnect(50) + if framePath != "" { + camera, err := video.NewCameraFake(client, frameTopic, framePath, fps) + if err != nil { + log.Fatalf("unable to load fake camera: %v", err) + } + if err = camera.Start(); err != nil { + log.Fatalf("unable to start fake camera: %v", err) + } + defer camera.Stop() + } + p := part.NewPart(client, frameTopic, objectsTopic, roadTopic, withObjects, withRoad ) diff --git a/video/testdata/video/image_array_000000001.jpg b/video/testdata/video/image_array_000000001.jpg new file mode 100644 index 0000000..4cda87b Binary files /dev/null and b/video/testdata/video/image_array_000000001.jpg differ diff --git a/video/testdata/video/image_array_000000002.jpg b/video/testdata/video/image_array_000000002.jpg new file mode 100644 index 0000000..e892dee Binary files /dev/null and b/video/testdata/video/image_array_000000002.jpg differ diff --git a/video/testdata/video/image_array_000000003.jpg b/video/testdata/video/image_array_000000003.jpg new file mode 100644 index 0000000..efc5a8e Binary files /dev/null and b/video/testdata/video/image_array_000000003.jpg differ diff --git a/video/testdata/video/image_array_000000004.jpg b/video/testdata/video/image_array_000000004.jpg new file mode 100644 index 0000000..d732dce Binary files /dev/null and b/video/testdata/video/image_array_000000004.jpg differ diff --git a/video/testdata/video/image_array_000000005.jpg b/video/testdata/video/image_array_000000005.jpg new file mode 100644 index 0000000..75ef325 Binary files /dev/null and b/video/testdata/video/image_array_000000005.jpg differ diff --git a/video/testdata/video/image_array_000000006.jpg b/video/testdata/video/image_array_000000006.jpg new file mode 100644 index 0000000..17f3668 Binary files /dev/null and b/video/testdata/video/image_array_000000006.jpg differ diff --git a/video/testdata/video/image_array_000000007.jpg b/video/testdata/video/image_array_000000007.jpg new file mode 100644 index 0000000..7245ab8 Binary files /dev/null and b/video/testdata/video/image_array_000000007.jpg differ diff --git a/video/testdata/video/image_array_000000008.jpg b/video/testdata/video/image_array_000000008.jpg new file mode 100644 index 0000000..c9f26d2 Binary files /dev/null and b/video/testdata/video/image_array_000000008.jpg differ diff --git a/video/testdata/video/image_array_000000009.jpg b/video/testdata/video/image_array_000000009.jpg new file mode 100644 index 0000000..6b4c3cc Binary files /dev/null and b/video/testdata/video/image_array_000000009.jpg differ diff --git a/video/testdata/video/image_array_000000010.jpg b/video/testdata/video/image_array_000000010.jpg new file mode 100644 index 0000000..43c22a3 Binary files /dev/null and b/video/testdata/video/image_array_000000010.jpg differ diff --git a/video/testdata/video/image_array_000000011.jpg b/video/testdata/video/image_array_000000011.jpg new file mode 100644 index 0000000..7aebc6f Binary files /dev/null and b/video/testdata/video/image_array_000000011.jpg differ diff --git a/video/testdata/video/image_array_000000012.jpg b/video/testdata/video/image_array_000000012.jpg new file mode 100644 index 0000000..3b14ed5 Binary files /dev/null and b/video/testdata/video/image_array_000000012.jpg differ diff --git a/video/testdata/video/image_array_000000013.jpg b/video/testdata/video/image_array_000000013.jpg new file mode 100644 index 0000000..ba058c2 Binary files /dev/null and b/video/testdata/video/image_array_000000013.jpg differ diff --git a/video/testdata/video/image_array_000000014.jpg b/video/testdata/video/image_array_000000014.jpg new file mode 100644 index 0000000..1ef81d4 Binary files /dev/null and b/video/testdata/video/image_array_000000014.jpg differ diff --git a/video/testdata/video/image_array_000000015.jpg b/video/testdata/video/image_array_000000015.jpg new file mode 100644 index 0000000..5c6d61a Binary files /dev/null and b/video/testdata/video/image_array_000000015.jpg differ diff --git a/video/testdata/video/image_array_000000016.jpg b/video/testdata/video/image_array_000000016.jpg new file mode 100644 index 0000000..983712e Binary files /dev/null and b/video/testdata/video/image_array_000000016.jpg differ diff --git a/video/testdata/video/image_array_000000017.jpg b/video/testdata/video/image_array_000000017.jpg new file mode 100644 index 0000000..4f20389 Binary files /dev/null and b/video/testdata/video/image_array_000000017.jpg differ diff --git a/video/testdata/video/image_array_000000018.jpg b/video/testdata/video/image_array_000000018.jpg new file mode 100644 index 0000000..932d583 Binary files /dev/null and b/video/testdata/video/image_array_000000018.jpg differ diff --git a/video/testdata/video/image_array_000000019.jpg b/video/testdata/video/image_array_000000019.jpg new file mode 100644 index 0000000..b0b95cb Binary files /dev/null and b/video/testdata/video/image_array_000000019.jpg differ diff --git a/video/testdata/video/image_array_000000020.jpg b/video/testdata/video/image_array_000000020.jpg new file mode 100644 index 0000000..752809b Binary files /dev/null and b/video/testdata/video/image_array_000000020.jpg differ diff --git a/video/testdata/video/image_array_000000021.jpg b/video/testdata/video/image_array_000000021.jpg new file mode 100644 index 0000000..cac2d21 Binary files /dev/null and b/video/testdata/video/image_array_000000021.jpg differ diff --git a/video/testdata/video/image_array_000000022.jpg b/video/testdata/video/image_array_000000022.jpg new file mode 100644 index 0000000..d6ec504 Binary files /dev/null and b/video/testdata/video/image_array_000000022.jpg differ diff --git a/video/testdata/video/image_array_000000023.jpg b/video/testdata/video/image_array_000000023.jpg new file mode 100644 index 0000000..6517e74 Binary files /dev/null and b/video/testdata/video/image_array_000000023.jpg differ diff --git a/video/testdata/video/image_array_000000024.jpg b/video/testdata/video/image_array_000000024.jpg new file mode 100644 index 0000000..b11f4e5 Binary files /dev/null and b/video/testdata/video/image_array_000000024.jpg differ diff --git a/video/testdata/video/image_array_000000025.jpg b/video/testdata/video/image_array_000000025.jpg new file mode 100644 index 0000000..a9b21e5 Binary files /dev/null and b/video/testdata/video/image_array_000000025.jpg differ diff --git a/video/testdata/video/image_array_000000026.jpg b/video/testdata/video/image_array_000000026.jpg new file mode 100644 index 0000000..b2fecef Binary files /dev/null and b/video/testdata/video/image_array_000000026.jpg differ diff --git a/video/testdata/video/image_array_000000027.jpg b/video/testdata/video/image_array_000000027.jpg new file mode 100644 index 0000000..25a9c39 Binary files /dev/null and b/video/testdata/video/image_array_000000027.jpg differ diff --git a/video/testdata/video/image_array_000000028.jpg b/video/testdata/video/image_array_000000028.jpg new file mode 100644 index 0000000..0f15117 Binary files /dev/null and b/video/testdata/video/image_array_000000028.jpg differ diff --git a/video/testdata/video/image_array_000000029.jpg b/video/testdata/video/image_array_000000029.jpg new file mode 100644 index 0000000..b977842 Binary files /dev/null and b/video/testdata/video/image_array_000000029.jpg differ diff --git a/video/testdata/video/image_array_000000030.jpg b/video/testdata/video/image_array_000000030.jpg new file mode 100644 index 0000000..38e6662 Binary files /dev/null and b/video/testdata/video/image_array_000000030.jpg differ diff --git a/video/testdata/video/image_array_000000031.jpg b/video/testdata/video/image_array_000000031.jpg new file mode 100644 index 0000000..698889e Binary files /dev/null and b/video/testdata/video/image_array_000000031.jpg differ diff --git a/video/testdata/video/image_array_000000032.jpg b/video/testdata/video/image_array_000000032.jpg new file mode 100644 index 0000000..ad6be37 Binary files /dev/null and b/video/testdata/video/image_array_000000032.jpg differ diff --git a/video/testdata/video/image_array_000000033.jpg b/video/testdata/video/image_array_000000033.jpg new file mode 100644 index 0000000..39709f6 Binary files /dev/null and b/video/testdata/video/image_array_000000033.jpg differ diff --git a/video/testdata/video/image_array_000000034.jpg b/video/testdata/video/image_array_000000034.jpg new file mode 100644 index 0000000..a3cdda3 Binary files /dev/null and b/video/testdata/video/image_array_000000034.jpg differ diff --git a/video/testdata/video/image_array_000000035.jpg b/video/testdata/video/image_array_000000035.jpg new file mode 100644 index 0000000..548ed48 Binary files /dev/null and b/video/testdata/video/image_array_000000035.jpg differ diff --git a/video/testdata/video/image_array_000000036.jpg b/video/testdata/video/image_array_000000036.jpg new file mode 100644 index 0000000..bfb6a87 Binary files /dev/null and b/video/testdata/video/image_array_000000036.jpg differ diff --git a/video/testdata/video/image_array_000000037.jpg b/video/testdata/video/image_array_000000037.jpg new file mode 100644 index 0000000..dd5f8cc Binary files /dev/null and b/video/testdata/video/image_array_000000037.jpg differ diff --git a/video/testdata/video/image_array_000000038.jpg b/video/testdata/video/image_array_000000038.jpg new file mode 100644 index 0000000..1584e5f Binary files /dev/null and b/video/testdata/video/image_array_000000038.jpg differ diff --git a/video/testdata/video/image_array_000000039.jpg b/video/testdata/video/image_array_000000039.jpg new file mode 100644 index 0000000..29e0615 Binary files /dev/null and b/video/testdata/video/image_array_000000039.jpg differ diff --git a/video/testdata/video/image_array_000000040.jpg b/video/testdata/video/image_array_000000040.jpg new file mode 100644 index 0000000..13d0ff4 Binary files /dev/null and b/video/testdata/video/image_array_000000040.jpg differ diff --git a/video/testdata/video/image_array_000000041.jpg b/video/testdata/video/image_array_000000041.jpg new file mode 100644 index 0000000..20f9580 Binary files /dev/null and b/video/testdata/video/image_array_000000041.jpg differ diff --git a/video/testdata/video/image_array_000000042.jpg b/video/testdata/video/image_array_000000042.jpg new file mode 100644 index 0000000..574d475 Binary files /dev/null and b/video/testdata/video/image_array_000000042.jpg differ diff --git a/video/testdata/video/image_array_000000043.jpg b/video/testdata/video/image_array_000000043.jpg new file mode 100644 index 0000000..e1f0b0d Binary files /dev/null and b/video/testdata/video/image_array_000000043.jpg differ diff --git a/video/testdata/video/image_array_000000044.jpg b/video/testdata/video/image_array_000000044.jpg new file mode 100644 index 0000000..0b60ce3 Binary files /dev/null and b/video/testdata/video/image_array_000000044.jpg differ diff --git a/video/testdata/video/image_array_000000045.jpg b/video/testdata/video/image_array_000000045.jpg new file mode 100644 index 0000000..6922043 Binary files /dev/null and b/video/testdata/video/image_array_000000045.jpg differ diff --git a/video/testdata/video/image_array_000000046.jpg b/video/testdata/video/image_array_000000046.jpg new file mode 100644 index 0000000..c49f075 Binary files /dev/null and b/video/testdata/video/image_array_000000046.jpg differ diff --git a/video/testdata/video/image_array_000000047.jpg b/video/testdata/video/image_array_000000047.jpg new file mode 100644 index 0000000..90e70c9 Binary files /dev/null and b/video/testdata/video/image_array_000000047.jpg differ diff --git a/video/testdata/video/image_array_000000048.jpg b/video/testdata/video/image_array_000000048.jpg new file mode 100644 index 0000000..0d1613d Binary files /dev/null and b/video/testdata/video/image_array_000000048.jpg differ diff --git a/video/testdata/video/image_array_000000049.jpg b/video/testdata/video/image_array_000000049.jpg new file mode 100644 index 0000000..89c7834 Binary files /dev/null and b/video/testdata/video/image_array_000000049.jpg differ diff --git a/video/testdata/video/image_array_000000050.jpg b/video/testdata/video/image_array_000000050.jpg new file mode 100644 index 0000000..3a71448 Binary files /dev/null and b/video/testdata/video/image_array_000000050.jpg differ diff --git a/video/testdata/video/image_array_000000051.jpg b/video/testdata/video/image_array_000000051.jpg new file mode 100644 index 0000000..3bfb5ef Binary files /dev/null and b/video/testdata/video/image_array_000000051.jpg differ diff --git a/video/testdata/video/image_array_000000052.jpg b/video/testdata/video/image_array_000000052.jpg new file mode 100644 index 0000000..102f4e1 Binary files /dev/null and b/video/testdata/video/image_array_000000052.jpg differ diff --git a/video/testdata/video/image_array_000000053.jpg b/video/testdata/video/image_array_000000053.jpg new file mode 100644 index 0000000..b8fb796 Binary files /dev/null and b/video/testdata/video/image_array_000000053.jpg differ diff --git a/video/testdata/video/image_array_000000054.jpg b/video/testdata/video/image_array_000000054.jpg new file mode 100644 index 0000000..84d8040 Binary files /dev/null and b/video/testdata/video/image_array_000000054.jpg differ diff --git a/video/testdata/video/image_array_000000055.jpg b/video/testdata/video/image_array_000000055.jpg new file mode 100644 index 0000000..4d267ad Binary files /dev/null and b/video/testdata/video/image_array_000000055.jpg differ diff --git a/video/testdata/video/image_array_000000056.jpg b/video/testdata/video/image_array_000000056.jpg new file mode 100644 index 0000000..5ea8a73 Binary files /dev/null and b/video/testdata/video/image_array_000000056.jpg differ diff --git a/video/testdata/video/image_array_000000057.jpg b/video/testdata/video/image_array_000000057.jpg new file mode 100644 index 0000000..c604c65 Binary files /dev/null and b/video/testdata/video/image_array_000000057.jpg differ diff --git a/video/testdata/video/image_array_000000058.jpg b/video/testdata/video/image_array_000000058.jpg new file mode 100644 index 0000000..9d6be83 Binary files /dev/null and b/video/testdata/video/image_array_000000058.jpg differ diff --git a/video/testdata/video/image_array_000000059.jpg b/video/testdata/video/image_array_000000059.jpg new file mode 100644 index 0000000..225a684 Binary files /dev/null and b/video/testdata/video/image_array_000000059.jpg differ diff --git a/video/testdata/video/image_array_000000060.jpg b/video/testdata/video/image_array_000000060.jpg new file mode 100644 index 0000000..b6e3add Binary files /dev/null and b/video/testdata/video/image_array_000000060.jpg differ diff --git a/video/testdata/video/image_array_000000061.jpg b/video/testdata/video/image_array_000000061.jpg new file mode 100644 index 0000000..e66a7a8 Binary files /dev/null and b/video/testdata/video/image_array_000000061.jpg differ diff --git a/video/testdata/video/image_array_000000062.jpg b/video/testdata/video/image_array_000000062.jpg new file mode 100644 index 0000000..73a537e Binary files /dev/null and b/video/testdata/video/image_array_000000062.jpg differ diff --git a/video/testdata/video/image_array_000000063.jpg b/video/testdata/video/image_array_000000063.jpg new file mode 100644 index 0000000..48d1de4 Binary files /dev/null and b/video/testdata/video/image_array_000000063.jpg differ diff --git a/video/testdata/video/image_array_000000064.jpg b/video/testdata/video/image_array_000000064.jpg new file mode 100644 index 0000000..5877425 Binary files /dev/null and b/video/testdata/video/image_array_000000064.jpg differ diff --git a/video/testdata/video/image_array_000000065.jpg b/video/testdata/video/image_array_000000065.jpg new file mode 100644 index 0000000..acfbfd7 Binary files /dev/null and b/video/testdata/video/image_array_000000065.jpg differ diff --git a/video/testdata/video/image_array_000000066.jpg b/video/testdata/video/image_array_000000066.jpg new file mode 100644 index 0000000..bbfc99e Binary files /dev/null and b/video/testdata/video/image_array_000000066.jpg differ diff --git a/video/testdata/video/image_array_000000067.jpg b/video/testdata/video/image_array_000000067.jpg new file mode 100644 index 0000000..c9aa425 Binary files /dev/null and b/video/testdata/video/image_array_000000067.jpg differ diff --git a/video/testdata/video/image_array_000000068.jpg b/video/testdata/video/image_array_000000068.jpg new file mode 100644 index 0000000..6c2b41c Binary files /dev/null and b/video/testdata/video/image_array_000000068.jpg differ diff --git a/video/testdata/video/image_array_000000069.jpg b/video/testdata/video/image_array_000000069.jpg new file mode 100644 index 0000000..1b48439 Binary files /dev/null and b/video/testdata/video/image_array_000000069.jpg differ diff --git a/video/testdata/video/image_array_000000070.jpg b/video/testdata/video/image_array_000000070.jpg new file mode 100644 index 0000000..dd9efbf Binary files /dev/null and b/video/testdata/video/image_array_000000070.jpg differ diff --git a/video/testdata/video/image_array_000000071.jpg b/video/testdata/video/image_array_000000071.jpg new file mode 100644 index 0000000..80d8442 Binary files /dev/null and b/video/testdata/video/image_array_000000071.jpg differ diff --git a/video/testdata/video/image_array_000000072.jpg b/video/testdata/video/image_array_000000072.jpg new file mode 100644 index 0000000..6145182 Binary files /dev/null and b/video/testdata/video/image_array_000000072.jpg differ diff --git a/video/testdata/video/image_array_000000073.jpg b/video/testdata/video/image_array_000000073.jpg new file mode 100644 index 0000000..bafbbd5 Binary files /dev/null and b/video/testdata/video/image_array_000000073.jpg differ diff --git a/video/testdata/video/image_array_000000074.jpg b/video/testdata/video/image_array_000000074.jpg new file mode 100644 index 0000000..2f56982 Binary files /dev/null and b/video/testdata/video/image_array_000000074.jpg differ diff --git a/video/testdata/video/image_array_000000075.jpg b/video/testdata/video/image_array_000000075.jpg new file mode 100644 index 0000000..d6b0ed3 Binary files /dev/null and b/video/testdata/video/image_array_000000075.jpg differ diff --git a/video/testdata/video/image_array_000000076.jpg b/video/testdata/video/image_array_000000076.jpg new file mode 100644 index 0000000..68919e1 Binary files /dev/null and b/video/testdata/video/image_array_000000076.jpg differ diff --git a/video/testdata/video/image_array_000000077.jpg b/video/testdata/video/image_array_000000077.jpg new file mode 100644 index 0000000..96bfa84 Binary files /dev/null and b/video/testdata/video/image_array_000000077.jpg differ diff --git a/video/testdata/video/image_array_000000078.jpg b/video/testdata/video/image_array_000000078.jpg new file mode 100644 index 0000000..64f856b Binary files /dev/null and b/video/testdata/video/image_array_000000078.jpg differ diff --git a/video/testdata/video/image_array_000000079.jpg b/video/testdata/video/image_array_000000079.jpg new file mode 100644 index 0000000..0da86a2 Binary files /dev/null and b/video/testdata/video/image_array_000000079.jpg differ diff --git a/video/testdata/video/image_array_000000080.jpg b/video/testdata/video/image_array_000000080.jpg new file mode 100644 index 0000000..5a62c82 Binary files /dev/null and b/video/testdata/video/image_array_000000080.jpg differ diff --git a/video/testdata/video/image_array_000000081.jpg b/video/testdata/video/image_array_000000081.jpg new file mode 100644 index 0000000..30e91fb Binary files /dev/null and b/video/testdata/video/image_array_000000081.jpg differ diff --git a/video/testdata/video/image_array_000000082.jpg b/video/testdata/video/image_array_000000082.jpg new file mode 100644 index 0000000..217b2a3 Binary files /dev/null and b/video/testdata/video/image_array_000000082.jpg differ diff --git a/video/testdata/video/image_array_000000083.jpg b/video/testdata/video/image_array_000000083.jpg new file mode 100644 index 0000000..4b1a1db Binary files /dev/null and b/video/testdata/video/image_array_000000083.jpg differ diff --git a/video/testdata/video/image_array_000000084.jpg b/video/testdata/video/image_array_000000084.jpg new file mode 100644 index 0000000..06dcc9c Binary files /dev/null and b/video/testdata/video/image_array_000000084.jpg differ diff --git a/video/testdata/video/image_array_000000085.jpg b/video/testdata/video/image_array_000000085.jpg new file mode 100644 index 0000000..41d683d Binary files /dev/null and b/video/testdata/video/image_array_000000085.jpg differ diff --git a/video/testdata/video/image_array_000000086.jpg b/video/testdata/video/image_array_000000086.jpg new file mode 100644 index 0000000..0c029a1 Binary files /dev/null and b/video/testdata/video/image_array_000000086.jpg differ diff --git a/video/testdata/video/image_array_000000087.jpg b/video/testdata/video/image_array_000000087.jpg new file mode 100644 index 0000000..d642373 Binary files /dev/null and b/video/testdata/video/image_array_000000087.jpg differ diff --git a/video/testdata/video/image_array_000000088.jpg b/video/testdata/video/image_array_000000088.jpg new file mode 100644 index 0000000..8c236bb Binary files /dev/null and b/video/testdata/video/image_array_000000088.jpg differ diff --git a/video/testdata/video/image_array_000000089.jpg b/video/testdata/video/image_array_000000089.jpg new file mode 100644 index 0000000..5c124aa Binary files /dev/null and b/video/testdata/video/image_array_000000089.jpg differ diff --git a/video/testdata/video/image_array_000000090.jpg b/video/testdata/video/image_array_000000090.jpg new file mode 100644 index 0000000..e2b6a7b Binary files /dev/null and b/video/testdata/video/image_array_000000090.jpg differ diff --git a/video/testdata/video/image_array_000000091.jpg b/video/testdata/video/image_array_000000091.jpg new file mode 100644 index 0000000..ed33fcf Binary files /dev/null and b/video/testdata/video/image_array_000000091.jpg differ diff --git a/video/testdata/video/image_array_000000092.jpg b/video/testdata/video/image_array_000000092.jpg new file mode 100644 index 0000000..1aae8db Binary files /dev/null and b/video/testdata/video/image_array_000000092.jpg differ diff --git a/video/testdata/video/image_array_000000093.jpg b/video/testdata/video/image_array_000000093.jpg new file mode 100644 index 0000000..e96b5bb Binary files /dev/null and b/video/testdata/video/image_array_000000093.jpg differ diff --git a/video/testdata/video/image_array_000000094.jpg b/video/testdata/video/image_array_000000094.jpg new file mode 100644 index 0000000..2500933 Binary files /dev/null and b/video/testdata/video/image_array_000000094.jpg differ diff --git a/video/testdata/video/image_array_000000095.jpg b/video/testdata/video/image_array_000000095.jpg new file mode 100644 index 0000000..353b091 Binary files /dev/null and b/video/testdata/video/image_array_000000095.jpg differ diff --git a/video/testdata/video/image_array_000000096.jpg b/video/testdata/video/image_array_000000096.jpg new file mode 100644 index 0000000..56a350a Binary files /dev/null and b/video/testdata/video/image_array_000000096.jpg differ diff --git a/video/testdata/video/image_array_000000097.jpg b/video/testdata/video/image_array_000000097.jpg new file mode 100644 index 0000000..4a6ce8a Binary files /dev/null and b/video/testdata/video/image_array_000000097.jpg differ diff --git a/video/testdata/video/image_array_000000098.jpg b/video/testdata/video/image_array_000000098.jpg new file mode 100644 index 0000000..75036f9 Binary files /dev/null and b/video/testdata/video/image_array_000000098.jpg differ diff --git a/video/testdata/video/image_array_000000099.jpg b/video/testdata/video/image_array_000000099.jpg new file mode 100644 index 0000000..f4f5b88 Binary files /dev/null and b/video/testdata/video/image_array_000000099.jpg differ diff --git a/video/testdata/video/image_array_000000100.jpg b/video/testdata/video/image_array_000000100.jpg new file mode 100644 index 0000000..3ecda2e Binary files /dev/null and b/video/testdata/video/image_array_000000100.jpg differ diff --git a/video/testdata/video/image_array_000000101.jpg b/video/testdata/video/image_array_000000101.jpg new file mode 100644 index 0000000..89457bb Binary files /dev/null and b/video/testdata/video/image_array_000000101.jpg differ diff --git a/video/testdata/video/image_array_000000102.jpg b/video/testdata/video/image_array_000000102.jpg new file mode 100644 index 0000000..61b128e Binary files /dev/null and b/video/testdata/video/image_array_000000102.jpg differ diff --git a/video/testdata/video/image_array_000000103.jpg b/video/testdata/video/image_array_000000103.jpg new file mode 100644 index 0000000..9e14d0a Binary files /dev/null and b/video/testdata/video/image_array_000000103.jpg differ diff --git a/video/testdata/video/image_array_000000104.jpg b/video/testdata/video/image_array_000000104.jpg new file mode 100644 index 0000000..ac5fb90 Binary files /dev/null and b/video/testdata/video/image_array_000000104.jpg differ diff --git a/video/testdata/video/image_array_000000105.jpg b/video/testdata/video/image_array_000000105.jpg new file mode 100644 index 0000000..fceb6f2 Binary files /dev/null and b/video/testdata/video/image_array_000000105.jpg differ diff --git a/video/testdata/video/image_array_000000106.jpg b/video/testdata/video/image_array_000000106.jpg new file mode 100644 index 0000000..abcdacf Binary files /dev/null and b/video/testdata/video/image_array_000000106.jpg differ diff --git a/video/testdata/video/image_array_000000107.jpg b/video/testdata/video/image_array_000000107.jpg new file mode 100644 index 0000000..ef4857d Binary files /dev/null and b/video/testdata/video/image_array_000000107.jpg differ diff --git a/video/testdata/video/image_array_000000108.jpg b/video/testdata/video/image_array_000000108.jpg new file mode 100644 index 0000000..7f20537 Binary files /dev/null and b/video/testdata/video/image_array_000000108.jpg differ diff --git a/video/testdata/video/image_array_000000109.jpg b/video/testdata/video/image_array_000000109.jpg new file mode 100644 index 0000000..74dcd41 Binary files /dev/null and b/video/testdata/video/image_array_000000109.jpg differ diff --git a/video/testdata/video/image_array_000000110.jpg b/video/testdata/video/image_array_000000110.jpg new file mode 100644 index 0000000..44b1dbf Binary files /dev/null and b/video/testdata/video/image_array_000000110.jpg differ diff --git a/video/testdata/video/image_array_000000111.jpg b/video/testdata/video/image_array_000000111.jpg new file mode 100644 index 0000000..d30e394 Binary files /dev/null and b/video/testdata/video/image_array_000000111.jpg differ diff --git a/video/testdata/video/image_array_000000112.jpg b/video/testdata/video/image_array_000000112.jpg new file mode 100644 index 0000000..174a5fa Binary files /dev/null and b/video/testdata/video/image_array_000000112.jpg differ diff --git a/video/testdata/video/image_array_000000113.jpg b/video/testdata/video/image_array_000000113.jpg new file mode 100644 index 0000000..d9664f8 Binary files /dev/null and b/video/testdata/video/image_array_000000113.jpg differ diff --git a/video/testdata/video/image_array_000000114.jpg b/video/testdata/video/image_array_000000114.jpg new file mode 100644 index 0000000..efb51b9 Binary files /dev/null and b/video/testdata/video/image_array_000000114.jpg differ diff --git a/video/testdata/video/image_array_000000115.jpg b/video/testdata/video/image_array_000000115.jpg new file mode 100644 index 0000000..1b49ae0 Binary files /dev/null and b/video/testdata/video/image_array_000000115.jpg differ diff --git a/video/testdata/video/image_array_000000116.jpg b/video/testdata/video/image_array_000000116.jpg new file mode 100644 index 0000000..6198006 Binary files /dev/null and b/video/testdata/video/image_array_000000116.jpg differ diff --git a/video/testdata/video/image_array_000000117.jpg b/video/testdata/video/image_array_000000117.jpg new file mode 100644 index 0000000..8e51a49 Binary files /dev/null and b/video/testdata/video/image_array_000000117.jpg differ diff --git a/video/testdata/video/image_array_000000118.jpg b/video/testdata/video/image_array_000000118.jpg new file mode 100644 index 0000000..03d56f5 Binary files /dev/null and b/video/testdata/video/image_array_000000118.jpg differ diff --git a/video/testdata/video/image_array_000000119.jpg b/video/testdata/video/image_array_000000119.jpg new file mode 100644 index 0000000..6ab6751 Binary files /dev/null and b/video/testdata/video/image_array_000000119.jpg differ diff --git a/video/testdata/video/image_array_000000120.jpg b/video/testdata/video/image_array_000000120.jpg new file mode 100644 index 0000000..0ca0bf2 Binary files /dev/null and b/video/testdata/video/image_array_000000120.jpg differ diff --git a/video/testdata/video/image_array_000000121.jpg b/video/testdata/video/image_array_000000121.jpg new file mode 100644 index 0000000..654e71c Binary files /dev/null and b/video/testdata/video/image_array_000000121.jpg differ diff --git a/video/testdata/video/image_array_000000122.jpg b/video/testdata/video/image_array_000000122.jpg new file mode 100644 index 0000000..c7571b0 Binary files /dev/null and b/video/testdata/video/image_array_000000122.jpg differ diff --git a/video/testdata/video/image_array_000000123.jpg b/video/testdata/video/image_array_000000123.jpg new file mode 100644 index 0000000..73f9bb3 Binary files /dev/null and b/video/testdata/video/image_array_000000123.jpg differ diff --git a/video/testdata/video/image_array_000000124.jpg b/video/testdata/video/image_array_000000124.jpg new file mode 100644 index 0000000..cb3a534 Binary files /dev/null and b/video/testdata/video/image_array_000000124.jpg differ diff --git a/video/testdata/video/image_array_000000125.jpg b/video/testdata/video/image_array_000000125.jpg new file mode 100644 index 0000000..8eb7385 Binary files /dev/null and b/video/testdata/video/image_array_000000125.jpg differ diff --git a/video/testdata/video/image_array_000000126.jpg b/video/testdata/video/image_array_000000126.jpg new file mode 100644 index 0000000..17d71bd Binary files /dev/null and b/video/testdata/video/image_array_000000126.jpg differ diff --git a/video/testdata/video/image_array_000000127.jpg b/video/testdata/video/image_array_000000127.jpg new file mode 100644 index 0000000..9345f76 Binary files /dev/null and b/video/testdata/video/image_array_000000127.jpg differ diff --git a/video/testdata/video/image_array_000000128.jpg b/video/testdata/video/image_array_000000128.jpg new file mode 100644 index 0000000..f4d05d9 Binary files /dev/null and b/video/testdata/video/image_array_000000128.jpg differ diff --git a/video/testdata/video/image_array_000000129.jpg b/video/testdata/video/image_array_000000129.jpg new file mode 100644 index 0000000..44a5b09 Binary files /dev/null and b/video/testdata/video/image_array_000000129.jpg differ diff --git a/video/testdata/video/image_array_000000130.jpg b/video/testdata/video/image_array_000000130.jpg new file mode 100644 index 0000000..f3fcc50 Binary files /dev/null and b/video/testdata/video/image_array_000000130.jpg differ diff --git a/video/testdata/video/image_array_000000131.jpg b/video/testdata/video/image_array_000000131.jpg new file mode 100644 index 0000000..1ae54db Binary files /dev/null and b/video/testdata/video/image_array_000000131.jpg differ diff --git a/video/testdata/video/image_array_000000132.jpg b/video/testdata/video/image_array_000000132.jpg new file mode 100644 index 0000000..f273f3e Binary files /dev/null and b/video/testdata/video/image_array_000000132.jpg differ diff --git a/video/video.go b/video/video.go new file mode 100644 index 0000000..186d578 --- /dev/null +++ b/video/video.go @@ -0,0 +1,99 @@ +package video + +import ( + "fmt" + "github.com/cyrilix/robocar-protobuf/go/events" + mqtt "github.com/eclipse/paho.mqtt.golang" + "github.com/golang/protobuf/proto" + "github.com/golang/protobuf/ptypes/timestamp" + log "github.com/sirupsen/logrus" + "io/ioutil" + "os" + "time" +) + +type CameraFake struct { + client mqtt.Client + frameTopic string + videoPath string + fps int + cancel chan interface{} +} + +func NewCameraFake(client mqtt.Client, frameTopic string, videoPath string, fps int) (*CameraFake, error) { + + files, err := ioutil.ReadDir(videoPath) + if err != nil { + return nil, fmt.Errorf("unable to found camera frame in directory %v: %v", videoPath, err) + } + if len(files) == 0 { + return nil, fmt.Errorf("no files in directory %v", videoPath) + } + return &CameraFake{ + client: client, + frameTopic: frameTopic, + videoPath: videoPath, + fps: fps, + cancel: make(chan interface{}), + }, nil +} + +func (c CameraFake) Start() error { + files, err := ioutil.ReadDir(c.videoPath) + if err != nil { + return fmt.Errorf("unable to found camera frame in directory %v: %v", c.videoPath, err) + } + + go c.loop(files) + return nil +} + +func (c CameraFake) loop(files []os.FileInfo) { + ticker := time.NewTicker(time.Second / time.Duration(c.fps)) + defer ticker.Stop() + + for { + + for _, file := range files { + framePath := fmt.Sprintf("%s/%s", c.videoPath, file.Name()) + frameContent, err := ioutil.ReadFile(framePath) + if err != nil { + log.Errorf("unable to load frame content for %v: %v", framePath, err) + continue + } + now := time.Now() + msg := &events.FrameMessage{ + Id: &events.FrameRef{ + Name: "camera", + Id: fmt.Sprintf("%d%000d", now.Unix(), now.Nanosecond()/1000/1000), + CreatedAt: ×tamp.Timestamp{ + Seconds: now.Unix(), + Nanos: int32(now.Nanosecond()), + }, + }, + Frame: frameContent, + } + + payload, err := proto.Marshal(msg) + if err != nil { + log.Errorf("unable to marshal protobuf message: %v", err) + } + + publish(c.client, c.frameTopic, &payload) + + select { + case <-ticker.C: + case <-c.cancel: + return + } + } + } +} + +func (c CameraFake) Stop() { + close(c.cancel) +} + +var publish = func(client mqtt.Client, topic string, payload *[]byte) { + client.Publish(topic, 0, true, *payload) +} diff --git a/video/video_test.go b/video/video_test.go new file mode 100644 index 0000000..dc0e736 --- /dev/null +++ b/video/video_test.go @@ -0,0 +1,85 @@ +package video + +import ( + "encoding/base64" + "fmt" + "github.com/cyrilix/robocar-protobuf/go/events" + mqtt "github.com/eclipse/paho.mqtt.golang" + "github.com/golang/protobuf/proto" + "io/ioutil" + "sync" + "testing" + "time" +) + +func TestNewCameraFake(t *testing.T) { + oldPublish := publish + defer func() { + publish = oldPublish + }() + + var muEventsPublished sync.Mutex + eventsPublished := make([]*[]byte, 0, 10) + publish = func(client mqtt.Client, topic string, payload *[]byte) { + muEventsPublished.Lock() + defer muEventsPublished.Unlock() + eventsPublished = append(eventsPublished, payload) + } + + videoDir := "testdata/video" + fps := 250 + camera, err := NewCameraFake(nil, "topic/fake/video", videoDir, fps) + if err != nil { + t.Errorf("unable to load frame from directory %v: %v", videoDir, err) + } + + // Video frame + files, err := ioutil.ReadDir(videoDir) + if err != nil { + t.Errorf("unable to list files in directory %v: %v", videoDir, err) + } + + if err := camera.Start(); err != nil { + t.Errorf("unexpected error: %v", err) + } + defer camera.Stop() + + time.Sleep(5 * time.Millisecond) + for idx, frame := range files { + muEventsPublished.Lock() + if len(eventsPublished) < idx+1 { + t.Errorf("frame %v has not been published", idx) + t.FailNow() + } + + msgPublished := eventsPublished[idx] + var frameMsg events.FrameMessage + err := proto.Unmarshal(*msgPublished, &frameMsg) + if err != nil { + t.Errorf("unable to unmarshal msg frame: %v", err) + } + + frameContent, err := ioutil.ReadFile(fmt.Sprintf("%s/%s", videoDir, frame.Name())) + if err != nil { + t.Errorf("unable to read frame file %v: %v", frame.Name(), err) + } + srcFrame := base64.StdEncoding.EncodeToString(frameContent) + publishedFrame := base64.StdEncoding.EncodeToString(frameMsg.GetFrame()) + + if srcFrame != publishedFrame { + t.Errorf("frame signatures doesn't match: %v, wants %v", publishedFrame, srcFrame) + } + if frameMsg.GetId().GetName() != "camera" { + t.Errorf("bad name frame: %v, wants %v", frameMsg.GetId().GetName(), "camera") + } + if len(frameMsg.GetId().GetId()) != 13 { + t.Errorf("bad id length: %v, wants %v", len(frameMsg.GetId().GetId()), 13) + } + if frameMsg.GetId().GetCreatedAt() == nil { + t.Errorf("missin CreatedAt field") + } + muEventsPublished.Unlock() + time.Sleep(1 * time.Second / time.Duration(fps)) + } + +}