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

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

Inheritance diagram for Slic3r::GUI::WebRtcMediaController:
Collaboration diagram for Slic3r::GUI::WebRtcMediaController:

Classes

struct  Status

Public Member Functions

 WebRtcMediaController (std::function< void(const wxImage &, wxSize)> frame_sink, std::function< void(Status)> on_status)
 ~WebRtcMediaController () override
void set_signalling_channel (std::unique_ptr< ICameraSignalingChannel > channel)
std::uint64_t epoch () const
bool is_active () const
void Load (wxURI) override
void Play () override
void Stop () override
wxMediaState GetState () override
wxSize GetVideoSize () const override
virtual int GetLastError () const

Private Member Functions

void teardown (bool notify)
void report (Status status)
void bind_data_channel (const std::shared_ptr< rtc::DataChannel > &dc)
void on_ready (std::vector< CameraIceServer > servers)
void on_answer (std::string sdp)
void on_ice (std::string candidate, std::string mid)
void on_unavailable (CameraUnavailableReason reason, std::string detail)
void decode_loop ()
void enqueue_jpeg (std::vector< std::byte > jpeg)
void deliver_jpeg (std::vector< std::byte > jpeg)

Private Attributes

std::mutex m_mutex
std::condition_variable m_cond
std::deque< std::vector< std::byte > > m_jpeg_queue
std::vector< std::pair< std::string, std::string > > m_pending_candidates
bool m_remote_description_set = false
std::unique_ptr< ICameraSignalingChannel > m_pending_signaling
std::unique_ptr< ICameraSignalingChannel > m_signaling
std::shared_ptr< rtc::PeerConnection > m_peer_connection
std::shared_ptr< rtc::DataChannel > m_data_channel
std::thread m_decode_thread
std::atomic< bool > m_alive {false}
std::atomic< std::uint64_t > m_epoch {0}
wxMediaState m_state = static_cast<wxMediaState>(3)
wxSize m_video_size = wxDefaultSize
std::function< void(const wxImage &, wxSize)> m_frame_sink
std::function< void(Status)> m_on_status
bool m_has_frame = false
std::chrono::steady_clock::time_point m_last_frame_time {}

Detailed Description

Constructor & Destructor Documentation

◆ WebRtcMediaController()

Slic3r::GUI::WebRtcMediaController::WebRtcMediaController ( std::function< void(const wxImage &, wxSize)> frame_sink,
std::function< void(Status)> on_status )
44 : m_frame_sink(std::move(frame_sink))
45 , m_on_status(std::move(on_status))
46{
47}
std::function< void(Status)> m_on_status
Definition WebRtcMediaController.hpp:97
std::function< void(const wxImage &, wxSize)> m_frame_sink
Definition WebRtcMediaController.hpp:96

References m_frame_sink, and m_on_status.

◆ ~WebRtcMediaController()

Slic3r::GUI::WebRtcMediaController::~WebRtcMediaController ( )
override
50{
51 Stop();
52}
void Stop() override
Definition WebRtcMediaController.cpp:127

References Stop().

Here is the call graph for this function:

Member Function Documentation

◆ bind_data_channel()

void Slic3r::GUI::WebRtcMediaController::bind_data_channel ( const std::shared_ptr< rtc::DataChannel > & dc)
private
174{
175 const std::string label = dc->label();
176 dc->onOpen([label] { BOOST_LOG_TRIVIAL(info) << "WebRTC: data channel '" << label << "' open"; });
177 dc->onClosed([label] { BOOST_LOG_TRIVIAL(info) << "WebRTC: data channel '" << label << "' closed"; });
178 dc->onError([label](std::string e) {
179 BOOST_LOG_TRIVIAL(warning) << "WebRTC: data channel '" << label << "' error: " << e;
180 });
181 dc->onMessage(
182 [this](rtc::binary data) {
183 if (m_alive.load())
184 enqueue_jpeg(std::vector<std::byte>(data.begin(), data.end()));
185 },
186 [](rtc::string) {});
187}
std::atomic< bool > m_alive
Definition WebRtcMediaController.hpp:92
void enqueue_jpeg(std::vector< std::byte > jpeg)
Definition WebRtcMediaController.cpp:342

References enqueue_jpeg(), and m_alive.

Referenced by on_ready().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode_loop()

