@@ -740,6 +740,8 @@ void controlBroadcastThread(control_server_t *server) {
740740 input::passthrough (session->input , std::move (plaintext));
741741 });
742742
743+ // This thread handles latency-sensitive control messages
744+ platf::adjust_thread_priority (platf::thread_priority_e::critical);
743745
744746 auto shutdown_event = mail::man->event <bool >(mail::broadcast_shutdown);
745747 while (!shutdown_event->peek ()) {
@@ -905,6 +907,9 @@ void videoBroadcastThread(udp::socket &sock) {
905907 auto packets = mail::man->queue <video::packet_t >(mail::video_packets);
906908 auto timebase = boost::posix_time::microsec_clock::universal_time ();
907909
910+ // Video traffic is sent on this thread
911+ platf::adjust_thread_priority (platf::thread_priority_e::high);
912+
908913 while (auto packet = packets->pop ()) {
909914 if (shutdown_event->peek ()) {
910915 break ;
@@ -1079,6 +1084,9 @@ void audioBroadcastThread(udp::socket &sock) {
10791084 audio_packet->rtp .packetType = 97 ;
10801085 audio_packet->rtp .ssrc = 0 ;
10811086
1087+ // Audio traffic is sent on this thread
1088+ platf::adjust_thread_priority (platf::thread_priority_e::high);
1089+
10821090 while (auto packet = packets->pop ()) {
10831091 if (shutdown_event->peek ()) {
10841092 break ;
@@ -1333,6 +1341,8 @@ void audioThread(session_t *session) {
13331341}
13341342
13351343namespace session {
1344+ std::atomic_uint running_sessions;
1345+
13361346state_e state (session_t &session) {
13371347 return session.state .load (std::memory_order_relaxed);
13381348}
@@ -1394,6 +1404,11 @@ void join(session_t &session) {
13941404 }
13951405 }
13961406
1407+ // If this is the last session, invoke the platform callbacks
1408+ if (--running_sessions == 0 ) {
1409+ platf::streaming_will_stop ();
1410+ }
1411+
13971412 BOOST_LOG (debug) << " Session ended" sv;
13981413}
13991414
@@ -1432,6 +1447,11 @@ int start(session_t &session, const std::string &addr_string) {
14321447
14331448 session.state .store (state_e::RUNNING , std::memory_order_relaxed);
14341449
1450+ // If this is the first session, invoke the platform callbacks
1451+ if (++running_sessions == 1 ) {
1452+ platf::streaming_will_start ();
1453+ }
1454+
14351455 return 0 ;
14361456}
14371457
0 commit comments