rustdesk/src/client/helper.rs

65 lines
1.7 KiB
Rust
Raw Normal View History

2022-08-04 17:24:02 +08:00
use hbb_common::{
2023-03-23 14:31:50 +08:00
get_time,
2023-04-01 10:13:39 +08:00
message_proto::{video_frame, Message, VideoFrame, VoiceCallRequest, VoiceCallResponse},
2022-08-04 17:24:02 +08:00
};
2023-04-01 10:13:39 +08:00
#[derive(PartialEq, Debug, Clone)]
pub enum CodecFormat {
VP9,
H264,
H265,
Unknown,
}
impl From<&VideoFrame> for CodecFormat {
fn from(it: &VideoFrame) -> Self {
match it.union {
Some(video_frame::Union::Vp9s(_)) => CodecFormat::VP9,
Some(video_frame::Union::H264s(_)) => CodecFormat::H264,
Some(video_frame::Union::H265s(_)) => CodecFormat::H265,
_ => CodecFormat::Unknown,
}
}
}
impl ToString for CodecFormat {
fn to_string(&self) -> String {
match self {
CodecFormat::VP9 => "VP9".into(),
CodecFormat::H264 => "H264".into(),
CodecFormat::H265 => "H265".into(),
CodecFormat::Unknown => "Unknow".into(),
}
}
}
2022-08-04 17:24:02 +08:00
#[derive(Debug, Default)]
pub struct QualityStatus {
pub speed: Option<String>,
pub fps: Option<i32>,
pub delay: Option<i32>,
pub target_bitrate: Option<i32>,
pub codec_format: Option<CodecFormat>,
}
2023-02-06 11:42:25 +08:00
#[inline]
pub fn new_voice_call_request(is_connect: bool) -> Message {
let mut req = VoiceCallRequest::new();
req.is_connect = is_connect;
req.req_timestamp = get_time();
let mut msg = Message::new();
msg.set_voice_call_request(req);
msg
}
#[inline]
pub fn new_voice_call_response(request_timestamp: i64, accepted: bool) -> Message {
let mut resp = VoiceCallResponse::new();
resp.accepted = accepted;
resp.req_timestamp = request_timestamp;
resp.ack_timestamp = get_time();
let mut msg = Message::new();
msg.set_voice_call_response(resp);
msg
2023-03-23 14:31:50 +08:00
}