fix mediacodec check_bitrate_range not work (#8133)
should check with mc_name, and that cause the highest custom bitrate being invalid Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
parent
1efce51222
commit
902e166f0c
@ -46,12 +46,10 @@ pub struct HwRamEncoderConfig {
|
|||||||
|
|
||||||
pub struct HwRamEncoder {
|
pub struct HwRamEncoder {
|
||||||
encoder: Encoder,
|
encoder: Encoder,
|
||||||
name: String,
|
|
||||||
pub format: DataFormat,
|
pub format: DataFormat,
|
||||||
pub pixfmt: AVPixelFormat,
|
pub pixfmt: AVPixelFormat,
|
||||||
width: u32,
|
|
||||||
height: u32,
|
|
||||||
bitrate: u32, //kbs
|
bitrate: u32, //kbs
|
||||||
|
config: HwRamEncoderConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EncoderApi for HwRamEncoder {
|
impl EncoderApi for HwRamEncoder {
|
||||||
@ -67,7 +65,7 @@ impl EncoderApi for HwRamEncoder {
|
|||||||
if base_bitrate <= 0 {
|
if base_bitrate <= 0 {
|
||||||
bitrate = base_bitrate;
|
bitrate = base_bitrate;
|
||||||
}
|
}
|
||||||
bitrate = Self::check_bitrate_range(&config.name, bitrate);
|
bitrate = Self::check_bitrate_range(&config, bitrate);
|
||||||
let gop = config.keyframe_interval.unwrap_or(DEFAULT_GOP as _) as i32;
|
let gop = config.keyframe_interval.unwrap_or(DEFAULT_GOP as _) as i32;
|
||||||
let ctx = EncodeContext {
|
let ctx = EncodeContext {
|
||||||
name: config.name.clone(),
|
name: config.name.clone(),
|
||||||
@ -95,12 +93,10 @@ impl EncoderApi for HwRamEncoder {
|
|||||||
match Encoder::new(ctx.clone()) {
|
match Encoder::new(ctx.clone()) {
|
||||||
Ok(encoder) => Ok(HwRamEncoder {
|
Ok(encoder) => Ok(HwRamEncoder {
|
||||||
encoder,
|
encoder,
|
||||||
name: config.name,
|
|
||||||
format,
|
format,
|
||||||
pixfmt: ctx.pixfmt,
|
pixfmt: ctx.pixfmt,
|
||||||
width: ctx.width as _,
|
|
||||||
height: ctx.height as _,
|
|
||||||
bitrate,
|
bitrate,
|
||||||
|
config,
|
||||||
}),
|
}),
|
||||||
Err(_) => Err(anyhow!(format!("Failed to create encoder"))),
|
Err(_) => Err(anyhow!(format!("Failed to create encoder"))),
|
||||||
}
|
}
|
||||||
@ -172,10 +168,10 @@ impl EncoderApi for HwRamEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn set_quality(&mut self, quality: crate::codec::Quality) -> ResultType<()> {
|
fn set_quality(&mut self, quality: crate::codec::Quality) -> ResultType<()> {
|
||||||
let b = Self::convert_quality(&self.name, quality);
|
let b = Self::convert_quality(&self.config.name, quality);
|
||||||
let mut bitrate = base_bitrate(self.width as _, self.height as _) * b / 100;
|
let mut bitrate = base_bitrate(self.config.width as _, self.config.height as _) * b / 100;
|
||||||
if bitrate > 0 {
|
if bitrate > 0 {
|
||||||
bitrate = Self::check_bitrate_range(&self.name, bitrate);
|
bitrate = Self::check_bitrate_range(&self.config, self.bitrate);
|
||||||
self.encoder.set_bitrate(bitrate as _).ok();
|
self.encoder.set_bitrate(bitrate as _).ok();
|
||||||
self.bitrate = bitrate;
|
self.bitrate = bitrate;
|
||||||
}
|
}
|
||||||
@ -189,17 +185,17 @@ impl EncoderApi for HwRamEncoder {
|
|||||||
fn support_abr(&self) -> bool {
|
fn support_abr(&self) -> bool {
|
||||||
["qsv", "vaapi", "mediacodec"]
|
["qsv", "vaapi", "mediacodec"]
|
||||||
.iter()
|
.iter()
|
||||||
.all(|&x| !self.name.contains(x))
|
.all(|&x| !self.config.name.contains(x))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn support_changing_quality(&self) -> bool {
|
fn support_changing_quality(&self) -> bool {
|
||||||
["vaapi", "mediacodec"]
|
["vaapi", "mediacodec"]
|
||||||
.iter()
|
.iter()
|
||||||
.all(|&x| !self.name.contains(x))
|
.all(|&x| !self.config.name.contains(x))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn latency_free(&self) -> bool {
|
fn latency_free(&self) -> bool {
|
||||||
!self.name.contains("mediacodec")
|
!self.config.name.contains("mediacodec")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,17 +252,23 @@ impl HwRamEncoder {
|
|||||||
quality * factor
|
quality * factor
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_bitrate_range(name: &str, bitrate: u32) -> u32 {
|
pub fn check_bitrate_range(config: &HwRamEncoderConfig, bitrate: u32) -> u32 {
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
if name.contains("mediacodec") {
|
if config.name.contains("mediacodec") {
|
||||||
let info = crate::android::ffi::get_codec_info();
|
let info = crate::android::ffi::get_codec_info();
|
||||||
if let Some(info) = info {
|
if let Some(info) = info {
|
||||||
if let Some(codec) = info.codecs.iter().find(|c| c.name == name && c.is_encoder) {
|
if let Some(codec) = info
|
||||||
if bitrate > codec.max_bitrate {
|
.codecs
|
||||||
return codec.max_bitrate;
|
.iter()
|
||||||
}
|
.find(|c| Some(c.name.clone()) == config.mc_name && c.is_encoder)
|
||||||
if bitrate < codec.min_bitrate {
|
{
|
||||||
return codec.min_bitrate;
|
if codec.max_bitrate > codec.min_bitrate {
|
||||||
|
if bitrate > codec.max_bitrate {
|
||||||
|
return codec.max_bitrate;
|
||||||
|
}
|
||||||
|
if bitrate < codec.min_bitrate {
|
||||||
|
return codec.min_bitrate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user