From ca7487350f63b8de5d07955bb2b4e00b006d0d89 Mon Sep 17 00:00:00 2001 From: 21pages Date: Fri, 28 Apr 2023 16:35:54 +0800 Subject: [PATCH] send SwitchDisplay using the same channel with VideoFrame Signed-off-by: 21pages --- src/server/connection.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/server/connection.rs b/src/server/connection.rs index a2959d254..b2651f0d3 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -165,18 +165,23 @@ impl Subscriber for ConnInner { #[inline] fn send(&mut self, msg: Arc) { - match &msg.union { - Some(message::Union::VideoFrame(_)) => { - self.tx_video.as_mut().map(|tx| { - allow_err!(tx.send((Instant::now(), msg))); - }); - } - _ => { - self.tx.as_mut().map(|tx| { - allow_err!(tx.send((Instant::now(), msg))); - }); - } - } + // Send SwitchDisplay on the same channel as VideoFrame to avoid send order problems. + let tx_by_video = match &msg.union { + Some(message::Union::VideoFrame(_)) => true, + Some(message::Union::Misc(misc)) => match &misc.union { + Some(misc::Union::SwitchDisplay(_)) => true, + _ => false, + }, + _ => false, + }; + let tx = if tx_by_video { + self.tx_video.as_mut() + } else { + self.tx.as_mut() + }; + tx.map(|tx| { + allow_err!(tx.send((Instant::now(), msg))); + }); } }