From 6b5ba840752ee369eb8e7abbd89b4d15c5435160 Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Mon, 14 Aug 2023 14:44:17 +0800 Subject: [PATCH] ENH: [STUDIO-4029] ipcam compatible remake Change-Id: Ic6cda7daa6a4e3b03fe645d8ae60f1e68a2c3864 --- src/slic3r/GUI/CameraPopup.cpp | 2 +- src/slic3r/GUI/DeviceManager.cpp | 97 +++++++++++++------------------ src/slic3r/GUI/DeviceManager.hpp | 24 ++++---- src/slic3r/GUI/MediaFilePanel.cpp | 6 +- src/slic3r/GUI/MediaPlayCtrl.cpp | 18 +++--- src/slic3r/GUI/StatusPanel.cpp | 2 +- 6 files changed, 66 insertions(+), 83 deletions(-) diff --git a/src/slic3r/GUI/CameraPopup.cpp b/src/slic3r/GUI/CameraPopup.cpp index b21c37878..db7a45baa 100644 --- a/src/slic3r/GUI/CameraPopup.cpp +++ b/src/slic3r/GUI/CameraPopup.cpp @@ -268,7 +268,7 @@ void CameraPopup::check_func_supported(MachineObject *obj2) m_switch_recording->Hide(); } - if (m_obj->is_function_supported(PrinterFunction::FUNC_VIRTUAL_CAMERA) && m_obj->has_ipcam) { + if (m_obj->virtual_camera && m_obj->has_ipcam) { m_text_vcamera->Show(); m_switch_vcamera->Show(); if (is_vcamera_show) { diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 987d3b30c..25ce797c2 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -1446,24 +1446,18 @@ void MachineObject::parse_version_func() is_support_mqtt_alive = ota_version->second.sw_ver.compare("01.05.06.05") >= 0; } - is_support_remote_tunnel = true; is_support_tunnel_mqtt = (ota_version->second.sw_ver.compare("01.05.06.06") >= 0 || (rv1126_version != module_vers.end() && rv1126_version->second.sw_ver.compare("00.00.21.20") >= 0)); } - local_camera_proto = local_rtsp_url.empty() ? -1 : local_rtsp_url == "disable" ? 0 - : boost::algorithm::starts_with(local_rtsp_url, "rtsps") ? 2 : 3; - file_proto = 2; } } else if (printer_type == "C11") { is_cloud_print_only = true; if (ota_version != module_vers.end()) { is_support_send_to_sdcard = ota_version->second.sw_ver.compare("01.02.00.00") >= 0; is_support_ai_monitoring = ota_version->second.sw_ver.compare("01.02.99.00") >= 0; - is_support_remote_tunnel = ota_version->second.sw_ver.compare("01.02.99.00") >= 0; is_support_tunnel_mqtt = (ota_version->second.sw_ver.compare("01.03.50.01") >= 0 || (esp32_version != module_vers.end() && esp32_version->second.sw_ver.compare("01.05.15.00") >= 0)); } - local_camera_proto = 1; if (esp32_version != module_vers.end()) { ams_support_auto_switch_filament_flag = esp32_version->second.sw_ver.compare("00.03.11.50") >= 0; @@ -1483,12 +1477,10 @@ void MachineObject::parse_version_func() } else if (printer_type == "C12") { is_support_ai_monitoring = true; is_cloud_print_only = true; - local_camera_proto = 1; if (ota_version != module_vers.end()) { is_support_tunnel_mqtt = (ota_version->second.sw_ver.compare("01.03.50.01") >= 0 || (esp32_version != module_vers.end() && esp32_version->second.sw_ver.compare("01.05.15.00") >= 0)); - is_support_remote_tunnel = ota_version->second.sw_ver.compare("01.03.50.01") >= 0; if (lifecycle == PrinterFirmwareType::FIRMWARE_TYPE_PRODUCTION) { is_support_mqtt_alive = ota_version->second.sw_ver.compare("01.03.50.01") >= 0; } @@ -2580,21 +2572,6 @@ bool MachineObject::is_function_supported(PrinterFunction func) case FUNC_CHAMBER_TEMP: func_name = "FUNC_CHAMBER_TEMP"; break; - case FUNC_CAMERA_VIDEO: - func_name = "FUNC_CAMERA_VIDEO"; - break; - case FUNC_MEDIA_FILE: - func_name = "FUNC_MEDIA_FILE"; - break; - case FUNC_REMOTE_TUNNEL: - parse_version_func(); - if (!is_support_remote_tunnel) - return false; - break; - case FUNC_LOCAL_TUNNEL: - parse_version_func(); - if (!local_camera_proto) return false; - break; case FUNC_PRINT_WITHOUT_SD: func_name = "FUNC_PRINT_WITHOUT_SD"; break; @@ -2616,9 +2593,6 @@ bool MachineObject::is_function_supported(PrinterFunction func) return false; func_name = "FUNC_AUTO_SWITCH_FILAMENT"; break; - case FUNC_VIRTUAL_CAMERA: - func_name = "FUNC_VIRTUAL_CAMERA"; - break; case FUNC_CHAMBER_FAN: func_name = "FUNC_CHAMBER_FAN"; break; @@ -2646,7 +2620,7 @@ bool MachineObject::is_function_supported(PrinterFunction func) std::vector MachineObject::get_resolution_supported() { - return DeviceManager::get_resolution_supported(printer_type); + return camera_resolution_supported; } bool MachineObject::is_support_print_with_timelapse() @@ -2662,24 +2636,6 @@ bool MachineObject::is_camera_busy_off() return false; } -int MachineObject::get_local_camera_proto() -{ - if (!is_function_supported(PrinterFunction::FUNC_LOCAL_TUNNEL)) return 0; - return local_camera_proto; -} - -bool MachineObject::has_local_file_proto() -{ - parse_version_func(); - return file_proto & 1; -} - -bool MachineObject::has_remote_file_proto() -{ - parse_version_func(); - return file_proto & 2; -} - int MachineObject::publish_json(std::string json_str, int qos) { if (is_lan_mode_printer()) { @@ -2732,6 +2688,14 @@ std::string MachineObject::setting_id_to_type(std::string setting_id, std::strin return type; } +template +static ENUM enum_index_of(char const *key, char const **enum_names, int enum_count, ENUM defl = static_cast(0)) +{ + for (int i = 0; i < enum_count; ++i) + if (strcmp(enum_names[i], key) == 0) return static_cast(i); + return defl; +} + int MachineObject::parse_json(std::string payload) { CNumericLocalesSetter locales_setter; @@ -3329,11 +3293,12 @@ int MachineObject::parse_json(std::string payload) // parse camera info try { if (jj.contains("ipcam")) { - if (jj["ipcam"].contains("ipcam_record")) { + json const & ipcam = jj["ipcam"]; + if (ipcam.contains("ipcam_record")) { if (camera_recording_hold_count > 0) camera_recording_hold_count--; else { - if (jj["ipcam"]["ipcam_record"].get() == "enable") { + if (ipcam["ipcam_record"].get() == "enable") { camera_recording_when_printing = true; } else { @@ -3341,11 +3306,11 @@ int MachineObject::parse_json(std::string payload) } } } - if (jj["ipcam"].contains("timelapse")) { + if (ipcam.contains("timelapse")) { if (camera_timelapse_hold_count > 0) camera_timelapse_hold_count--; else { - if (jj["ipcam"]["timelapse"].get() == "enable") { + if (ipcam["timelapse"].get() == "enable") { camera_timelapse = true; } else { @@ -3353,25 +3318,43 @@ int MachineObject::parse_json(std::string payload) } } } - if (jj["ipcam"].contains("ipcam_dev")) { - if (jj["ipcam"]["ipcam_dev"].get() == "1") { + if (ipcam.contains("ipcam_dev")) { + if (ipcam["ipcam_dev"].get() == "1") { has_ipcam = true; } else { has_ipcam = false; } } - if (jj["ipcam"].contains("resolution")) { + if (ipcam.contains("resolution")) { if (camera_resolution_hold_count > 0) camera_resolution_hold_count--; else { - camera_resolution = jj["ipcam"]["resolution"].get(); + camera_resolution = ipcam["resolution"].get(); } } - if (jj["ipcam"].contains("rtsp_url")) { - local_rtsp_url = jj["ipcam"]["rtsp_url"].get(); + if (ipcam.contains("resolution_supported")) { + std::vector resolution_supported; + for (auto res : ipcam["resolution_supported"]) + resolution_supported.emplace_back(res.get()); + camera_resolution_supported.swap(resolution_supported); } - if (jj["ipcam"].contains("tutk_server")) { - tutk_state = jj["ipcam"]["tutk_server"].get(); + if (ipcam.contains("liveview")) { + char const *local_protos[] = { "none", "local", "rtsps", "rtsp" }; + liveview_local = enum_index_of(ipcam["liveview"].value("local", "none").c_str(), local_protos, 4, LiveviewLocal::LVL_None); + liveview_remote = ipcam["liveview"].value("remote", "disabled") == "enabled"; + } + if (ipcam.contains("file")) { + file_local = ipcam["file"].value("local", "disabled") == "enabled"; + file_remote = ipcam["file"].value("remote", "disabled") == "enabled"; + } + virtual_camera = ipcam.value("virtual_camera", "disabled") == "enabled"; + if (ipcam.contains("rtsp_url")) { + local_rtsp_url = ipcam["rtsp_url"].get(); + liveview_local = local_rtsp_url.empty() ? LVL_None : local_rtsp_url == "disable" + ? LVL_None : boost::algorithm::starts_with(local_rtsp_url, "rtsps") ? LVL_Rtsps : LVL_Rtsp; + } + if (ipcam.contains("tutk_server")) { + tutk_state = ipcam["tutk_server"].get(); } } } diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index d6eec94c4..7897a8fed 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -70,12 +70,7 @@ enum PrinterFunction { FUNC_FLOW_CALIBRATION, FUNC_AUTO_LEVELING, FUNC_CHAMBER_TEMP, - FUNC_CAMERA_VIDEO, - FUNC_MEDIA_FILE, - FUNC_REMOTE_TUNNEL, - FUNC_LOCAL_TUNNEL, FUNC_PRINT_WITHOUT_SD, - FUNC_VIRTUAL_CAMERA, FUNC_USE_AMS, FUNC_ALTER_RESOLUTION, FUNC_SEND_TO_SDCARD, @@ -676,14 +671,22 @@ public: int camera_recording_hold_count = 0; int camera_timelapse_hold_count = 0; int camera_resolution_hold_count = 0; - std::string camera_resolution = ""; + std::string camera_resolution = ""; + std::vector camera_resolution_supported; bool xcam_first_layer_inspector { false }; int xcam_first_layer_hold_count = 0; - int local_camera_proto = -1; - int file_proto = 0; std::string local_rtsp_url; std::string tutk_state; - bool is_support_remote_tunnel{false}; + enum LiveviewLocal { + LVL_None, + LVL_Local, + LVL_Rtsps, + LVL_Rtsp + } liveview_local{ LVL_None }; + bool liveview_remote{false}; + bool file_local{false}; + bool file_remote{false}; + bool virtual_camera{false}; bool xcam_ai_monitoring{ false }; int xcam_ai_monitoring_hold_count = 0; @@ -851,9 +854,6 @@ public: std::vector get_resolution_supported(); bool is_support_print_with_timelapse(); bool is_camera_busy_off(); - int get_local_camera_proto(); - bool has_local_file_proto(); - bool has_remote_file_proto(); /* Msg for display MsgFn */ typedef std::function MsgFn; diff --git a/src/slic3r/GUI/MediaFilePanel.cpp b/src/slic3r/GUI/MediaFilePanel.cpp index 713aa50e1..024c41bc2 100644 --- a/src/slic3r/GUI/MediaFilePanel.cpp +++ b/src/slic3r/GUI/MediaFilePanel.cpp @@ -201,14 +201,14 @@ MediaFilePanel::~MediaFilePanel() void MediaFilePanel::SetMachineObject(MachineObject* obj) { std::string machine = obj ? obj->dev_id : ""; - if (obj && obj->is_function_supported(PrinterFunction::FUNC_MEDIA_FILE)) { + if (obj) { m_supported = true; m_lan_mode = obj->is_lan_mode_printer(); m_lan_ip = obj->dev_ip; m_lan_passwd = obj->get_access_code(); m_dev_ver = obj->get_ota_version(); - m_local_support = obj->has_local_file_proto(); - m_remote_support = obj->has_remote_file_proto(); + m_local_support = obj->file_local; + m_remote_support = obj->file_remote; } else { m_supported = false; m_lan_mode = false; diff --git a/src/slic3r/GUI/MediaPlayCtrl.cpp b/src/slic3r/GUI/MediaPlayCtrl.cpp index 854482028..8c73563a9 100644 --- a/src/slic3r/GUI/MediaPlayCtrl.cpp +++ b/src/slic3r/GUI/MediaPlayCtrl.cpp @@ -77,20 +77,20 @@ MediaPlayCtrl::~MediaPlayCtrl() void MediaPlayCtrl::SetMachineObject(MachineObject* obj) { std::string machine = obj ? obj->dev_id : ""; - if (obj && obj->is_function_supported(PrinterFunction::FUNC_CAMERA_VIDEO)) { + if (obj) { m_camera_exists = obj->has_ipcam; + m_dev_ver = obj->get_ota_version(); m_lan_mode = obj->is_lan_mode_printer(); - m_lan_proto = obj->get_local_camera_proto(); + m_lan_proto = obj->liveview_local; + m_remote_support = obj->liveview_remote; m_lan_ip = obj->dev_ip; m_lan_passwd = obj->get_access_code(); - m_dev_ver = obj->get_ota_version(); - m_remote_support = obj->is_function_supported(PrinterFunction::FUNC_REMOTE_TUNNEL); m_device_busy = obj->is_camera_busy_off(); m_tutk_state = obj->tutk_state; } else { m_camera_exists = false; m_lan_mode = false; - m_lan_proto = -1; + m_lan_proto = MachineObject::LVL_None; m_lan_ip.clear(); m_lan_passwd.clear(); m_dev_ver.clear(); @@ -155,13 +155,13 @@ void MediaPlayCtrl::Play() m_button_play->SetIcon("media_stop"); NetworkAgent *agent = wxGetApp().getAgent(); std::string agent_version = agent ? agent->get_version() : ""; - if (m_lan_proto > 0 && (m_lan_mode ||!m_remote_support) && !m_disable_lan && !m_lan_ip.empty()) { + if (m_lan_proto > MachineObject::LVL_None && (m_lan_mode || !m_remote_support) && !m_disable_lan && !m_lan_ip.empty()) { m_disable_lan = m_remote_support && !m_lan_mode; // try remote next time - if (m_lan_proto == 1) + if (m_lan_proto == MachineObject::LVL_Local) m_url = "bambu:///local/" + m_lan_ip + ".?port=6000&user=" + m_lan_user + "&passwd=" + m_lan_passwd; - else if (m_lan_proto == 2) + else if (m_lan_proto == MachineObject::LVL_Rtsps) m_url = "bambu:///rtsps___" + m_lan_user + ":" + m_lan_passwd + "@" + m_lan_ip + "/streaming/live/1?proto=rtsps"; - else if (m_lan_proto == 3) + else if (m_lan_proto == MachineObject::LVL_Rtsp) m_url = "bambu:///rtsp___" + m_lan_user + ":" + m_lan_passwd + "@" + m_lan_ip + "/streaming/live/1?proto=rtsp"; m_url += "&device=" + m_machine; m_url += "&version=" + agent_version; diff --git a/src/slic3r/GUI/StatusPanel.cpp b/src/slic3r/GUI/StatusPanel.cpp index 3ef22fb5a..9294c7516 100644 --- a/src/slic3r/GUI/StatusPanel.cpp +++ b/src/slic3r/GUI/StatusPanel.cpp @@ -1397,7 +1397,7 @@ void StatusPanel::update_camera_state(MachineObject* obj) } //vcamera - if (obj->is_function_supported(PrinterFunction::FUNC_VIRTUAL_CAMERA)) { + if (obj->virtual_camera) { if (m_last_vcamera != (m_media_play_ctrl->IsStreaming() ? 1: 0)) { if (m_media_play_ctrl->IsStreaming()) { m_bitmap_vcamera_img->SetBitmap(m_bitmap_vcamera_on.bmp());