Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into sctgdesk
Browse files Browse the repository at this point in the history
  • Loading branch information
aeltorio committed Jun 25, 2024
2 parents d4a6ffe + 245f080 commit 46f825c
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 118 deletions.
18 changes: 9 additions & 9 deletions flutter/lib/common/widgets/overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -486,32 +486,32 @@ class IOSDraggableState extends State<IOSDraggable> {
_height = widget.height;
}

get position => widget.position;
DraggableKeyPosition get position => widget.position;

checkKeyboard() {
final bottomHeight = MediaQuery.of(context).viewInsets.bottom;
final currentVisible = bottomHeight != 0;

// save
if (!_keyboardVisible && currentVisible) {
_saveHeight = position.value.dy;
_saveHeight = position.pos.dy;
}

// reset
if (_lastBottomHeight > 0 && bottomHeight == 0) {
setState(() {
position.value = Offset(position.value.dx, _saveHeight);
position.update(Offset(position.pos.dx, _saveHeight));
});
}

// onKeyboardVisible
if (_keyboardVisible && currentVisible) {
final sumHeight = bottomHeight + _height;
final contextHeight = MediaQuery.of(context).size.height;
if (sumHeight + position.value.dy > contextHeight) {
if (sumHeight + position.pos.dy > contextHeight) {
final y = contextHeight - sumHeight;
setState(() {
position.value = Offset(position.value.dx, y);
position.update(Offset(position.pos.dx, y));
});
}
}
Expand All @@ -526,14 +526,14 @@ class IOSDraggableState extends State<IOSDraggable> {
return Stack(
children: [
Positioned(
left: position.value.dx,
top: position.value.dy,
left: position.pos.dx,
top: position.pos.dy,
child: GestureDetector(
onPanUpdate: (details) {
setState(() {
position.value += details.delta;
position.update(position.pos + details.delta);
});
_chatModel?.setChatWindowPosition(position.value);
_chatModel?.setChatWindowPosition(position.pos);
},
child: Material(
child: Container(
Expand Down
8 changes: 5 additions & 3 deletions flutter/lib/mobile/pages/remote_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,11 @@ class _RemotePageState extends State<RemotePage> {
child: Text(translate(label), style: labelStyle),
trailingIcon: Transform.scale(
scale: (isDesktop || isWebDesktop) ? 0.8 : 1,
child: IconButton(
onPressed: onPressed,
icon: icon,
child: IgnorePointer(
child: IconButton(
onPressed: null,
icon: icon,
),
),
),
onPressed: onPressed,
Expand Down
81 changes: 48 additions & 33 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ use hbb_common::{
rand,
rendezvous_proto::*,
socket_client,
sodiumoxide::base64,
sodiumoxide::crypto::sign,
sodiumoxide::{base64, crypto::sign},
tcp::FramedStream,
timeout,
tokio::time::Duration,
Expand Down Expand Up @@ -2093,8 +2092,6 @@ pub type MediaSender = mpsc::Sender<MediaData>;

struct VideoHandlerController {
handler: VideoHandler,
count: u128,
duration: std::time::Duration,
skip_beginning: u32,
}

Expand All @@ -2111,7 +2108,7 @@ pub fn start_video_audio_threads<F, T>(
MediaSender,
MediaSender,
Arc<RwLock<HashMap<usize, ArrayQueue<VideoFrame>>>>,
Arc<RwLock<HashMap<usize, usize>>>,
Arc<RwLock<Option<usize>>>,
Arc<RwLock<Option<Chroma>>>,
)
where
Expand All @@ -2123,8 +2120,8 @@ where
let video_queue_map_cloned = video_queue_map.clone();
let mut video_callback = video_callback;

let fps_map = Arc::new(RwLock::new(HashMap::new()));
let decode_fps_map = fps_map.clone();
let fps = Arc::new(RwLock::new(None));
let decode_fps_map = fps.clone();
let chroma = Arc::new(RwLock::new(None));
let chroma_cloned = chroma.clone();
let mut last_chroma = None;
Expand All @@ -2134,9 +2131,8 @@ where
sync_cpu_usage();
get_hwcodec_config();
let mut handler_controller_map = HashMap::new();
// let mut count = Vec::new();
// let mut duration = std::time::Duration::ZERO;
// let mut skip_beginning = Vec::new();
let mut count = 0;
let mut duration = std::time::Duration::ZERO;
loop {
if let Ok(data) = video_receiver.recv() {
match data {
Expand Down Expand Up @@ -2169,15 +2165,15 @@ where
display,
VideoHandlerController {
handler: VideoHandler::new(format, display),
count: 0,
duration: std::time::Duration::ZERO,
skip_beginning: 0,
},
);
}
if let Some(handler_controller) = handler_controller_map.get_mut(&display) {
let mut pixelbuffer = true;
let mut tmp_chroma = None;
let format_changed =
handler_controller.handler.decoder.format() != format;
match handler_controller.handler.handle_frame(
vf,
&mut pixelbuffer,
Expand All @@ -2198,27 +2194,14 @@ where
}

// fps calculation
// The first frame will be very slow
if handler_controller.skip_beginning < 5 {
handler_controller.skip_beginning += 1;
continue;
}

handler_controller.duration += start.elapsed();
handler_controller.count += 1;
if handler_controller.count % 10 == 0 {
fps_map.write().unwrap().insert(
display,
(handler_controller.count * 1000
/ handler_controller.duration.as_millis())
as usize,
);
}
// Clear to get real-time fps
if handler_controller.count > 150 {
handler_controller.count = 0;
handler_controller.duration = Duration::ZERO;
}
fps_calculate(
handler_controller,
&fps,
format_changed,
start.elapsed(),
&mut count,
&mut duration,
);
}
Err(e) => {
// This is a simple workaround.
Expand Down Expand Up @@ -2334,6 +2317,38 @@ pub fn start_audio_thread() -> MediaSender {
audio_sender
}

#[inline]
fn fps_calculate(
handler_controller: &mut VideoHandlerController,
fps: &Arc<RwLock<Option<usize>>>,
format_changed: bool,
elapsed: std::time::Duration,
count: &mut usize,
duration: &mut std::time::Duration,
) {
if format_changed {
*count = 0;
*duration = std::time::Duration::ZERO;
handler_controller.skip_beginning = 0;
}
// // The first frame will be very slow
if handler_controller.skip_beginning < 3 {
handler_controller.skip_beginning += 1;
return;
}
*duration += elapsed;
*count += 1;
let ms = duration.as_millis();
if *count % 10 == 0 && ms > 0 {
*fps.write().unwrap() = Some((*count as usize) * 1000 / (ms as usize));
}
// Clear to get real-time fps
if *count >= 30 {
*count = 0;
*duration = Duration::ZERO;
}
}

fn get_hwcodec_config() {
// for sciter and unilink
#[cfg(feature = "hwcodec")]
Expand Down
Loading

0 comments on commit 46f825c

Please sign in to comment.