Skip to content

Commit

Permalink
Merge pull request #256 from cea-sec/updt_crates_x11rb_spin
Browse files Browse the repository at this point in the history
Updt crates x11rb & spin
  • Loading branch information
serpilliere authored Jan 8, 2024
2 parents 4875b3e + e7fff8d commit 4b4815a
Show file tree
Hide file tree
Showing 8 changed files with 387 additions and 292 deletions.
629 changes: 366 additions & 263 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/Dockerfile-windows
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ RUN set -eux; \
rsync \
curl ; \
cd /tmp ; \
curl -L -o /tmp/ffmpeg.zip https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-n6.0-latest-win64-gpl-shared-6.0.zip ; \
curl -L -o /tmp/ffmpeg.zip https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-n4.4-latest-win64-gpl-shared-4.4.zip ; \
unzip /tmp/ffmpeg.zip ; cd /tmp/ffmpeg*/bin/ ; \
for lib in *.dll ; do echo ${lib} ; \
cp $lib /usr/x86_64-w64-mingw32/lib/${lib} ; \
Expand Down
4 changes: 2 additions & 2 deletions sanzu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
serde_yaml = "0.9"
socket2 = {version = "0.5", features=['all'] }
spin_sleep = "1.1"
spin_sleep_util = "0.1"
twelf = {version = "0.13.0", features=["toml"]}
toml = "0.8"
dbus = { version = "0.9", optional = true }
Expand Down Expand Up @@ -74,7 +74,7 @@ vsock = "0.4"
x11-clipboard = "0.8"

[dependencies.x11rb]
version = "0.12"
version = "0.13"
features = ["shm", "xtest", "xfixes", "damage", "randr"]

[package.metadata.deb]
Expand Down
4 changes: 1 addition & 3 deletions sanzu/src/client_wind3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ use std::{

use sanzu_common::tunnel;

use spin_sleep::sleep;

use winapi::{
ctypes::c_void,
shared::{
Expand Down Expand Up @@ -1518,7 +1516,7 @@ pub fn init_wind3d(
unsafe { TranslateMessage(&msg) };
unsafe { DispatchMessageA(&msg) };
}
sleep(Duration::from_millis(5));
std::thread::sleep(Duration::from_millis(5));
}
info!("Client end");
unsafe { ExitProcess(0) };
Expand Down
22 changes: 10 additions & 12 deletions sanzu/src/client_x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,22 +359,20 @@ pub fn init_x11rb(
.context("Error in query pict format reply")?;

let mut bgra_format_id = 0;
let bgra_format = render::Directformat {
red_shift: 16,
red_mask: 255,
green_shift: 8,
green_mask: 255,
blue_shift: 0,
blue_mask: 255,
alpha_shift: 24,
alpha_mask: 255,
};
for format in render_pict_format.formats.iter() {
let direct = format.direct;
let direct: x11rb::protocol::render::Directformat = format.direct;
if format.depth != 32 {
continue;
}
if direct == bgra_format {
if direct.red_shift == 16
&& direct.red_mask == 255
&& direct.green_shift == 8
&& direct.green_mask == 255
&& direct.blue_shift == 0
&& direct.blue_mask == 255
&& direct.alpha_shift == 24
&& direct.alpha_mask == 255
{
bgra_format_id = format.id;
break;
}
Expand Down
8 changes: 4 additions & 4 deletions sanzu/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use sanzu_common::{
ReadWrite, Tunnel,
};

use spin_sleep::LoopHelper;
use spin_sleep_util;
use std::{
net::{self, IpAddr, TcpListener},
time::Instant,
Expand Down Expand Up @@ -392,7 +392,8 @@ pub fn run_server(config: &ConfigServer, arguments: &ServerArgsConfig) -> Result

let mut prev_time_start = Instant::now();

let mut loop_helper = LoopHelper::builder().build_with_target_rate(config.video.max_fps as f64); // limit FPS if possible
let mut loop_sleep =
spin_sleep_util::interval(std::time::Duration::from_secs(1) / config.video.max_fps as u32);

let mut new_size = None;
let mut cur_size = None;
Expand Down Expand Up @@ -430,7 +431,6 @@ pub fn run_server(config: &ConfigServer, arguments: &ServerArgsConfig) -> Result
let mut msg_stats = "".to_owned();
let err = loop {
let time_start = Instant::now();
loop_helper.loop_start();

let mut events = vec![];
if let Some((width, height)) = new_size.take() {
Expand Down Expand Up @@ -586,7 +586,7 @@ pub fn run_server(config: &ConfigServer, arguments: &ServerArgsConfig) -> Result
msg_stats = msg;

prev_time_start = time_start;
loop_helper.loop_sleep(); // sleeps to acheive target FPS rate
loop_sleep.tick(); // sleeps to acheive target FPS rate
};

Err(err)
Expand Down
4 changes: 1 addition & 3 deletions sanzu/src/server_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ use std::{
time::{Duration, Instant},
};

use spin_sleep::sleep;

use winapi::{
ctypes::c_void,
shared::{
Expand Down Expand Up @@ -823,7 +821,7 @@ pub fn init_win(
unsafe { TranslateMessage(&msg) };
unsafe { DispatchMessageA(&msg) };
}
sleep(Duration::from_millis(5));
std::thread::sleep(Duration::from_millis(5));
}
});
init_d3d11().context("Cannot init d3d11")?;
Expand Down
6 changes: 2 additions & 4 deletions sanzu/src/sound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use std::{
time::Duration,
};

use spin_sleep::sleep;

/// Sampling frequency
pub const SOUND_FREQ: u32 = 48000;
pub const DECODER_BUFFER_MS: usize = 150;
Expand Down Expand Up @@ -200,7 +198,7 @@ impl SoundDecoder {
}
}
// Wait for buffer loading
sleep(Duration::from_millis(10));
std::thread::sleep(Duration::from_millis(10));
}
});

Expand Down Expand Up @@ -475,7 +473,7 @@ impl SoundEncoder {
}

if need_data {
sleep(Duration::from_millis(10));
std::thread::sleep(Duration::from_millis(10));
continue;
}
match &mut encoder {
Expand Down

0 comments on commit 4b4815a

Please sign in to comment.