void Slic3r::GUI::WebRtcMediaController::decode_loop ( )
private
381{
382 int stall_polls = 0;
383 std::unique_lock<std::mutex> lock(m_mutex);
384 while (m_alive.load()) {
385 const bool woke = m_cond.wait_for(lock, std::chrono::seconds(2), [this] {
386 return !m_alive.load() || !m_jpeg_queue.empty();
387 });
388 if (!m_alive.load())
389 break;
390 if (!woke && !m_has_frame) {
391 const int pc_state = m_peer_connection ? static_cast<int>(m_peer_connection->state()) : -1;
392 std::string dc = "none";
393 if (m_data_channel)
394 dc = "label='" + m_data_channel->label() + "' open=" +
395 (m_data_channel->isOpen() ? "1" : "0");
396 lock.unlock();
397 BOOST_LOG_TRIVIAL(info) << "WebRTC: waiting for frames; peer_state=" << pc_state
398 << " data_channel=" << dc;
399 if (++stall_polls >= 8) { // ~16s connected with no frame -> give up so the UI can retry
401 lock.lock();
402 break;
403 }
404 lock.lock();
405 continue;
406 }
407 stall_polls = 0;
408 if (!m_jpeg_queue.empty()) {
409 auto jpeg = std::move(m_jpeg_queue.front());
410 m_jpeg_queue.pop_front();
411 lock.unlock();
412 deliver_jpeg(std::move(jpeg));
413 lock.lock();
414 }
415 }
416}
bool m_has_frame
Definition WebRtcMediaController.hpp:98
std::deque< std::vector< std::byte > > m_jpeg_queue
Definition WebRtcMediaController.hpp:82
std::condition_variable m_cond
Definition WebRtcMediaController.hpp:81
void report(Status status)
Definition WebRtcMediaController.cpp:54
std::shared_ptr< rtc::PeerConnection > m_peer_connection
Definition WebRtcMediaController.hpp:89
std::mutex m_mutex
Definition WebRtcMediaController.hpp:80
void deliver_jpeg(std::vector< std::byte > jpeg)
Definition WebRtcMediaController.cpp:351
std::shared_ptr< rtc::DataChannel > m_data_channel
Definition WebRtcMediaController.hpp:90
@ lock
Definition GLGizmoEmboss.cpp:209
@ TIMEOUT
Definition WebRtcMediaController.hpp:47
@ Failed
Definition WebRtcMediaController.hpp:39

References deliver_jpeg(), Slic3r::GUI::WebRtcMediaController::Status::Failed, m_alive, m_cond, m_data_channel, m_has_frame, m_jpeg_queue, m_mutex, m_peer_connection, report(), and Slic3r::GUI::WebRtcMediaController::Status::TIMEOUT.

Referenced by Play().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deliver_jpeg()

void Slic3r::GUI::WebRtcMediaController::deliver_jpeg ( std::vector< std::byte > jpeg)
private
352{
353 const auto now = std::chrono::steady_clock::now();
354 {
355 std::lock_guard<std::mutex> lock(m_mutex);
356 if (m_last_frame_time != std::chrono::steady_clock::time_point{} &&
357 now - m_last_frame_time < std::chrono::milliseconds(33))
358 return;
359 m_last_frame_time = now;
360 }
361 wxMemoryInputStream stream(jpeg.data(), jpeg.size());
362 wxImage image;
363 if (!image.LoadFile(stream, wxBITMAP_TYPE_JPEG)) {
365 return;
366 }
367 bool first_frame = false;
368 {
369 std::lock_guard<std::mutex> lock(m_mutex);
370 m_video_size = image.GetSize();
371 first_frame = !m_has_frame;
372 m_has_frame = true;
373 }
374 if (m_frame_sink)
375 m_frame_sink(image, image.GetSize());
376 if (first_frame)
378}
wxSize m_video_size
Definition WebRtcMediaController.hpp:95
std::chrono::steady_clock::time_point m_last_frame_time
Definition WebRtcMediaController.hpp:99
@ DECODE_ERROR
Definition WebRtcMediaController.hpp:46
@ Playing
Definition WebRtcMediaController.hpp:39

