Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

update hwcodec, use ms as pts like vpx (#8422)

21pages30bd4e1cef96
diff --git a/Cargo.lock b/Cargo.lock
index 9b9101bb6..54bef4444 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3037,8 +3037,8 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "hwcodec"
-version = "0.4.17"
-source = "git+https://github.com/21pages/hwcodec#38eb9bfc4730986ebeb519ab39027d654356ce1a"
+version = "0.4.18"
+source = "git+https://github.com/21pages/hwcodec#b84d5bbefa949194d1fc51a5c7e9d7988e315ce6"
dependencies = [
"bindgen 0.59.2",
"cc",
diff --git a/libs/scrap/examples/benchmark.rs b/libs/scrap/examples/benchmark.rs
index 3ef7916a9..803a4343c 100644
--- a/libs/scrap/examples/benchmark.rs
+++ b/libs/scrap/examples/benchmark.rs
@@ -287,13 +287,17 @@ mod hw {
let mut mid_data = Vec::new();
let mut counter = 0;
let mut time_sum = Duration::ZERO;
+ let start = std::time::Instant::now();
loop {
match c.frame(std::time::Duration::from_millis(30)) {
Ok(frame) => {
let tmp_timer = Instant::now();
let frame = frame.to(encoder.yuvfmt(), &mut yuv, &mut mid_data).unwrap();
let yuv = frame.yuv().unwrap();
- for ref frame in encoder.encode(&yuv).unwrap() {
+ for ref frame in encoder
+ .encode(&yuv, start.elapsed().as_millis() as _)
+ .unwrap()
+ {
size += frame.data.len();
h26xs.push(frame.data.to_vec());
diff --git a/libs/scrap/src/common/hwcodec.rs b/libs/scrap/src/common/hwcodec.rs
index 589396ede..c387afcd7 100644
--- a/libs/scrap/src/common/hwcodec.rs
+++ b/libs/scrap/src/common/hwcodec.rs
@@ -28,7 +28,7 @@ use hwcodec::{
};
const DEFAULT_PIXFMT: AVPixelFormat = AVPixelFormat::AV_PIX_FMT_NV12;
-pub const DEFAULT_TIME_BASE: [i32; 2] = [1, 30];
+pub const DEFAULT_FPS: i32 = 30;
const DEFAULT_GOP: i32 = i32::MAX;
const DEFAULT_HW_QUALITY: Quality = Quality_Default;
@@ -82,7 +82,7 @@ impl EncoderApi for HwRamEncoder {
pixfmt: DEFAULT_PIXFMT,
align: HW_STRIDE_ALIGN as _,
kbs: bitrate as i32,
- timebase: DEFAULT_TIME_BASE,
+ fps: DEFAULT_FPS,
gop,
quality: DEFAULT_HW_QUALITY,
rc,
@@ -113,16 +113,16 @@ impl EncoderApi for HwRamEncoder {
}
}
- fn encode_to_message(&mut self, input: EncodeInput, _ms: i64) -> ResultType<VideoFrame> {
+ fn encode_to_message(&mut self, input: EncodeInput, ms: i64) -> ResultType<VideoFrame> {
let mut vf = VideoFrame::new();
let mut frames = Vec::new();
for frame in self
- .encode(input.yuv()?)
+ .encode(input.yuv()?, ms)
.with_context(|| "Failed to encode")?
{
frames.push(EncodedVideoFrame {
data: Bytes::from(frame.data),
- pts: frame.pts as _,
+ pts: frame.pts,
key: frame.key == 1,
..Default::default()
});
@@ -236,8 +236,8 @@ impl HwRamEncoder {
info
}
- pub fn encode(&mut self, yuv: &[u8]) -> ResultType<Vec<EncodeFrame>> {
- match self.encoder.encode(yuv) {
+ pub fn encode(&mut self, yuv: &[u8], ms: i64) -> ResultType<Vec<EncodeFrame>> {
+ match self.encoder.encode(yuv, ms) {
Ok(v) => {
let mut data = Vec::<EncodeFrame>::new();
data.append(v);
@@ -664,7 +664,7 @@ pub fn check_available_hwcodec() -> String {
pixfmt: DEFAULT_PIXFMT,
align: HW_STRIDE_ALIGN as _,
kbs: 0,
- timebase: DEFAULT_TIME_BASE,
+ fps: DEFAULT_FPS,
gop: DEFAULT_GOP,
quality: DEFAULT_HW_QUALITY,
rc: RC_CBR,
diff --git a/libs/scrap/src/common/record.rs b/libs/scrap/src/common/record.rs
index 54c9c1864..52973c2b2 100644
--- a/libs/scrap/src/common/record.rs
+++ b/libs/scrap/src/common/record.rs
@@ -331,7 +331,7 @@ impl RecorderApi for HwRecorder {
width: ctx.width,
height: ctx.height,
is265: ctx.format == CodecFormat::H265,
- framerate: crate::hwcodec::DEFAULT_TIME_BASE[1] as _,
+ framerate: crate::hwcodec::DEFAULT_FPS as _,
})
.map_err(|_| anyhow!("Failed to create hardware muxer"))?;
Ok(HwRecorder {
diff --git a/libs/scrap/src/common/vram.rs b/libs/scrap/src/common/vram.rs
index 8de6658a4..241908b74 100644
--- a/libs/scrap/src/common/vram.rs
+++ b/libs/scrap/src/common/vram.rs
@@ -99,15 +99,18 @@ impl EncoderApi for VRamEncoder {
fn encode_to_message(
&mut self,
frame: EncodeInput,
- _ms: i64,
+ ms: i64,
) -> ResultType<hbb_common::message_proto::VideoFrame> {
let texture = frame.texture()?;
let mut vf = VideoFrame::new();
let mut frames = Vec::new();
- for frame in self.encode(texture).with_context(|| "Failed to encode")? {
+ for frame in self
+ .encode(texture, ms)
+ .with_context(|| "Failed to encode")?
+ {
frames.push(EncodedVideoFrame {
data: Bytes::from(frame.data),
- pts: frame.pts as _,
+ pts: frame.pts,
key: frame.key == 1,
..Default::default()
});
@@ -266,8 +269,8 @@ impl VRamEncoder {
}
}
- pub fn encode(&mut self, texture: *mut c_void) -> ResultType<Vec<EncodeFrame>> {
- match self.encoder.encode(texture) {
+ pub fn encode(&mut self, texture: *mut c_void, ms: i64) -> ResultType<Vec<EncodeFrame>> {
+ match self.encoder.encode(texture, ms) {
Ok(v) => {
let mut data = Vec::<EncodeFrame>::new();
data.append(v);