From 005168b8e1f64249a73c8130ec50bb30116a0bed Mon Sep 17 00:00:00 2001 From: zengqile <2674805612@qq.com> Date: Mon, 26 Jan 2026 10:21:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9dockerfile=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0ffmpeg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/video_config.json | 422 ++++++++++++------------- docker/Dockerfile | 1 + src/light_control/light_controller.cc | 13 +- src/light_control/light_controller.hpp | 13 + src/web/web_server.cc | 8 + 5 files changed, 244 insertions(+), 213 deletions(-) diff --git a/config/video_config.json b/config/video_config.json index 4ebcec0..ed6ad85 100644 --- a/config/video_config.json +++ b/config/video_config.json @@ -1,213 +1,213 @@ { - "video_service": { - "enabled": true - }, - "video_streams": [ - { - "enabled": true, - "id": "cam_01_intrusion", - "input_url": "rtsp://admin:hzx12345@192.168.1.10:554/Streaming/Channels/3101", - "module_config": { - "class_num": 3, - "intrusion_zone": [ - [ - 4, - 8 - ], - [ - 1057, - 13 - ], - [ - 1053, - 267 - ], - [ - 1347, - 289 - ], - [ - 1365, - 8 - ], - [ - 1911, - 6 - ], - [ - 1898, - 1077 - ], - [ - 7, - 1077 - ] - ], - "label_path": "/app/models/human.txt", - "light_device_ids": [ - "351", - "352", - "353", - "349", - "354", - "350" - ], - "mode": 2, - "model_path": "/app/models/human_detection.rknn", - "rknn_thread_num": 3, - "time_threshold_sec": 3 - }, - "module_type": "human_detection", - "output_rtsp": "rtsp://127.0.0.1:8554/ch1901" - }, - { - "enabled": true, - "id": "cam_02_intrusion", - "input_url": "rtsp://admin:hzx12345@192.168.1.10:554/Streaming/Channels/3201", - "module_config": { - "class_num": 3, - "intrusion_zone": [ - [ - 11, - 13 - ], - [ - 1907, - 13 - ], - [ - 1911, - 1074 - ], - [ - 7, - 1070 - ] - ], - "label_path": "/app/models/human.txt", - "light_device_ids": [ - "351", - "352", - "353", - "349", - "354", - "350" - ], - "mode": 2, - "model_path": "/app/models/human_detection.rknn", - "rknn_thread_num": 3, - "time_threshold_sec": 3 - }, - "module_type": "human_detection", - "output_rtsp": "rtsp://127.0.0.1:8554/ch1801" - }, - { - "enabled": true, - "id": "cam_03_intrusion", - "input_url": "rtsp://admin:hzx12345@192.168.1.10:554/Streaming/Channels/1601", - "module_config": { - "class_num": 3, - "intrusion_zone": [ - [ - 20, - 19 - ], - [ - 1891, - 35 - ], - [ - 1433, - 466 - ], - [ - 1006, - 619 - ], - [ - 1210, - 1001 - ], - [ - 1201, - 1072 - ], - [ - 2, - 1077 - ] - ], - "label_path": "/app/models/human.txt", - "model_path": "/app/models/human_detection.rknn", - "rknn_thread_num": 3, - "time_threshold_sec": 3 - }, - "module_type": "human_detection", - "output_rtsp": "rtsp://127.0.0.1:8554/ch2201" - }, - { - "enabled": false, - "id": "cam_04_intrusion", - "input_url": "rtsp://admin:hzx12345@192.168.1.10:554/Streaming/Channels/1101", - "module_config": { - "class_num": 3, - "intrusion_zone": [ - [ - 400, - 400 - ], - [ - 800, - 400 - ], - [ - 900, - 600 - ], - [ - 300, - 600 - ] - ], - "label_path": "/app/models/human.txt", - "model_path": "/app/models/human_detection.rknn", - "rknn_thread_num": 3, - "time_threshold_sec": 3 - }, - "module_type": "human_detection", - "output_rtsp": "rtsp://127.0.0.1:8554/ch1201" - }, - { - "enabled": false, - "id": "cam_01_intrusion", - "input_url": "rtsp://admin:hzx12345@192.168.1.10:554/Streaming/Channels/1101", - "module_config": { - "class_num": 3, - "intrusion_zone": [ - [ - 400, - 400 - ], - [ - 800, - 400 - ], - [ - 900, - 600 - ], - [ - 300, - 600 - ] - ], - "label_path": "/app/models/human.txt", - "model_path": "/app/models/human_detection.rknn", - "rknn_thread_num": 3, - "time_threshold_sec": 3 - }, - "module_type": "human_detection", - "output_rtsp": "rtsp://127.0.0.1:8554/ch1101" - } - ] + "video_service": { + "enabled": true + }, + "video_streams": [ + { + "enabled": true, + "id": "cam_01_intrusion", + "input_url": "rtsp://admin:hzx12345@192.168.1.10:554/Streaming/Channels/3101", + "module_config": { + "class_num": 3, + "intrusion_zone": [ + [ + 4, + 8 + ], + [ + 1057, + 13 + ], + [ + 1053, + 267 + ], + [ + 1347, + 289 + ], + [ + 1365, + 8 + ], + [ + 1911, + 6 + ], + [ + 1898, + 1077 + ], + [ + 7, + 1077 + ] + ], + "label_path": "/app/models/human.txt", + "light_device_ids": [ + "351", + "352", + "353", + "349", + "354", + "350" + ], + "mode": 1, + "model_path": "/app/models/human_detection.rknn", + "rknn_thread_num": 3, + "time_threshold_sec": 3 + }, + "module_type": "human_detection", + "output_rtsp": "rtsp://127.0.0.1:8554/ch1901" + }, + { + "enabled": true, + "id": "cam_02_intrusion", + "input_url": "rtsp://admin:hzx12345@192.168.1.10:554/Streaming/Channels/3201", + "module_config": { + "class_num": 3, + "intrusion_zone": [ + [ + 11, + 13 + ], + [ + 1907, + 13 + ], + [ + 1911, + 1074 + ], + [ + 7, + 1070 + ] + ], + "label_path": "/app/models/human.txt", + "light_device_ids": [ + "351", + "352", + "353", + "349", + "354", + "350" + ], + "mode": 1, + "model_path": "/app/models/human_detection.rknn", + "rknn_thread_num": 3, + "time_threshold_sec": 3 + }, + "module_type": "human_detection", + "output_rtsp": "rtsp://127.0.0.1:8554/ch1801" + }, + { + "enabled": true, + "id": "cam_03_intrusion", + "input_url": "rtsp://admin:hzx12345@192.168.1.10:554/Streaming/Channels/1601", + "module_config": { + "class_num": 3, + "intrusion_zone": [ + [ + 20, + 19 + ], + [ + 1891, + 35 + ], + [ + 1433, + 466 + ], + [ + 1006, + 619 + ], + [ + 1210, + 1001 + ], + [ + 1201, + 1072 + ], + [ + 2, + 1077 + ] + ], + "label_path": "/app/models/human.txt", + "model_path": "/app/models/human_detection.rknn", + "rknn_thread_num": 3, + "time_threshold_sec": 3 + }, + "module_type": "human_detection", + "output_rtsp": "rtsp://127.0.0.1:8554/ch2201" + }, + { + "enabled": false, + "id": "cam_04_intrusion", + "input_url": "rtsp://admin:hzx12345@192.168.1.10:554/Streaming/Channels/1101", + "module_config": { + "class_num": 3, + "intrusion_zone": [ + [ + 400, + 400 + ], + [ + 800, + 400 + ], + [ + 900, + 600 + ], + [ + 300, + 600 + ] + ], + "label_path": "/app/models/human.txt", + "model_path": "/app/models/human_detection.rknn", + "rknn_thread_num": 3, + "time_threshold_sec": 3 + }, + "module_type": "human_detection", + "output_rtsp": "rtsp://127.0.0.1:8554/ch1201" + }, + { + "enabled": false, + "id": "cam_01_intrusion", + "input_url": "rtsp://admin:hzx12345@192.168.1.10:554/Streaming/Channels/1101", + "module_config": { + "class_num": 3, + "intrusion_zone": [ + [ + 400, + 400 + ], + [ + 800, + 400 + ], + [ + 900, + 600 + ], + [ + 300, + 600 + ] + ], + "label_path": "/app/models/human.txt", + "model_path": "/app/models/human_detection.rknn", + "rknn_thread_num": 3, + "time_threshold_sec": 3 + }, + "module_type": "human_detection", + "output_rtsp": "rtsp://127.0.0.1:8554/ch1101" + } + ] } \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index d76020a..3c3bc66 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -95,6 +95,7 @@ RUN unzip -q /tmp/librga-1.10.0.zip -d /tmp/ && \ # ----------------------------------------------------------------------------- RUN apt-get update && \ apt-get install -y --no-install-recommends \ + ffmpeg \ gstreamer1.0-rockchip \ libgstreamer1.0-dev \ libgstreamer-plugins-base1.0-dev \ diff --git a/src/light_control/light_controller.cc b/src/light_control/light_controller.cc index e0b27e0..8926646 100644 --- a/src/light_control/light_controller.cc +++ b/src/light_control/light_controller.cc @@ -9,6 +9,7 @@ LightController::LightController(std::string baseUrl, std::string token) : baseUrl(baseUrl), token(token) { // 启动后台工作线程 running_ = true; + InitializeDevices(); worker_thread_ = std::thread(&LightController::WorkerLoop, this); spdlog::info("[LightController] Worker thread started."); } @@ -97,7 +98,11 @@ void LightController::UpdateAutoLight(std::string deviceId, std::string sourceId bool is_on = !votes.empty(); // 只有状态改变才触发 - if (was_on != is_on) { + if (was_on != is_on || deviceStatus[deviceId]) { + if (deviceStatus[deviceId]) { + spdlog::info("[AutoLight] ForceControll."); + } + deviceStatus[deviceId] = false; std::string action = is_on ? "1" : "0"; spdlog::info("[AutoLight] Logic Change: Device {} -> {}", deviceId, is_on ? "ON" : "OFF"); @@ -126,7 +131,11 @@ void LightController::RemoveSession(std::string sourceId) { votes.erase(sourceId); bool is_on = !votes.empty(); - if (was_on && !is_on) { + if ((was_on && !is_on) || deviceStatus[deviceId]) { + if (deviceStatus[deviceId]) { + spdlog::info("[AutoLight] ForceControll."); + } + deviceStatus[deviceId] = false; spdlog::info("[AutoLight] Source {} disconnect. Turning OFF {}.", sourceId, deviceId); { diff --git a/src/light_control/light_controller.hpp b/src/light_control/light_controller.hpp index 38b713a..6f8717a 100644 --- a/src/light_control/light_controller.hpp +++ b/src/light_control/light_controller.hpp @@ -20,6 +20,9 @@ public: void UpdateAutoLight(std::string deviceId, std::string sourceId, bool voteOn); void RemoveSession(std::string sourceId); +public: + std::map deviceStatus; + private: static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp); bool SendHttpCommand(std::string deviceId, std::string switchType); @@ -41,4 +44,14 @@ private: // 待执行的任务表:Key=设备ID, Value=动作("1"或"0") // 使用 map 的好处是:同一个设备的多次指令会自动覆盖,只保留最新的! std::map pending_actions_; + + void InitializeDevices() { + // 假设这些是你的设备 ID + std::vector deviceIds = {"349", "350", "351", "352", "353", "354"}; + + // 遍历 ID 并初始化为 false + for (const auto& id : deviceIds) { + deviceStatus[id] = false; + } + } }; \ No newline at end of file diff --git a/src/web/web_server.cc b/src/web/web_server.cc index bcd7903..29b63ac 100644 --- a/src/web/web_server.cc +++ b/src/web/web_server.cc @@ -781,6 +781,7 @@ void WebServer::setup_routes() { auto service = m_video_manager.getService(stream_id); if (service) { service->set_analysis_mode(1); + affected_streams.push_back(stream_id); } } @@ -961,6 +962,7 @@ void WebServer::setup_routes() { * - mode: 1 (普通报警), 2 (快速响应) */ CROW_ROUTE((*this), "/api/video/mode").methods("POST"_method)([this](const crow::request& req) { + LightController* ctrl = &m_light_controller; crow::json::rvalue j_body; try { j_body = crow::json::load(req.body); @@ -980,6 +982,12 @@ void WebServer::setup_routes() { if (service) { // 调用内存中的对象修改状态 bool result = service->set_analysis_mode(mode); + if (mode == 2) { + for (auto& [id, status] : ctrl->deviceStatus){ + status = true; + spdlog::info("force controll set:{}", status); + } + } if (!result) { spdlog::warn("Failed to set runtime mode for stream {}", stream_id); // 注意:这里即使运行时失败,只要配置能保存,也可以继续往下走,或者直接返回错误