OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::WebMediaController Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/WebMediaController.hpp>

Inheritance diagram for Slic3r::GUI::WebMediaController:
Collaboration diagram for Slic3r::GUI::WebMediaController:

Public Member Functions

 WebMediaController (wxWebView *webview)
void Load (wxURI url) override
void set_mode (CameraStreamMode mode)
void Play () override
void Stop () override
virtual wxMediaState GetState ()
virtual int GetLastError () const
virtual wxSize GetVideoSize () const

Private Attributes

wxWebView * m_webview = nullptr
std::string m_url
CameraStreamMode m_stream_mode = CameraStreamMode::http

Detailed Description

Constructor & Destructor Documentation

◆ WebMediaController()

Slic3r::GUI::WebMediaController::WebMediaController ( wxWebView * webview)
explicit
24 : m_webview(webview)
25{
27}
wxWebView * m_webview
Definition WebMediaController.hpp:27
void initialize_webview(wxWebView *webview)
Definition WebMediaController.cpp:12

References m_webview.

Member Function Documentation

◆ GetLastError()

virtual int Slic3r::GUI::IMediaController::GetLastError ( ) const
inlinevirtualinherited

Reimplemented in wxMediaCtrl3.

22{ return {}; };

◆ GetState()

virtual wxMediaState Slic3r::GUI::IMediaController::GetState ( )
inlinevirtualinherited

Reimplemented in Slic3r::GUI::WebRtcMediaController, and wxMediaCtrl3.

20{ return wxMediaState{}; }

◆ GetVideoSize()

virtual wxSize Slic3r::GUI::IMediaController::GetVideoSize ( ) const
inlinevirtualinherited

Reimplemented in Slic3r::GUI::WebRtcMediaController, and wxMediaCtrl3.

24{ return {}; };

◆ Load()

void Slic3r::GUI::WebMediaController::Load ( wxURI url)
overridevirtual

Implements Slic3r::GUI::IMediaController.

30{
31 m_url = url.BuildURI().ToStdString();
32}
std::string m_url
Definition WebMediaController.hpp:28

References m_url.

◆ Play()

void Slic3r::GUI::WebMediaController::Play ( )
overridevirtual

Implements Slic3r::GUI::IMediaController.

40{
41 if (!m_webview)
42 return;
43
44 wxString url = wxString::FromUTF8(m_url);
45 wxString html = "<html><head><style>"
46 "html,body{margin:0;height:100%;background:#000;overflow:hidden;}"
47 "img{width:100%;height:100%;object-fit:contain;display:block;}"
48 "</style></head><body><img id=\"camera-frame\"";
50 html += " data-camera-url=\"" + url +
51 "\"><script>"
52 "const cameraFrame=document.getElementById('camera-frame');"
53 "const cameraUrl=cameraFrame.dataset.cameraUrl;"
54 "let cameraFrameLoading=false;"
55 "function refreshCameraFrame(){"
56 "if(cameraFrameLoading)return;"
57 "cameraFrameLoading=true;"
58 "const nextFrame=new Image();"
59 "nextFrame.onload=function(){cameraFrame.src=nextFrame.src;cameraFrameLoading=false;};"
60 "nextFrame.onerror=function(){cameraFrameLoading=false;};"
61 "nextFrame.src=cameraUrl+(cameraUrl.indexOf('?')>=0?'&':'?')+'_orca_frame='+Date.now();"
62 "}"
63 "let cameraRefreshInterval=null;"
64 "function stopCameraRefresh(){"
65 "if(cameraRefreshInterval!==null){"
66 "clearInterval(cameraRefreshInterval);"
67 "cameraRefreshInterval=null;"
68 "}"
69 "}"
70 "refreshCameraFrame();"
71 "cameraRefreshInterval = setInterval(refreshCameraFrame,200);"
72 "</script></body></html>";
73 m_webview->SetPage(html, url);
74 } else {
75 // Load MJPEG streams as the top-level document. Some embedded WebView
76 // backends buffer a multipart stream when it is used as an <img> resource,
77 // which introduces noticeable live-view latency.
78 m_webview->LoadURL(url);
79 }
80}
CameraStreamMode m_stream_mode
Definition WebMediaController.hpp:29
@ http_snapshot
Definition IPrinterAgent.hpp:68

References Slic3r::http_snapshot, m_stream_mode, m_url, and m_webview.

◆ set_mode()

void Slic3r::GUI::WebMediaController::set_mode ( CameraStreamMode mode)
35{
36 m_stream_mode = mode;
37}

References m_stream_mode.

◆ Stop()

void Slic3r::GUI::WebMediaController::Stop ( )
overridevirtual

Implements Slic3r::GUI::IMediaController.

83{
84 if (m_webview) {
85 m_webview->RunScript("if(typeof stopCameraRefresh==='function') stopCameraRefresh();");
86 m_webview->Stop();
87 m_webview->SetPage("", "about:blank");
88 m_webview->ClearHistory();
89 }
90 m_url.clear();
91}

References m_url, and m_webview.

Member Data Documentation

◆ m_stream_mode

CameraStreamMode Slic3r::GUI::WebMediaController::m_stream_mode = CameraStreamMode::http
private

Referenced by Play(), and set_mode().

◆ m_url

std::string Slic3r::GUI::WebMediaController::m_url
private

Referenced by Load(), Play(), and Stop().

◆ m_webview

wxWebView* Slic3r::GUI::WebMediaController::m_webview = nullptr
private

Referenced by WebMediaController(), Play(), and Stop().


The documentation for this class was generated from the following files: