@@ -392,8 +392,22 @@ void IceTransport::LogCallback(juice_log_level_t level, const char *message) {
392
392
393
393
#else // USE_NICE == 1
394
394
395
- unique_ptr<GMainLoop, void (*)(GMainLoop *)> IceTransport::MainLoop (nullptr , nullptr );
396
- std::thread IceTransport::MainLoopThread;
395
+ IceTransport::MainLoopWrapper *IceTransport::MainLoop = nullptr ;
396
+
397
+ IceTransport::MainLoopWrapper::MainLoopWrapper ()
398
+ : mMainLoop(g_main_loop_new(nullptr , FALSE ), g_main_loop_unref) {
399
+ if (!mMainLoop )
400
+ throw std::runtime_error (" Failed to create the glib main loop" );
401
+
402
+ mThread = std::thread (g_main_loop_run, mMainLoop .get ());
403
+ }
404
+
405
+ IceTransport::MainLoopWrapper::~MainLoopWrapper () {
406
+ g_main_loop_quit (mMainLoop .get ());
407
+ mThread .join ();
408
+ }
409
+
410
+ GMainLoop *IceTransport::MainLoopWrapper::get () const { return mMainLoop .get (); }
397
411
398
412
void IceTransport::Init () {
399
413
g_log_set_handler (" libnice" , G_LOG_LEVEL_MASK, LogCallback, nullptr );
@@ -402,17 +416,12 @@ void IceTransport::Init() {
402
416
nice_debug_enable (false ); // do not output STUN debug messages
403
417
}
404
418
405
- MainLoop = decltype (MainLoop)(g_main_loop_new (nullptr , FALSE ), g_main_loop_unref);
406
- if (!MainLoop)
407
- throw std::runtime_error (" Failed to create the main loop" );
408
-
409
- MainLoopThread = std::thread (g_main_loop_run, MainLoop.get ());
419
+ MainLoop = new MainLoopWrapper;
410
420
}
411
421
412
422
void IceTransport::Cleanup () {
413
- g_main_loop_quit (MainLoop.get ());
414
- MainLoopThread.join ();
415
- MainLoop.reset ();
423
+ delete MainLoop;
424
+ MainLoop = nullptr ;
416
425
}
417
426
418
427
static void closeNiceAgentCallback (GObject *niceAgent, GAsyncResult *, gpointer) {
@@ -447,7 +456,7 @@ IceTransport::IceTransport(const Configuration &config, candidate_callback candi
447
456
// Create agent
448
457
mNiceAgent = decltype (mNiceAgent )(
449
458
nice_agent_new_full (
450
- g_main_loop_get_context (MainLoop. get ()),
459
+ g_main_loop_get_context (MainLoop-> get ()),
451
460
NICE_COMPATIBILITY_RFC5245, // RFC 5245 was obsoleted by RFC 8445 but this should be OK
452
461
flags),
453
462
closeNiceAgent);
@@ -580,12 +589,13 @@ IceTransport::IceTransport(const Configuration &config, candidate_callback candi
580
589
nice_agent_set_port_range (mNiceAgent .get (), mStreamId , 1 , config.portRangeBegin ,
581
590
config.portRangeEnd );
582
591
583
- nice_agent_attach_recv (mNiceAgent .get (), mStreamId , 1 , g_main_loop_get_context (MainLoop. get ()),
592
+ nice_agent_attach_recv (mNiceAgent .get (), mStreamId , 1 , g_main_loop_get_context (MainLoop-> get ()),
584
593
RecvCallback, this );
585
594
}
586
595
587
596
void IceTransport::setIceAttributes ([[maybe_unused]] string uFrag, [[maybe_unused]] string pwd) {
588
- PLOG_WARNING << " Setting custom ICE attributes is not supported with libnice, please use libjuice" ;
597
+ PLOG_WARNING
598
+ << " Setting custom ICE attributes is not supported with libnice, please use libjuice" ;
589
599
}
590
600
591
601
void IceTransport::addIceServer (IceServer server) {
@@ -647,7 +657,7 @@ void IceTransport::addIceServer(IceServer server) {
647
657
648
658
IceTransport::~IceTransport () {
649
659
PLOG_DEBUG << " Destroying ICE transport" ;
650
- nice_agent_attach_recv (mNiceAgent .get (), mStreamId , 1 , g_main_loop_get_context (MainLoop. get ()),
660
+ nice_agent_attach_recv (mNiceAgent .get (), mStreamId , 1 , g_main_loop_get_context (MainLoop-> get ()),
651
661
NULL , NULL );
652
662
nice_agent_remove_stream (mNiceAgent .get (), mStreamId );
653
663
mNiceAgent .reset ();
0 commit comments