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:
parent
302a43d68c
commit
42d17f9d2b
@ -228,6 +228,14 @@ pub fn get_uuid() -> Vec<u8> {
|
||||
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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -4,10 +4,11 @@ use crate::{
|
||||
};
|
||||
use hbb_common::{
|
||||
anyhow::{anyhow, Context},
|
||||
bytes::Bytes,
|
||||
config::HwCodecConfig,
|
||||
lazy_static, log,
|
||||
get_time, lazy_static, log,
|
||||
message_proto::{EncodedVideoFrame, EncodedVideoFrames, Message, VideoFrame},
|
||||
ResultType, bytes::Bytes,
|
||||
ResultType,
|
||||
};
|
||||
use hwcodec::{
|
||||
decode::{DecodeContext, DecodeFrame, Decoder},
|
||||
@ -105,6 +106,7 @@ impl EncoderApi for HwEncoder {
|
||||
DataFormat::H264 => vf.set_h264s(frames),
|
||||
DataFormat::H265 => vf.set_h265s(frames),
|
||||
}
|
||||
vf.timestamp = get_time();
|
||||
msg_out.set_video_frame(vf);
|
||||
Ok(msg_out)
|
||||
} else {
|
||||
|
@ -4,15 +4,15 @@
|
||||
|
||||
use hbb_common::anyhow::{anyhow, Context};
|
||||
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::STRIDE_ALIGN;
|
||||
|
||||
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::{ptr, slice};
|
||||
use hbb_common::bytes::Bytes;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum VpxVideoCodecId {
|
||||
@ -285,6 +285,7 @@ impl VpxEncoder {
|
||||
frames: vp9s.into(),
|
||||
..Default::default()
|
||||
});
|
||||
vf.timestamp = get_time();
|
||||
msg_out.set_video_frame(vf);
|
||||
msg_out
|
||||
}
|
||||
|
@ -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> {
|
||||
#[cfg(not(feature = "appimage"))]
|
||||
{
|
||||
|
@ -13,6 +13,7 @@
|
||||
// https://github.com/krruzic/pulsectl
|
||||
|
||||
use super::*;
|
||||
use hbb_common::get_time;
|
||||
use magnum_opus::{Application::*, Channels::*, Encoder};
|
||||
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();
|
||||
msg_out.set_audio_frame(AudioFrame {
|
||||
data: data.into(),
|
||||
timestamp: crate::common::get_time(),
|
||||
timestamp: get_time(),
|
||||
..Default::default()
|
||||
});
|
||||
sp.send(msg_out);
|
||||
@ -368,7 +369,7 @@ fn send_f32(data: &[f32], encoder: &mut Encoder, sp: &GenericService) {
|
||||
let mut msg_out = Message::new();
|
||||
msg_out.set_audio_frame(AudioFrame {
|
||||
data: data.into(),
|
||||
timestamp: crate::common::get_time(),
|
||||
timestamp: get_time(),
|
||||
..Default::default()
|
||||
});
|
||||
sp.send(msg_out);
|
||||
|
@ -12,7 +12,7 @@ use hbb_common::{
|
||||
fs,
|
||||
fs::can_enable_overwrite_detection,
|
||||
futures::{SinkExt, StreamExt},
|
||||
get_version_number,
|
||||
get_time, get_version_number,
|
||||
message_proto::{option_message::BoolOption, permission_info::Permission},
|
||||
password_security as password, sleep, timeout,
|
||||
tokio::{
|
||||
@ -397,7 +397,7 @@ impl Connection {
|
||||
conn.on_close("Timeout", true).await;
|
||||
break;
|
||||
}
|
||||
let time = crate::get_time();
|
||||
let time = get_time();
|
||||
if time > 0 && conn.last_test_delay == 0 {
|
||||
conn.last_test_delay = time;
|
||||
let mut msg_out = Message::new();
|
||||
@ -983,7 +983,7 @@ impl Connection {
|
||||
.get(&self.ip)
|
||||
.map(|x| x.clone())
|
||||
.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 {
|
||||
self.send_login_error("Too many wrong password attempts")
|
||||
.await;
|
||||
@ -1022,7 +1022,7 @@ impl Connection {
|
||||
self.inner.send(msg_out.into());
|
||||
} else {
|
||||
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
|
||||
.lock()
|
||||
.unwrap()
|
||||
@ -1038,9 +1038,9 @@ impl Connection {
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
if self.keyboard {
|
||||
if is_left_up(&me) {
|
||||
CLICK_TIME.store(crate::get_time(), Ordering::SeqCst);
|
||||
CLICK_TIME.store(get_time(), Ordering::SeqCst);
|
||||
} 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());
|
||||
}
|
||||
@ -1049,7 +1049,7 @@ impl Connection {
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
if self.keyboard {
|
||||
if is_enter(&me) {
|
||||
CLICK_TIME.store(crate::get_time(), Ordering::SeqCst);
|
||||
CLICK_TIME.store(get_time(), Ordering::SeqCst);
|
||||
}
|
||||
// handle all down as press
|
||||
// fix unexpected repeating key on remote linux, seems also fix abnormal alt/shift, which
|
||||
|
@ -3,7 +3,7 @@ use crate::common::IS_X11;
|
||||
#[cfg(target_os = "macos")]
|
||||
use dispatch::Queue;
|
||||
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 std::{
|
||||
convert::TryFrom,
|
||||
@ -111,7 +111,7 @@ fn run_pos(sp: GenericService, state: &mut StatePos) -> ResultType<()> {
|
||||
..Default::default()
|
||||
});
|
||||
let exclude = {
|
||||
let now = crate::get_time();
|
||||
let now = get_time();
|
||||
let lock = LATEST_INPUT.lock().unwrap();
|
||||
if now - lock.time < 300 {
|
||||
lock.conn
|
||||
@ -365,7 +365,7 @@ fn handle_mouse_(evt: &MouseEvent, conn: i32) {
|
||||
let buttons = evt.mask >> 3;
|
||||
let evt_type = evt.mask & 0x7;
|
||||
if evt_type == 0 {
|
||||
let time = crate::get_time();
|
||||
let time = get_time();
|
||||
*LATEST_INPUT.lock().unwrap() = Input { time, conn };
|
||||
}
|
||||
let mut en = ENIGO.lock().unwrap();
|
||||
|
@ -601,7 +601,7 @@ fn create_msg(vp9s: Vec<EncodedVideoFrame>) -> Message {
|
||||
frames: vp9s.into(),
|
||||
..Default::default()
|
||||
});
|
||||
vf.timestamp = crate::common::get_time();
|
||||
vf.timestamp = hbb_common::get_time();
|
||||
msg_out.set_video_frame(vf);
|
||||
msg_out
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user