fix custom_image_qulity and android

This commit is contained in:
csf 2022-06-30 20:48:29 +08:00
parent a5ab0db5b9
commit 5a7dca72c8
5 changed files with 24 additions and 12 deletions

View File

@ -11,13 +11,13 @@ use crate::vpxcodec::*;
use hbb_common::{
anyhow::anyhow,
config::Config2,
log,
message_proto::{test_delay, video_frame, Message, VP9s, VideoCodecState},
ResultType,
};
#[cfg(feature = "hwcodec")]
use hbb_common::{
config::Config2,
lazy_static,
message_proto::{H264s, H265s},
};

View File

@ -3,7 +3,7 @@
// https://github.com/rust-av/vpx-rs/blob/master/src/decoder.rs
use hbb_common::anyhow::{anyhow, Context};
use hbb_common::message_proto::{Message, VP9s, VideoFrame, VP9, test_delay};
use hbb_common::message_proto::{test_delay, Message, VP9s, VideoFrame, VP9};
use hbb_common::ResultType;
use crate::codec::EncoderApi;
@ -237,7 +237,7 @@ impl EncoderApi for VpxEncoder {
fn get_codec_format(&self) -> test_delay::CodecFormat {
match self.format {
VpxVideoCodecId::VP8 => test_delay::CodecFormat::VP8,
VpxVideoCodecId::VP9 => test_delay::CodecFormat::VP9
VpxVideoCodecId::VP9 => test_delay::CodecFormat::VP9,
}
}
}

View File

@ -914,7 +914,7 @@ impl LoginConfigHandler {
n += 1;
} else if q == "custom" {
let config = PeerConfig::load(&self.id);
msg.custom_image_quality = config.custom_image_quality[0] as _;
msg.custom_image_quality = config.custom_image_quality[0] << 8;
n += 1;
}
if self.get_toggle_option("show-remote-cursor") {
@ -1212,6 +1212,14 @@ where
return (video_sender, audio_sender);
}
pub async fn handle_test_delay(t: TestDelay, peer: &mut Stream) {
if !t.from_client {
let mut msg_out = Message::new();
msg_out.set_test_delay(t);
allow_err!(peer.send(&msg_out).await);
}
}
// mask = buttons << 3 | type
// type, 1: down, 2: up, 3: wheel
// buttons, 1: left, 2: right, 4: middle

View File

@ -139,6 +139,8 @@ impl VideoQoS {
time::Duration::from_secs_f32(1. / (self.fps as f32))
}
// update_network_delay periodically
// decrease the bitrate when the delay gets bigger
pub fn update_network_delay(&mut self, delay: u32) {
if self.current_delay.eq(&0) {
self.current_delay = delay;
@ -195,9 +197,10 @@ impl VideoQoS {
self.updated = true;
}
// handle image_quality change from peer
pub fn update_image_quality(&mut self, image_quality: i32) {
let image_quality = Self::convert_quality(image_quality) as _;
log::debug!("VideoQoS update_image_quality{}", image_quality);
log::debug!("VideoQoS update_image_quality: {}", image_quality);
if self.current_image_quality != image_quality {
self.current_image_quality = image_quality;
let _ = self.generate_bitrate().ok();
@ -224,11 +227,14 @@ impl VideoQoS {
let fix = Display::fix_quality() as u32;
log::debug!("Android screen, fix quality:{}", fix);
let base_bitrate = base_bitrate * fix;
self.target_bitrate = base_bitrate * self.image_quality / 100;
self.target_bitrate = base_bitrate * self.current_image_quality / 100;
Ok(self.target_bitrate)
}
#[cfg(not(target_os = "android"))]
{
self.target_bitrate = base_bitrate * self.current_image_quality / 100;
Ok(self.target_bitrate)
}
self.target_bitrate = base_bitrate * self.current_image_quality / 100;
Ok(self.target_bitrate)
}
pub fn check_if_updated(&mut self) -> bool {

View File

@ -277,7 +277,7 @@ impl Handler {
test_delay::CodecFormat::VP9 => "VP9",
test_delay::CodecFormat::H264 => "H264",
test_delay::CodecFormat::H265 => "H265",
};
};
self.call2(
"updateQualityStatus",
&make_args!(
@ -2617,9 +2617,7 @@ impl Interface for Handler {
codec_format: t.codec_format.enum_value_or_default(),
..Default::default()
});
let mut msg_out = Message::new();
msg_out.set_test_delay(t);
allow_err!(peer.send(&msg_out).await);
handle_test_delay(t, peer).await;
}
}
}