temp
This commit is contained in:
parent
ec4790e65d
commit
5137f45e30
@ -57,9 +57,7 @@ static void on_mqtt_message_received(const std::string &topic, const std::string
|
||||
{
|
||||
auto j = nlohmann::json::parse(message);
|
||||
|
||||
if (topic == g_app_config.mqtt.topics.video_down)
|
||||
{
|
||||
if (topic.find("/kun/vehicle/video/push/") != std::string::npos && j["type"] == "request")
|
||||
if (topic == g_app_config.mqtt.topics.video_down && j["type"] == "request")
|
||||
{
|
||||
std::string seqNo = j.value("seqNo", "");
|
||||
auto data = j["data"];
|
||||
@ -73,21 +71,15 @@ static void on_mqtt_message_received(const std::string &topic, const std::string
|
||||
|
||||
for (int ch : channels)
|
||||
{
|
||||
// 用数组索引找到摄像头
|
||||
if (ch < 0 || ch >= static_cast<int>(g_app_config.cameras.size()))
|
||||
{
|
||||
LOG_WARN("[MQTT] Invalid channel: " + std::to_string(ch));
|
||||
continue;
|
||||
}
|
||||
|
||||
Camera &cam = g_app_config.cameras[ch];
|
||||
|
||||
bool op_result = false;
|
||||
|
||||
if (switch_val == 0)
|
||||
{
|
||||
// 启动流
|
||||
if (!RTMPManager::is_streaming(cam.name, type))
|
||||
if (!RTMPManager::is_streaming(cam.name))
|
||||
{
|
||||
RTMPManager::start_camera(cam, type);
|
||||
op_result = true;
|
||||
@ -95,8 +87,7 @@ static void on_mqtt_message_received(const std::string &topic, const std::string
|
||||
}
|
||||
else
|
||||
{
|
||||
// 停止流
|
||||
if (RTMPManager::is_streaming(cam.name, type))
|
||||
if (RTMPManager::is_streaming(cam.name))
|
||||
{
|
||||
RTMPManager::stop_camera(cam.name, type);
|
||||
op_result = true;
|
||||
@ -112,18 +103,12 @@ static void on_mqtt_message_received(const std::string &topic, const std::string
|
||||
resp_data.push_back(ch_resp);
|
||||
}
|
||||
|
||||
// 构造应答
|
||||
nlohmann::json reply;
|
||||
reply["type"] = "response";
|
||||
reply["seqNo"] = seqNo;
|
||||
reply["data"] = resp_data;
|
||||
|
||||
mqtt_client->publish(topic, reply.dump());
|
||||
LOG_INFO("[MQTT] Replied to video push request: " + reply.dump());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARN("[MQTT] Unknown topic or non-request type: " + topic);
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
@ -131,7 +116,6 @@ static void on_mqtt_message_received(const std::string &topic, const std::string
|
||||
LOG_ERROR(std::string("[MQTT] Failed to process incoming JSON: ") + e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mqtt_client_thread_func()
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user