References Slic3r::GUI::WebRtcMediaController::Status::DECODE_ERROR, Slic3r::GUI::WebRtcMediaController::Status::Failed, m_frame_sink, m_has_frame, m_last_frame_time, m_mutex, m_video_size, Slic3r::GUI::WebRtcMediaController::Status::Playing, and report().

Referenced by decode_loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enqueue_jpeg()

void Slic3r::GUI::WebRtcMediaController::enqueue_jpeg ( std::vector< std::byte > jpeg)
private
343{
344 std::lock_guard<std::mutex> lock(m_mutex);
345 if (m_jpeg_queue.size() >= 4)
346 m_jpeg_queue.pop_front();
347 m_jpeg_queue.emplace_back(std::move(jpeg));
348 m_cond.notify_one();
349}

References m_cond, m_jpeg_queue, and m_mutex.

Referenced by bind_data_channel().

Here is the caller graph for this function:

◆ epoch()

std::uint64_t Slic3r::GUI::WebRtcMediaController::epoch ( ) const
inline
59{ return m_epoch.load(); }
std::atomic< std::uint64_t > m_epoch
Definition WebRtcMediaController.hpp:93

References m_epoch.

◆ GetLastError()

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

Reimplemented in wxMediaCtrl3.

22{ return {}; };

◆ GetState()

wxMediaState Slic3r::GUI::WebRtcMediaController::GetState ( )
overridevirtual

Reimplemented from Slic3r::GUI::IMediaController.

162{
163 std::lock_guard<std::mutex> lock(m_mutex);
164 return m_state;
165}
wxMediaState m_state
Definition WebRtcMediaController.hpp:94

References m_mutex, and m_state.

◆ GetVideoSize()

wxSize Slic3r::GUI::WebRtcMediaController::GetVideoSize ( ) const
overridevirtual

Reimplemented from Slic3r::GUI::IMediaController.

168{
169 std::lock_guard<std::mutex> lock(m_mutex);
170 return m_video_size;
171}

References m_mutex, and m_video_size.

◆ is_active()

bool Slic3r::GUI::WebRtcMediaController::is_active ( ) const
inline
60{ return m_alive.load(); }

References m_alive.

◆ Load()

void Slic3r::GUI::WebRtcMediaController::Load ( wxURI )
inlineoverridevirtual

◆ on_answer()

void Slic3r::GUI::WebRtcMediaController::on_answer ( std::string sdp)
private
274{
275 std::shared_ptr<rtc::PeerConnection> peer_connection;
276 {
277 std::lock_guard<std::mutex> lock(m_mutex);
278 peer_connection = m_peer_connection;
279 }
280 BOOST_LOG_TRIVIAL(info) << "WebRTC: applying remote answer (" << sdp.size() << " bytes), ANSWER SDP:\n" << sdp;
281 if (!peer_connection)
282 return;
283 try {
284 peer_connection->setRemoteDescription(rtc::Description(sdp, "answer"));
285 } catch (const std::exception& e) {
286 BOOST_LOG_TRIVIAL(warning) << "WebRTC: setRemoteDescription failed: " << e.what();
288 return;
289 }
290
291 // Flush any remote candidates that arrived before the answer.
292 std::vector<std::pair<std::string, std::string>> pending;
293 {
294 std::lock_guard<std::mutex> lock(m_mutex);
296 pending.swap(m_pending_candidates);
297 }
298 BOOST_LOG_TRIVIAL(info) << "WebRTC: remote description set, flushing " << pending.size()
299 << " buffered candidate(s)";
300 for (const auto& c : pending) {
301 try {
302 peer_connection->addRemoteCandidate(rtc::Candidate(c.first, c.second));
303 } catch (const std::exception& e) {
304 BOOST_LOG_TRIVIAL(warning) << "WebRTC: addRemoteCandidate (buffered) failed: " << e.what();
305 }
306 }
307}
bool m_remote_description_set
Definition WebRtcMediaController.hpp:86
std::vector< std::pair< std::string, std::string > > m_pending_candidates
Definition WebRtcMediaController.hpp:85
@ ICE_FAILED
Definition WebRtcMediaController.hpp:41

References Slic3r::GUI::WebRtcMediaController::Status::Failed, Slic3r::GUI::WebRtcMediaController::Status::ICE_FAILED, m_mutex, m_peer_connection, m_pending_candidates, m_remote_description_set, and report().

