fix audio no sound, add missing VideoFrame timestamp

move get_time to hbb_common

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2022-09-11 21:46:53 +08:00
parent 302a43d68c
commit 42d17f9d2b
8 changed files with 30 additions and 26 deletions

View File

@ -228,6 +228,14 @@ pub fn get_uuid() -> Vec<u8> {
Config::get_key_pair().1 Config::get_key_pair().1
} }
#[inline]
pub fn get_time() -> i64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_millis())
.unwrap_or(0) as _
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View File

@ -4,10 +4,11 @@ use crate::{
}; };
use hbb_common::{ use hbb_common::{
anyhow::{anyhow, Context}, anyhow::{anyhow, Context},
bytes::Bytes,
config::HwCodecConfig, config::HwCodecConfig,
lazy_static, log, get_time, lazy_static, log,
message_proto::{EncodedVideoFrame, EncodedVideoFrames, Message, VideoFrame}, message_proto::{EncodedVideoFrame, EncodedVideoFrames, Message, VideoFrame},
ResultType, bytes::Bytes, ResultType,
}; };
use hwcodec::{ use hwcodec::{
decode::{DecodeContext, DecodeFrame, Decoder}, decode::{DecodeContext, DecodeFrame, Decoder},
@ -105,6 +106,7 @@ impl EncoderApi for HwEncoder {
DataFormat::H264 => vf.set_h264s(frames), DataFormat::H264 => vf.set_h264s(frames),
DataFormat::H265 => vf.set_h265s(frames), DataFormat::H265 => vf.set_h265s(frames),
} }
vf.timestamp = get_time();
msg_out.set_video_frame(vf); msg_out.set_video_frame(vf);
Ok(msg_out) Ok(msg_out)
} else { } else {

View File

@ -4,15 +4,15 @@
use hbb_common::anyhow::{anyhow, Context}; use hbb_common::anyhow::{anyhow, Context};
use hbb_common::message_proto::{EncodedVideoFrame, EncodedVideoFrames, Message, VideoFrame}; use hbb_common::message_proto::{EncodedVideoFrame, EncodedVideoFrames, Message, VideoFrame};
use hbb_common::ResultType; use hbb_common::{ResultType, get_time};
use crate::codec::EncoderApi; use crate::codec::EncoderApi;
use crate::STRIDE_ALIGN; use crate::STRIDE_ALIGN;
use super::vpx::{vp8e_enc_control_id::*, vpx_codec_err_t::*, *}; use super::vpx::{vp8e_enc_control_id::*, vpx_codec_err_t::*, *};
use hbb_common::bytes::Bytes;
use std::os::raw::{c_int, c_uint}; use std::os::raw::{c_int, c_uint};
use std::{ptr, slice}; use std::{ptr, slice};
use hbb_common::bytes::Bytes;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum VpxVideoCodecId { pub enum VpxVideoCodecId {
@ -285,6 +285,7 @@ impl VpxEncoder {
frames: vp9s.into(), frames: vp9s.into(),
..Default::default() ..Default::default()
}); });
vf.timestamp = get_time();
msg_out.set_video_frame(vf); msg_out.set_video_frame(vf);
msg_out msg_out
} }

View File

