mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
sync codec format
This commit is contained in:
@@ -479,10 +479,18 @@ message OptionMessage {
|
||||
}
|
||||
|
||||
message TestDelay {
|
||||
enum CodecFormat {
|
||||
Unknown = 0;
|
||||
VP8 = 1;
|
||||
VP9 = 2;
|
||||
H264 = 3;
|
||||
H265 = 4;
|
||||
}
|
||||
int64 time = 1;
|
||||
bool from_client = 2;
|
||||
uint32 last_delay = 3;
|
||||
uint32 target_bitrate = 4;
|
||||
CodecFormat codec_format = 5;
|
||||
}
|
||||
|
||||
message PublicKey {
|
||||
|
||||
@@ -12,7 +12,7 @@ use crate::vpxcodec::*;
|
||||
use hbb_common::{
|
||||
anyhow::anyhow,
|
||||
log,
|
||||
message_proto::{video_frame, Message, VP9s, VideoCodecState},
|
||||
message_proto::{video_frame, Message, VP9s, VideoCodecState, test_delay},
|
||||
ResultType,
|
||||
};
|
||||
#[cfg(feature = "hwcodec")]
|
||||
@@ -52,6 +52,8 @@ pub trait EncoderApi {
|
||||
fn use_yuv(&self) -> bool;
|
||||
|
||||
fn set_bitrate(&mut self, bitrate: u32) -> ResultType<()>;
|
||||
|
||||
fn get_codec_format(&self) -> test_delay::CodecFormat;
|
||||
}
|
||||
|
||||
pub struct DecoderCfg {
|
||||
|
||||
@@ -6,7 +6,7 @@ use hbb_common::{
|
||||
anyhow::{anyhow, Context},
|
||||
config::HwCodecConfig,
|
||||
lazy_static, log,
|
||||
message_proto::{H264s, H265s, Message, VideoFrame, H264, H265},
|
||||
message_proto::{test_delay, H264s, H265s, Message, VideoFrame, H264, H265},
|
||||
ResultType,
|
||||
};
|
||||
use hwcodec::{
|
||||
@@ -143,6 +143,13 @@ impl EncoderApi for HwEncoder {
|
||||
self.encoder.set_bitrate((bitrate * 1000) as _).ok();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_codec_format(&self) -> test_delay::CodecFormat {
|
||||
match self.format {
|
||||
DataFormat::H264 => test_delay::CodecFormat::H264,
|
||||
DataFormat::H265 => test_delay::CodecFormat::H265,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HwEncoder {
|
||||
|
||||
@@ -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};
|
||||
use hbb_common::message_proto::{Message, VP9s, VideoFrame, VP9, test_delay};
|
||||
use hbb_common::ResultType;
|
||||
|
||||
use crate::codec::EncoderApi;
|
||||
@@ -27,6 +27,7 @@ impl Default for VpxVideoCodecId {
|
||||
|
||||
pub struct VpxEncoder {
|
||||
ctx: vpx_codec_ctx_t,
|
||||
format: VpxVideoCodecId,
|
||||
width: usize,
|
||||
height: usize,
|
||||
}
|
||||
@@ -96,14 +97,17 @@ impl EncoderApi for VpxEncoder {
|
||||
{
|
||||
match cfg {
|
||||
crate::codec::EncoderCfg::VPX(config) => {
|
||||
let format;
|
||||
let i;
|
||||
if cfg!(feature = "VP8") {
|
||||
i = match config.codec {
|
||||
VpxVideoCodecId::VP8 => call_vpx_ptr!(vpx_codec_vp8_cx()),
|
||||
VpxVideoCodecId::VP9 => call_vpx_ptr!(vpx_codec_vp9_cx()),
|
||||
};
|
||||
format = config.codec;
|
||||
} else {
|
||||
i = call_vpx_ptr!(vpx_codec_vp9_cx());
|
||||
format = VpxVideoCodecId::VP9;
|
||||
}
|
||||
let mut c = unsafe { std::mem::MaybeUninit::zeroed().assume_init() };
|
||||
call_vpx!(vpx_codec_enc_config_default(i, &mut c, 0));
|
||||
@@ -190,6 +194,7 @@ impl EncoderApi for VpxEncoder {
|
||||
|
||||
Ok(Self {
|
||||
ctx,
|
||||
format,
|
||||
width: config.width as _,
|
||||
height: config.height as _,
|
||||
})
|
||||
@@ -228,6 +233,13 @@ impl EncoderApi for VpxEncoder {
|
||||
call_vpx!(vpx_codec_enc_config_set(&mut self.ctx, &new_enc_cfg));
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
fn get_codec_format(&self) -> test_delay::CodecFormat {
|
||||
match self.format {
|
||||
VpxVideoCodecId::VP8 => test_delay::CodecFormat::VP8,
|
||||
VpxVideoCodecId::VP9 => test_delay::CodecFormat::VP9
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VpxEncoder {
|
||||
|
||||
Reference in New Issue
Block a user