Referenced by Play().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_ice()

void Slic3r::GUI::WebRtcMediaController::on_ice ( std::string candidate,
std::string mid )
private
310{
311 std::shared_ptr<rtc::PeerConnection> peer_connection;
312 {
313 std::lock_guard<std::mutex> lock(m_mutex);
315 m_pending_candidates.emplace_back(std::move(candidate), std::move(mid));
316 return;
317 }
318 peer_connection = m_peer_connection;
319 }
320 if (!peer_connection)
321 return;
322 try {
323 peer_connection->addRemoteCandidate(rtc::Candidate(candidate, mid));
324 } catch (const std::exception& e) {
325 BOOST_LOG_TRIVIAL(warning) << "WebRTC: addRemoteCandidate failed: " << e.what();
326 }
327}

References m_mutex, m_peer_connection, m_pending_candidates, and m_remote_description_set.

Referenced by Play().

Here is the caller graph for this function:

◆ on_ready()

void Slic3r::GUI::WebRtcMediaController::on_ready ( std::vector< CameraIceServer > servers)
private
190{
192 rtc::Configuration configuration;
193 // Allow complete-JPEG DataChannel messages up to 1 MiB. This value is
194 // advertised in SDP and becomes the upper bound for frames OrcaSonar can
195 // send to OrcaSlicer.
196 configuration.maxMessageSize = 1024 * 1024;
197 for (const CameraIceServer& server : servers) {
198 try {
199 rtc::IceServer ice_server(server.urls);
200 ice_server.username = server.username;
201 ice_server.password = server.credential;
202 configuration.iceServers.emplace_back(std::move(ice_server));
203 } catch (const std::exception& e) {
204 BOOST_LOG_TRIVIAL(warning) << "WebRTC: invalid ICE server: " << e.what();
205 }
206 }
207
208 BOOST_LOG_TRIVIAL(info) << "WebRTC: creating peer connection with " << configuration.iceServers.size() << " ice servers";
209 auto peer_connection = std::make_shared<rtc::PeerConnection>(std::move(configuration));
210 peer_connection->onLocalDescription([this](rtc::Description description) {
211 if (!m_alive.load())
212 return;
213 const std::string sdp(description);
214 BOOST_LOG_TRIVIAL(info) << "WebRTC: local description ready (" << description.typeString()
215 << "), OFFER SDP:\n" << sdp;
216 std::lock_guard<std::mutex> lock(m_mutex);
217 if (m_signaling)
218 m_signaling->send_offer(sdp);
219 });
220 peer_connection->onLocalCandidate([this](rtc::Candidate candidate) {
221 if (!m_alive.load())
222 return;
223 std::lock_guard<std::mutex> lock(m_mutex);
224 if (m_signaling)
225 m_signaling->send_ice(std::string(candidate), candidate.mid());
226 });
227 peer_connection->onStateChange([this](rtc::PeerConnection::State state) {
228 BOOST_LOG_TRIVIAL(info) << "WebRTC: peer state -> " << static_cast<int>(state);
229 if (!m_alive.load())
230 return;
231 if (state == rtc::PeerConnection::State::Failed || state == rtc::PeerConnection::State::Disconnected)
233 });
234 peer_connection->onGatheringStateChange([](rtc::PeerConnection::GatheringState state) {
235 BOOST_LOG_TRIVIAL(info) << "WebRTC: gathering state -> " << static_cast<int>(state);
236 });
237
238 // Accept a DataChannel opened by the remote peer (OrcaSonar may create the
239 // "camera" channel from its side rather than answering the one we offer).
240 peer_connection->onDataChannel([this](std::shared_ptr<rtc::DataChannel> dc) {
241 BOOST_LOG_TRIVIAL(info) << "WebRTC: remote opened data channel '" << dc->label() << "'";
243 std::lock_guard<std::mutex> lock(m_mutex);
244 m_data_channel = std::move(dc);
245 });
246
247 rtc::DataChannelInit init;
248 init.reliability.unordered = true;
249 // init.reliability.maxPacketLifeTime = std::chrono::milliseconds(350);
250 // Request one complete JPEG frame per DataChannel message. OrcaSonar
251 // keeps the legacy chunked protocol for clients that omit this property.
252 init.protocol = "orca-jpeg";
253 auto data_channel = peer_connection->createDataChannel("camera", init);
254 if (data_channel)
255 bind_data_channel(data_channel);
256
257 // Camera media is carried as one complete JPEG per DataChannel message;
258 // no RTP video track or application-level framing is required.
259
260 std::shared_ptr<rtc::PeerConnection> peer_for_description;
261 {
262 std::lock_guard<std::mutex> lock(m_mutex);
263 if (!m_alive.load())
264 return;
265 m_peer_connection = std::move(peer_connection);
266 peer_for_description = m_peer_connection;
267 m_data_channel = std::move(data_channel);
268 }
269 if (peer_for_description)
270 peer_for_description->setLocalDescription();
271}
std::unique_ptr< ICameraSignalingChannel > m_signaling
Definition WebRtcMediaController.hpp:88
void bind_data_channel(const std::shared_ptr< rtc::DataChannel > &dc)
Definition WebRtcMediaController.cpp:173
std::tuple< TriangleInfos, VertexInfos, EdgeInfos, Errors > init(const indexed_triangle_set &its, ThrowOnCancel &throw_on_cancel, StatusFn &status_fn)
Definition QuadricEdgeCollapse.cpp:455
void init_rtc_logger_once()
Definition WebRtcMediaController.cpp:29

