Merge translate mode

This commit is contained in:
Asura
2022-08-04 16:11:37 +08:00
91 changed files with 2869 additions and 1419 deletions

View File

@@ -347,7 +347,7 @@ fn send_f32(data: &[f32], encoder: &mut Encoder, sp: &GenericService) {
Ok(data) => {
let mut msg_out = Message::new();
msg_out.set_audio_frame(AudioFrame {
data,
data: data.into(),
timestamp: crate::common::get_time(),
..Default::default()
});

View File

@@ -7,15 +7,14 @@ use crate::video_service;
#[cfg(any(target_os = "android", target_os = "ios"))]
use crate::{common::MOBILE_INFO2, mobile::connection_manager::start_channel};
use crate::{ipc, VERSION};
use hbb_common::fs::can_enable_overwrite_detection;
use hbb_common::password_security::password;
use hbb_common::{
config::Config,
fs,
fs::can_enable_overwrite_detection,
futures::{SinkExt, StreamExt},
get_version_number,
message_proto::{option_message::BoolOption, permission_info::Permission},
sleep, timeout,
password_security as password, sleep, timeout,
tokio::{
net::TcpStream,
sync::mpsc,
@@ -31,6 +30,8 @@ use std::sync::{
atomic::{AtomicI64, Ordering},
mpsc as std_mpsc,
};
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use system_shutdown;
pub type Sender = mpsc::UnboundedSender<(Instant, Arc<Message>)>;
@@ -79,6 +80,7 @@ pub struct Connection {
clipboard: bool,
audio: bool,
file: bool,
restart: bool,
last_test_delay: i64,
lock_after_session_end: bool,
show_remote_cursor: bool, // by peer
@@ -134,7 +136,7 @@ impl Connection {
) {
let hash = Hash {
salt: Config::get_salt(),
challenge: Config::get_auto_password(),
challenge: Config::get_auto_password(6),
..Default::default()
};
let (tx_from_cm_holder, mut rx_from_cm) = mpsc::unbounded_channel::<ipc::Data>();
@@ -166,6 +168,7 @@ impl Connection {
clipboard: Config::get_option("enable-clipboard").is_empty(),
audio: Config::get_option("enable-audio").is_empty(),
file: Config::get_option("enable-file-transfer").is_empty(),
restart: Config::get_option("enable-remote-restart").is_empty(),
last_test_delay: 0,
lock_after_session_end: false,
show_remote_cursor: false,
@@ -204,6 +207,9 @@ impl Connection {
if !conn.file {
conn.send_permission(Permission::File, false).await;
}
if !conn.restart {
conn.send_permission(Permission::Restart, false).await;
}
let mut test_delay_timer =
time::interval_at(Instant::now() + TEST_DELAY_TIMEOUT, TEST_DELAY_TIMEOUT);
let mut last_recv_time = Instant::now();
@@ -281,6 +287,9 @@ impl Connection {
conn.file = enabled;
conn.send_permission(Permission::File, enabled).await;
conn.send_to_cm(ipc::Data::ClipboardFileEnabled(conn.file_transfer_enabled()));
} else if &name == "restart" {
conn.restart = enabled;
conn.send_permission(Permission::Restart, enabled).await;
}
}
ipc::Data::RawMessage(bytes) => {
@@ -297,24 +306,24 @@ impl Connection {
ipc::PrivacyModeState::OffSucceeded => {
video_service::set_privacy_mode_conn_id(0);
crate::common::make_privacy_mode_msg(
back_notification::PrivacyModeState::OffSucceeded,
back_notification::PrivacyModeState::PrvOffSucceeded,
)
}
ipc::PrivacyModeState::OffFailed => {
crate::common::make_privacy_mode_msg(
back_notification::PrivacyModeState::OffFailed,
back_notification::PrivacyModeState::PrvOffFailed,
)
}
ipc::PrivacyModeState::OffByPeer => {
video_service::set_privacy_mode_conn_id(0);
crate::common::make_privacy_mode_msg(
back_notification::PrivacyModeState::OffByPeer,
back_notification::PrivacyModeState::PrvOffByPeer,
)
}
ipc::PrivacyModeState::OffUnknown => {
video_service::set_privacy_mode_conn_id(0);
crate::common::make_privacy_mode_msg(
back_notification::PrivacyModeState::OffUnknown,
back_notification::PrivacyModeState::PrvOffUnknown,
)
}
};
@@ -415,7 +424,9 @@ impl Connection {
video_service::notify_video_frame_feched(id, None);
scrap::codec::Encoder::update_video_encoder(id, scrap::codec::EncoderUpdate::Remove);
video_service::VIDEO_QOS.lock().unwrap().reset();
password::after_session(conn.authorized);
if conn.authorized {
password::update_temporary_password();
}
if let Err(err) = conn.try_port_forward_loop(&mut rx_from_cm).await {
conn.on_close(&err.to_string(), false).await;
}
@@ -453,7 +464,7 @@ impl Connection {
} else {
Self::send_block_input_error(
&tx,
back_notification::BlockInputState::OnFailed,
back_notification::BlockInputState::BlkOnFailed,
);
}
}
@@ -463,7 +474,7 @@ impl Connection {
} else {
Self::send_block_input_error(
&tx,
back_notification::BlockInputState::OffFailed,
back_notification::BlockInputState::BlkOffFailed,
);
}
}
@@ -765,6 +776,7 @@ impl Connection {
audio: self.audio,
file: self.file,
file_transfer_enabled: self.file_transfer_enabled(),
restart: self.restart,
});
}
@@ -821,17 +833,9 @@ impl Connection {
}
fn validate_password(&mut self) -> bool {
if password::security_enabled() {
if self.validate_one_password(Config::get_security_password()) {
return true;
}
}
if password::random_password_valid() {
let password = password::random_password();
if password::temporary_enabled() {
let password = password::temporary_password();
if self.validate_one_password(password.clone()) {
if password::onetime_password_activated() {
password::set_onetime_password_activated(false);
}
SESSIONS.lock().unwrap().insert(
self.lr.my_id.clone(),
Session {
@@ -844,6 +848,11 @@ impl Connection {
return true;
}
}
if password::permanent_enabled() {
if self.validate_one_password(Config::get_permanent_password()) {
return true;
}
}
false
}
@@ -957,7 +966,7 @@ impl Connection {
} else if lr.password.is_empty() {
self.try_start_cm(lr.my_id, lr.my_name, false);
} else {
if password::passwords().len() == 0 {
if !password::has_valid_password() {
self.send_login_error("Connection not allowed").await;
return false;
}
@@ -1091,8 +1100,9 @@ impl Connection {
}
Some(file_action::Union::Send(s)) => {
let id = s.id;
let od =
can_enable_overwrite_detection(get_version_number(VERSION));
let od = can_enable_overwrite_detection(get_version_number(
&self.lr.version,
));
let path = s.path.clone();
match fs::TransferJob::new_read(
id,
@@ -1115,6 +1125,11 @@ impl Connection {
}
}
Some(file_action::Union::Receive(r)) => {
// note: 1.1.10 introduced identical file detection, which breaks original logic of send/recv files
// whenever got send/recv request, check peer version to ensure old version of rustdesk
let od = can_enable_overwrite_detection(get_version_number(
&self.lr.version,
));
self.send_fs(ipc::FS::NewWrite {
path: r.path,
id: r.id,
@@ -1125,6 +1140,7 @@ impl Connection {
.drain(..)
.map(|f| (f.name, f.modified_time))
.collect(),
overwrite_detection: od,
});
}
Some(file_action::Union::RemoveDir(d)) => {
@@ -1210,6 +1226,17 @@ impl Connection {
SESSIONS.lock().unwrap().remove(&self.lr.my_id);
return false;
}
Some(misc::Union::RestartRemoteDevice(_)) =>
{
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if self.restart {
match system_shutdown::reboot() {
Ok(_) => log::info!("Restart by the peer"),
Err(e) => log::error!("Failed to restart:{}", e),
}
}
}
_ => {}
},
_ => {}
@@ -1297,7 +1324,7 @@ impl Connection {
BoolOption::Yes => {
let msg_out = if !video_service::is_privacy_mode_supported() {
crate::common::make_privacy_mode_msg(
back_notification::PrivacyModeState::NotSupported,
back_notification::PrivacyModeState::PrvNotSupported,
)
} else {
match privacy_mode::turn_on_privacy(self.inner.id) {
@@ -1305,7 +1332,7 @@ impl Connection {
if video_service::test_create_capturer(self.inner.id, 5_000) {
video_service::set_privacy_mode_conn_id(self.inner.id);
crate::common::make_privacy_mode_msg(
back_notification::PrivacyModeState::OnSucceeded,
back_notification::PrivacyModeState::PrvOnSucceeded,
)
} else {
log::error!(
@@ -1314,12 +1341,12 @@ impl Connection {
video_service::set_privacy_mode_conn_id(0);
let _ = privacy_mode::turn_off_privacy(self.inner.id);
crate::common::make_privacy_mode_msg(
back_notification::PrivacyModeState::OnFailed,
back_notification::PrivacyModeState::PrvOnFailed,
)
}
}
Ok(false) => crate::common::make_privacy_mode_msg(
back_notification::PrivacyModeState::OnFailedPlugin,
back_notification::PrivacyModeState::PrvOnFailedPlugin,
),
Err(e) => {
log::error!("Failed to turn on privacy mode. {}", e);
@@ -1327,7 +1354,7 @@ impl Connection {
let _ = privacy_mode::turn_off_privacy(0);
}
crate::common::make_privacy_mode_msg(
back_notification::PrivacyModeState::OnFailed,
back_notification::PrivacyModeState::PrvOnFailed,
)
}
}
@@ -1337,7 +1364,7 @@ impl Connection {
BoolOption::No => {
let msg_out = if !video_service::is_privacy_mode_supported() {
crate::common::make_privacy_mode_msg(
back_notification::PrivacyModeState::NotSupported,
back_notification::PrivacyModeState::PrvNotSupported,
)
} else {
video_service::set_privacy_mode_conn_id(0);
@@ -1512,19 +1539,19 @@ mod privacy_mode {
let res = turn_off_privacy(_conn_id, None);
match res {
Ok(_) => crate::common::make_privacy_mode_msg(
back_notification::PrivacyModeState::OffSucceeded,
back_notification::PrivacyModeState::PrvOffSucceeded,
),
Err(e) => {
log::error!("Failed to turn off privacy mode {}", e);
crate::common::make_privacy_mode_msg(
back_notification::PrivacyModeState::OffFailed,
back_notification::PrivacyModeState::PrvOffFailed,
)
}
}
}
#[cfg(not(windows))]
{
crate::common::make_privacy_mode_msg(back_notification::PrivacyModeState::OffFailed)
crate::common::make_privacy_mode_msg(back_notification::PrivacyModeState::PrvOffFailed)
}
}

View File

@@ -378,7 +378,6 @@ fn run(sp: GenericService) -> ResultType<()> {
let mut c = get_capturer(true)?;
let mut video_qos = VIDEO_QOS.lock().unwrap();
video_qos.set_size(c.width as _, c.height as _);
let mut spf = video_qos.spf();
let bitrate = video_qos.generate_bitrate()?;
@@ -441,18 +440,17 @@ fn run(sp: GenericService) -> ResultType<()> {
#[cfg(windows)]
check_uac_switch(c.privacy_mode_id, c._captuerer_privacy_mode_id)?;
{
let mut video_qos = VIDEO_QOS.lock().unwrap();
if video_qos.check_if_updated() {
log::debug!(
"qos is updated, target_bitrate:{}, fps:{}",
video_qos.target_bitrate,
video_qos.fps
);
encoder.set_bitrate(video_qos.target_bitrate).unwrap();
spf = video_qos.spf();
}
let mut video_qos = VIDEO_QOS.lock().unwrap();
if video_qos.check_if_updated() {
log::debug!(
"qos is updated, target_bitrate:{}, fps:{}",
video_qos.target_bitrate,
video_qos.fps
);
encoder.set_bitrate(video_qos.target_bitrate).unwrap();
spf = video_qos.spf();
}
drop(video_qos);
if *SWITCH.lock().unwrap() {
bail!("SWITCH");
@@ -585,7 +583,7 @@ fn check_privacy_mode_changed(sp: &GenericService, privacy_mode_id: i32) -> Resu
if privacy_mode_id != privacy_mode_id_2 {
if privacy_mode_id_2 != 0 {
let msg_out = crate::common::make_privacy_mode_msg(
back_notification::PrivacyModeState::OnByOther,
back_notification::PrivacyModeState::PrvOnByOther,
);
sp.send_to_others(msg_out, privacy_mode_id_2);
}
@@ -646,7 +644,7 @@ pub fn handle_one_frame_encoded(
})?;
let mut send_conn_ids: HashSet<i32> = Default::default();
let vp9_frame = EncodedVideoFrame {
data: frame.to_vec(),
data: frame.to_vec().into(),
key: true,
pts: ms,
..Default::default()