@ -426,14 +426,6 @@ pub fn refresh_rendezvous_server() {
}); });
} }
#[inline]
pub fn get_time() -> i64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_millis())
.unwrap_or(0) as _
}
pub fn run_me<T: AsRef<std::ffi::OsStr>>(args: Vec<T>) -> std::io::Result<std::process::Child> { pub fn run_me<T: AsRef<std::ffi::OsStr>>(args: Vec<T>) -> std::io::Result<std::process::Child> {
#[cfg(not(feature = "appimage"))] #[cfg(not(feature = "appimage"))]
{ {

View File

@ -13,6 +13,7 @@
// https://github.com/krruzic/pulsectl // https://github.com/krruzic/pulsectl
use super::*; use super::*;
use hbb_common::get_time;
use magnum_opus::{Application::*, Channels::*, Encoder}; use magnum_opus::{Application::*, Channels::*, Encoder};
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
@ -348,7 +349,7 @@ fn send_f32(data: &[f32], encoder: &mut Encoder, sp: &GenericService) {
let mut msg_out = Message::new(); let mut msg_out = Message::new();
msg_out.set_audio_frame(AudioFrame { msg_out.set_audio_frame(AudioFrame {
data: data.into(), data: data.into(),
timestamp: crate::common::get_time(), timestamp: get_time(),
..Default::default() ..Default::default()
}); });
sp.send(msg_out); sp.send(msg_out);
@ -368,7 +369,7 @@ fn send_f32(data: &[f32], encoder: &mut Encoder, sp: &GenericService) {
let mut msg_out = Message::new(); let mut msg_out = Message::new();
msg_out.set_audio_frame(AudioFrame { msg_out.set_audio_frame(AudioFrame {
data: data.into(), data: data.into(),
timestamp: crate::common::get_time(), timestamp: get_time(),
..Default::default() ..Default::default()
}); });
sp.send(msg_out); sp.send(msg_out);

View File

@ -12,7 +12,7 @@ use hbb_common::{
fs, fs,
fs::can_enable_overwrite_detection, fs::can_enable_overwrite_detection,
futures::{SinkExt, StreamExt}, futures::{SinkExt, StreamExt},
get_version_number, get_time, get_version_number,
message_proto::{option_message::BoolOption, permission_info::Permission}, message_proto::{option_message::BoolOption, permission_info::Permission},
password_security as password, sleep, timeout, password_security as password, sleep, timeout,
tokio::{ tokio::{
@ -397,7 +397,7 @@ impl Connection {
conn.on_close("Timeout", true).await; conn.on_close("Timeout", true).await;
break; break;
} }
let time = crate::get_time(); let time = get_time();
if time > 0 && conn.last_test_delay == 0 { if time > 0 && conn.last_test_delay == 0 {
conn.last_test_delay = time; conn.last_test_delay = time;
let mut msg_out = Message::new(); let mut msg_out = Message::new();
@ -983,7 +983,7 @@ impl Connection {
.get(&self.ip) .get(&self.ip)
.map(|x| x.clone()) .map(|x| x.clone())
.unwrap_or((0, 0, 0)); .unwrap_or((0, 0, 0));
let time = (crate::get_time() / 60_000) as i32; let time = (get_time() / 60_000) as i32;
if failure.2 > 30 { if failure.2 > 30 {
self.send_login_error("Too many wrong password attempts") self.send_login_error("Too many wrong password attempts")
.await; .await;
@ -1022,7 +1022,7 @@ impl Connection {
self.inner.send(msg_out.into()); self.inner.send(msg_out.into());
} else { } else {
self.last_test_delay = 0; self.last_test_delay = 0;
let new_delay = (crate::get_time() - t.time) as u32; let new_delay = (get_time() - t.time) as u32;
video_service::VIDEO_QOS video_service::VIDEO_QOS
.lock() .lock()
.unwrap() .unwrap()
@ -1038,9 +1038,9 @@ impl Connection {
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
if self.keyboard { if self.keyboard {
if is_left_up(&me) { if is_left_up(&me) {
CLICK_TIME.store(crate::get_time(), Ordering::SeqCst); CLICK_TIME.store(get_time(), Ordering::SeqCst);
} else { } else {
MOUSE_MOVE_TIME.store(crate::get_time(), Ordering::SeqCst); MOUSE_MOVE_TIME.store(get_time(), Ordering::SeqCst);
} }
self.input_mouse(me, self.inner.id()); self.input_mouse(me, self.inner.id());
} }
@ -1049,7 +1049,7 @@ impl Connection {
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
if self.keyboard { if self.keyboard {
if is_enter(&me) { if is_enter(&me) {
CLICK_TIME.store(crate::get_time(), Ordering::SeqCst); CLICK_TIME.store(get_time(), Ordering::SeqCst);
} }
// handle all down as press // handle all down as press
// fix unexpected repeating key on remote linux, seems also fix abnormal alt/shift, which // fix unexpected repeating key on remote linux, seems also fix abnormal alt/shift, which

View File

@ -3,7 +3,7 @@ use crate::common::IS_X11;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
use dispatch::Queue; use dispatch::Queue;
use enigo::{Enigo, Key, KeyboardControllable, MouseButton, MouseControllable}; use enigo::{Enigo, Key, KeyboardControllable, MouseButton, MouseControllable};
use hbb_common::{config::COMPRESS_LEVEL, protobuf::EnumOrUnknown}; use hbb_common::{config::COMPRESS_LEVEL, get_time, protobuf::EnumOrUnknown};
use rdev::{simulate, EventType, Key as RdevKey}; use rdev::{simulate, EventType, Key as RdevKey};
use std::{ use std::{
convert::TryFrom, convert::TryFrom,
@ -111,7 +111,7 @@ fn run_pos(sp: GenericService, state: &mut StatePos) -> ResultType<()> {
..Default::default() ..Default::default()
}); });
let exclude = { let exclude = {
let now = crate::get_time(); let now = get_time();
let lock = LATEST_INPUT.lock().unwrap(); let lock = LATEST_INPUT.lock().unwrap();
if now - lock.time < 300 { if now - lock.time < 300 {
lock.conn lock.conn
@ -365,7 +365,7 @@ fn handle_mouse_(evt: &MouseEvent, conn: i32) {
let buttons = evt.mask >> 3; let buttons = evt.mask >> 3;
let evt_type = evt.mask & 0x7; let evt_type = evt.mask & 0x7;
if evt_type == 0 { if evt_type == 0 {
let time = crate::get_time(); let time = get_time();
*LATEST_INPUT.lock().unwrap() = Input { time, conn }; *LATEST_INPUT.lock().unwrap() = Input { time, conn };
} }
let mut en = ENIGO.lock().unwrap(); let mut en = ENIGO.lock().unwrap();

View File

@ -601,7 +601,7 @@ fn create_msg(vp9s: Vec<EncodedVideoFrame>) -> Message {
frames: vp9s.into(), frames: vp9s.into(),
..Default::default() ..Default::default()
}); });
vf.timestamp = crate::common::get_time(); vf.timestamp = hbb_common::get_time();
msg_out.set_video_frame(vf); msg_out.set_video_frame(vf);
msg_out msg_out
} }