References bind_data_channel(), Slic3r::GUI::WebRtcMediaController::Status::Failed, Slic3r::GUI::WebRtcMediaController::Status::ICE_FAILED, m_alive, m_data_channel, m_mutex, m_peer_connection, m_signaling, and report().

Referenced by Play().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_unavailable()

void Slic3r::GUI::WebRtcMediaController::on_unavailable ( CameraUnavailableReason reason,
std::string detail )
private
330{
331 BOOST_LOG_TRIVIAL(warning) << "WebRTC camera unavailable: " << detail;
333 if (reason == CameraUnavailableReason::Busy)
335 else if (reason == CameraUnavailableReason::Disabled)
337 else if (reason == CameraUnavailableReason::Closed)
339 report({Status::Failed, code});
340}
@ Closed
Definition ICameraSignalingChannel.hpp:19
@ Disabled
Definition ICameraSignalingChannel.hpp:18
@ Busy
Definition ICameraSignalingChannel.hpp:16
Code
Definition WebRtcMediaController.hpp:40
@ UNAVAILABLE_ERROR
Definition WebRtcMediaController.hpp:44
@ UNAVAILABLE_DISABLED
Definition WebRtcMediaController.hpp:45
@ UNAVAILABLE_BUSY
Definition WebRtcMediaController.hpp:43
@ SIGNALING_CLOSED
Definition WebRtcMediaController.hpp:42

References Slic3r::Busy, Slic3r::Closed, Slic3r::Disabled, Slic3r::GUI::WebRtcMediaController::Status::Failed, report(), Slic3r::GUI::WebRtcMediaController::Status::SIGNALING_CLOSED, Slic3r::GUI::WebRtcMediaController::Status::UNAVAILABLE_BUSY, Slic3r::GUI::WebRtcMediaController::Status::UNAVAILABLE_DISABLED, and Slic3r::GUI::WebRtcMediaController::Status::UNAVAILABLE_ERROR.

Referenced by Play().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Play()

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

Implements Slic3r::GUI::IMediaController.

