diff --git a/src/slic3r/GUI/MediaFilePanel.cpp b/src/slic3r/GUI/MediaFilePanel.cpp index 40dc99c03..dc23159a0 100644 --- a/src/slic3r/GUI/MediaFilePanel.cpp +++ b/src/slic3r/GUI/MediaFilePanel.cpp @@ -208,6 +208,7 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj) if (machine == m_machine) return; m_machine = machine; + m_last_errors.clear(); auto fs = m_image_grid->GetFileSystem(); if (fs) { m_image_grid->SetFileSystem(nullptr); @@ -265,7 +266,7 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj) if (e.GetInt() == PrinterFileSystem::Initializing) fetchUrl(boost::weak_ptr(fs)); - if (status == PrinterFileSystem::Failed + if ((status == PrinterFileSystem::Failed && m_last_errors.find(fs->GetLastError()) == m_last_errors.end()) || status == PrinterFileSystem::ListReady) { json j; j["code"] = fs->GetLastError(); @@ -281,6 +282,7 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj) if (agent) agent->track_event("download_video_conn", j.dump()); } + m_last_errors.insert(fs->GetLastError()); } }); fs->Bind(EVT_DOWNLOAD, [this, wfs = boost::weak_ptr(fs)](auto& e) { diff --git a/src/slic3r/GUI/MediaFilePanel.h b/src/slic3r/GUI/MediaFilePanel.h index 286ca52b8..666d70cb6 100644 --- a/src/slic3r/GUI/MediaFilePanel.h +++ b/src/slic3r/GUI/MediaFilePanel.h @@ -85,6 +85,7 @@ private: int m_last_mode = 0; int m_last_type = 0; + std::set m_last_errors; }; diff --git a/src/slic3r/GUI/MediaPlayCtrl.cpp b/src/slic3r/GUI/MediaPlayCtrl.cpp index f639d6e64..2d267d9db 100644 --- a/src/slic3r/GUI/MediaPlayCtrl.cpp +++ b/src/slic3r/GUI/MediaPlayCtrl.cpp @@ -100,6 +100,7 @@ void MediaPlayCtrl::SetMachineObject(MachineObject* obj) m_machine = machine; BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl switch machine: " << m_machine; m_failed_retry = 0; + m_last_failed_codes.clear(); std::string stream_url; if (get_stream_url(&stream_url)) { m_streaming = boost::algorithm::contains(stream_url, "device=" + m_machine); @@ -215,7 +216,7 @@ void MediaPlayCtrl::Play() void MediaPlayCtrl::Stop(wxString const &msg) { - bool init_failed = m_last_state != wxMEDIASTATE_PLAYING; + int last_state = m_last_state; if (m_last_state != MEDIASTATE_IDLE) { m_media_ctrl->InvalidateBestSize(); @@ -238,19 +239,22 @@ void MediaPlayCtrl::Stop(wxString const &msg) m_failed_code = 0; } - if (init_failed && m_failed_code != 0 && m_last_failed_code != m_failed_code) { + if (last_state != wxMEDIASTATE_PLAYING && m_failed_code != 0 + && m_last_failed_codes.find(m_failed_code) == m_last_failed_codes.end() + && (m_user_triggered || m_failed_retry > 3)) { json j; - j["stage"] = std::to_string(m_last_state); + j["stage"] = last_state; j["dev_id"] = m_machine; j["dev_ip"] = m_lan_ip; j["result"] = "failed"; + j["user_triggered"] = m_user_triggered; j["code"] = m_failed_code; j["msg"] = into_u8(msg); NetworkAgent *agent = wxGetApp().getAgent(); if (agent) agent->track_event("start_liveview", j.dump()); + m_last_failed_codes.insert(m_failed_code); } - m_last_failed_code = m_failed_code; ++m_failed_retry; if (m_failed_code != 0 && !m_tutk_support && (m_failed_retry > 1 || m_user_triggered)) { @@ -258,7 +262,7 @@ void MediaPlayCtrl::Stop(wxString const &msg) if (wxGetApp().show_modal_ip_address_enter_dialog(_L("LAN Connection Failed (Failed to start liveview)"))) { m_failed_retry = 0; m_user_triggered = true; - m_last_failed_code = 0; + m_last_failed_codes.clear(); m_next_retry = wxDateTime::Now(); return; } @@ -276,7 +280,7 @@ void MediaPlayCtrl::TogglePlay() } else { m_failed_retry = 0; m_user_triggered = true; - m_last_failed_code = 0; + m_last_failed_codes.clear(); m_next_retry = wxDateTime::Now(); Play(); } diff --git a/src/slic3r/GUI/MediaPlayCtrl.h b/src/slic3r/GUI/MediaPlayCtrl.h index 05bc6d9ef..45de46620 100644 --- a/src/slic3r/GUI/MediaPlayCtrl.h +++ b/src/slic3r/GUI/MediaPlayCtrl.h @@ -16,6 +16,7 @@ #include #include +#include class Button; class Label; @@ -86,7 +87,7 @@ private: bool m_user_triggered = false; int m_failed_retry = 0; int m_failed_code = 0; - int m_last_failed_code = 0; + std::set m_last_failed_codes; wxDateTime m_next_retry; ::Button *m_button_play; diff --git a/src/slic3r/GUI/Printer/BambuTunnel.h b/src/slic3r/GUI/Printer/BambuTunnel.h index 572f8dd5a..bd00bdce9 100644 --- a/src/slic3r/GUI/Printer/BambuTunnel.h +++ b/src/slic3r/GUI/Printer/BambuTunnel.h @@ -21,12 +21,12 @@ extern "C" { #endif // __cplusplus -#ifndef __cplusplus -#include -#endif - #ifdef _WIN32 +#ifdef __cplusplus typedef wchar_t tchar; +#else + typedef unsigned short tchar; +#endif #else typedef char tchar; #endif @@ -117,7 +117,7 @@ BAMBU_EXPORT void BAMBU_FUNC(Bambu_SetLogger)(Bambu_Tunnel tunnel, Logger logger BAMBU_EXPORT int BAMBU_FUNC(Bambu_Open)(Bambu_Tunnel tunnel); -BAMBU_EXPORT int BAMBU_FUNC(Bambu_StartStream)(Bambu_Tunnel tunnel, bool video); +BAMBU_EXPORT int BAMBU_FUNC(Bambu_StartStream)(Bambu_Tunnel tunnel, int video); BAMBU_EXPORT int BAMBU_FUNC(Bambu_GetStreamCount)(Bambu_Tunnel tunnel); diff --git a/src/slic3r/GUI/Printer/PrinterFileSystem.cpp b/src/slic3r/GUI/Printer/PrinterFileSystem.cpp index e4199ffa7..9596d19fa 100644 --- a/src/slic3r/GUI/Printer/PrinterFileSystem.cpp +++ b/src/slic3r/GUI/Printer/PrinterFileSystem.cpp @@ -1074,9 +1074,14 @@ void PrinterFileSystem::Reconnect(boost::unique_lock &l, int resul if (ret == 0) ret = Bambu_StartStream(tunnel, false); l.lock(); - m_session.tunnel = tunnel; - if (ret == 0) + if (ret == 0) { + m_session.tunnel = tunnel; break; + } + if (tunnel) { + Bambu_Close(tunnel); + Bambu_Destroy(tunnel); + } m_last_error = ret; } m_status = Status::Failed; diff --git a/src/slic3r/GUI/wxMediaCtrl2.mm b/src/slic3r/GUI/wxMediaCtrl2.mm index bb78fe535..b3b8775e7 100644 --- a/src/slic3r/GUI/wxMediaCtrl2.mm +++ b/src/slic3r/GUI/wxMediaCtrl2.mm @@ -89,8 +89,8 @@ void wxMediaCtrl2::Load(wxURI url) BambuPlayer * player = (BambuPlayer *) m_player; if (player) { [player close]; - [player open: url.BuildURI().ToUTF8()]; m_error = 0; + [player open: url.BuildURI().ToUTF8()]; } wxMediaEvent event(wxEVT_MEDIA_STATECHANGED); event.SetId(GetId());