temp
This commit is contained in:
parent
448ea73af9
commit
ec4790e65d
@ -66,24 +66,22 @@ static void on_mqtt_message_received(const std::string &topic, const std::string
|
|||||||
|
|
||||||
int switch_val = data.value("switch", 0);
|
int switch_val = data.value("switch", 0);
|
||||||
int streamType = data.value("streamType", 0); // 0主 1子
|
int streamType = data.value("streamType", 0); // 0主 1子
|
||||||
StreamType type = (streamTypeInt == 0) ? StreamType::MAIN : StreamType::SUB;
|
StreamType type = (streamType == 0) ? StreamType::MAIN : StreamType::SUB;
|
||||||
auto channels = data.value("channels", std::vector<int>{});
|
auto channels = data.value("channels", std::vector<int>{});
|
||||||
|
|
||||||
nlohmann::json resp_data = nlohmann::json::array();
|
nlohmann::json resp_data = nlohmann::json::array();
|
||||||
|
|
||||||
for (int ch : channels)
|
for (int ch : channels)
|
||||||
{
|
{
|
||||||
// 根据通道号找到摄像头
|
// 用数组索引找到摄像头
|
||||||
auto it = std::find_if(g_app_config.cameras.begin(), g_app_config.cameras.end(),
|
if (ch < 0 || ch >= static_cast<int>(g_app_config.cameras.size()))
|
||||||
[ch](const Camera &c)
|
|
||||||
{ return c.channel == ch; });
|
|
||||||
|
|
||||||
nlohmann::json ch_resp;
|
|
||||||
ch_resp["loc"] = ch;
|
|
||||||
|
|
||||||
if (it != g_app_config.cameras.end())
|
|
||||||
{
|
{
|
||||||
Camera &cam = *it;
|
LOG_WARN("[MQTT] Invalid channel: " + std::to_string(ch));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Camera &cam = g_app_config.cameras[ch];
|
||||||
|
|
||||||
bool op_result = false;
|
bool op_result = false;
|
||||||
|
|
||||||
if (switch_val == 0)
|
if (switch_val == 0)
|
||||||
@ -105,16 +103,11 @@ static void on_mqtt_message_received(const std::string &topic, const std::string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nlohmann::json ch_resp;
|
||||||
|
ch_resp["loc"] = ch;
|
||||||
ch_resp["url"] = op_result ? RTMPManager::get_stream_url(cam.name, type) : "";
|
ch_resp["url"] = op_result ? RTMPManager::get_stream_url(cam.name, type) : "";
|
||||||
ch_resp["result"] = op_result ? 0 : 1;
|
ch_resp["result"] = op_result ? 0 : 1;
|
||||||
ch_resp["reason"] = op_result ? "" : "already in requested state";
|
ch_resp["reason"] = op_result ? "" : "already in requested state";
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ch_resp["url"] = "";
|
|
||||||
ch_resp["result"] = 1;
|
|
||||||
ch_resp["reason"] = "channel not found";
|
|
||||||
}
|
|
||||||
|
|
||||||
resp_data.push_back(ch_resp);
|
resp_data.push_back(ch_resp);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user