78{
79 std::unique_ptr<ICameraSignalingChannel> channel = std::move(m_pending_signaling);
80 // Tear down any previous attempt WITHOUT notifying: the Stopped that would
81 // otherwise be delivered (async, via CallAfter) races the new attempt's
82 // Connecting and makes the consumer cancel a session that is mid-connect.
83 teardown(false);
84 if (!channel)
85 return;
86
87 m_epoch.fetch_add(1);
88 m_alive.store(true);
89 {
90 std::lock_guard<std::mutex> lock(m_mutex);
91 m_signaling = std::move(channel);
92 m_jpeg_queue.clear();
95 m_video_size = wxDefaultSize;
96 m_has_frame = false;
98 }
99
100 ICameraSignalingChannel* signaling = nullptr;
101 {
102 std::lock_guard<std::mutex> lock(m_mutex);
103 signaling = m_signaling.get();
104 }
105 signaling->on_ready = [this](std::vector<CameraIceServer> servers) {
106 if (m_alive.load())
107 on_ready(std::move(servers));
108 };
109 signaling->on_answer = [this](std::string sdp) {
110 if (m_alive.load())
111 on_answer(std::move(sdp));
112 };
113 signaling->on_ice = [this](std::string candidate, std::string mid) {
114 if (m_alive.load())
115 on_ice(std::move(candidate), std::move(mid));
116 };
117 signaling->on_unavailable = [this](CameraUnavailableReason reason, std::string detail) {
118 if (m_alive.load())
119 on_unavailable(reason, std::move(detail));
120 };
121
122 m_decode_thread = std::thread([this] { decode_loop(); });
124 signaling->open();
125}
std::unique_ptr< ICameraSignalingChannel > m_pending_signaling
Definition WebRtcMediaController.hpp:87
void on_ready(std::vector< CameraIceServer > servers)
Definition WebRtcMediaController.cpp:189
std::thread m_decode_thread
Definition WebRtcMediaController.hpp:91
void on_answer(std::string sdp)
Definition WebRtcMediaController.cpp:273
void on_unavailable(CameraUnavailableReason reason, std::string detail)
Definition WebRtcMediaController.cpp:329
void decode_loop()
Definition WebRtcMediaController.cpp:380
void teardown(bool notify)
Definition WebRtcMediaController.cpp:132
void on_ice(std::string candidate, std::string mid)
Definition WebRtcMediaController.cpp:309
CameraUnavailableReason
Definition ICameraSignalingChannel.hpp:15
@ Connecting
Definition WebRtcMediaController.hpp:39

References Slic3r::GUI::WebRtcMediaController::Status::Connecting, decode_loop(), m_alive, m_decode_thread, m_epoch, m_has_frame, m_jpeg_queue, m_last_frame_time, m_mutex, m_pending_candidates, m_pending_signaling, m_remote_description_set, m_signaling, m_video_size, on_answer(), Slic3r::ICameraSignalingChannel::on_answer, on_ice(), Slic3r::ICameraSignalingChannel::on_ice, on_ready(), Slic3r::ICameraSignalingChannel::on_ready, on_unavailable(), Slic3r::ICameraSignalingChannel::on_unavailable, Slic3r::ICameraSignalingChannel::open(), report(), and teardown().

Here is the call graph for this function:

◆ report()

void Slic3r::GUI::WebRtcMediaController::report ( Status status)
private
55{
56 status.epoch = m_epoch.load();
57 BOOST_LOG_TRIVIAL(info) << "WebRTC: report kind=" << static_cast<int>(status.kind)
58 << " code=" << static_cast<int>(status.code) << " epoch=" << status.epoch;
59 {
60 std::lock_guard<std::mutex> lock(m_mutex);
61 if (status.kind == Status::Connecting)
62 m_state = static_cast<wxMediaState>(4);
63 else if (status.kind == Status::Playing)
64 m_state = wxMEDIASTATE_PLAYING;
65 else
66 m_state = static_cast<wxMediaState>(3);
67 }
68 if (m_on_status)
69 m_on_status(status);
70}

References Slic3r::GUI::WebRtcMediaController::Status::code, Slic3r::GUI::WebRtcMediaController::Status::Connecting, Slic3r::GUI::WebRtcMediaController::Status::epoch, Slic3r::GUI::WebRtcMediaController::Status::kind, m_epoch, m_mutex, m_on_status, m_state, and Slic3r::GUI::WebRtcMediaController::Status::Playing.

Referenced by decode_loop(), deliver_jpeg(), on_answer(), on_ready(), on_unavailable(), Play(), and teardown().

Here is the caller graph for this function:

◆ set_signalling_channel()

void Slic3r::GUI::WebRtcMediaController::set_signalling_channel ( std::unique_ptr< ICameraSignalingChannel > channel)
73{
74 m_pending_signaling = std::move(channel);
75}

References m_pending_signaling.

◆ Stop()

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

Implements Slic3r::GUI::IMediaController.

128{
129 teardown(true);
130}

References teardown().

Referenced by ~WebRtcMediaController().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ teardown()

void Slic3r::GUI::WebRtcMediaController::teardown ( bool notify)
private
133{
134 const bool was_alive = m_alive.exchange(false);
135 if (!was_alive && !m_decode_thread.joinable())
136 return;
137
138 m_cond.notify_all();
139 std::unique_ptr<ICameraSignalingChannel> signaling;
140 std::shared_ptr<rtc::PeerConnection> peer_connection;
141 {
142 std::lock_guard<std::mutex> lock(m_mutex);
143 signaling = std::move(m_signaling);
144 peer_connection = std::move(m_peer_connection);
145 m_data_channel.reset();
146 }
147 if (signaling)
148 signaling->close();
149 if (peer_connection)
150 peer_connection->close();
151 if (m_decode_thread.joinable())
152 m_decode_thread.join();
153 {
154 std::lock_guard<std::mutex> lock(m_mutex);
155 m_jpeg_queue.clear();
156 }
157 if (was_alive && notify)
159}
@ Stopped
Definition WebRtcMediaController.hpp:39

References m_alive, m_cond, m_data_channel, m_decode_thread, m_jpeg_queue, m_mutex, m_peer_connection, m_signaling, report(), and Slic3r::GUI::WebRtcMediaController::Status::Stopped.

Referenced by Play(), and Stop().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_alive

std::atomic<bool> Slic3r::GUI::WebRtcMediaController::m_alive {false}
private

◆ m_cond

std::condition_variable Slic3r::GUI::WebRtcMediaController::m_cond
private

Referenced by decode_loop(), enqueue_jpeg(), and teardown().

◆ m_data_channel

std::shared_ptr<rtc::DataChannel> Slic3r::GUI::WebRtcMediaController::m_data_channel
private

Referenced by decode_loop(), on_ready(), and teardown().

◆ m_decode_thread

std::thread Slic3r::GUI::WebRtcMediaController::m_decode_thread
private

Referenced by Play(), and teardown().

◆ m_epoch

std::atomic<std::uint64_t> Slic3r::GUI::WebRtcMediaController::m_epoch {0}
private
93{0};

Referenced by epoch(), Play(), and report().

◆ m_frame_sink

std::function<void(const wxImage&, wxSize)> Slic3r::GUI::WebRtcMediaController::m_frame_sink
private

◆ m_has_frame

bool Slic3r::GUI::WebRtcMediaController::m_has_frame = false
private

Referenced by decode_loop(), deliver_jpeg(), and Play().

◆ m_jpeg_queue

std::deque<std::vector<std::byte> > Slic3r::GUI::WebRtcMediaController::m_jpeg_queue
private

◆ m_last_frame_time

std::chrono::steady_clock::time_point Slic3r::GUI::WebRtcMediaController::m_last_frame_time {}
private
99{};

Referenced by deliver_jpeg(), and Play().

◆ m_mutex

std::mutex Slic3r::GUI::WebRtcMediaController::m_mutex
mutableprivate

◆ m_on_status

std::function<void(Status)> Slic3r::GUI::WebRtcMediaController::m_on_status
private

Referenced by WebRtcMediaController(), and report().

◆ m_peer_connection

std::shared_ptr<rtc::PeerConnection> Slic3r::GUI::WebRtcMediaController::m_peer_connection
private

◆ m_pending_candidates

std::vector<std::pair<std::string, std::string> > Slic3r::GUI::WebRtcMediaController::m_pending_candidates
private

Referenced by on_answer(), on_ice(), and Play().

◆ m_pending_signaling

std::unique_ptr<ICameraSignalingChannel> Slic3r::GUI::WebRtcMediaController::m_pending_signaling
private

Referenced by Play(), and set_signalling_channel().

◆ m_remote_description_set

bool Slic3r::GUI::WebRtcMediaController::m_remote_description_set = false
private

Referenced by on_answer(), on_ice(), and Play().

◆ m_signaling

std::unique_ptr<ICameraSignalingChannel> Slic3r::GUI::WebRtcMediaController::m_signaling
private

Referenced by on_ready(), Play(), and teardown().

◆ m_state

wxMediaState Slic3r::GUI::WebRtcMediaController::m_state = static_cast<wxMediaState>(3)
private

Referenced by GetState(), and report().

◆ m_video_size

wxSize Slic3r::GUI::WebRtcMediaController::m_video_size = wxDefaultSize
private

Referenced by deliver_jpeg(), GetVideoSize(), and Play().


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