()
| 415 | } |
| 416 | |
| 417 | fn get_config() -> ResultType<Available> { |
| 418 | #[cfg(target_os = "android")] |
| 419 | { |
| 420 | let info = crate::android::ffi::get_codec_info(); |
| 421 | log::info!("all codec info: {info:?}"); |
| 422 | struct T { |
| 423 | name_prefix: &'static str, |
| 424 | data_format: DataFormat, |
| 425 | } |
| 426 | let ts = vec![ |
| 427 | T { |
| 428 | name_prefix: "h264", |
| 429 | data_format: DataFormat::H264, |
| 430 | }, |
| 431 | T { |
| 432 | name_prefix: "hevc", |
| 433 | data_format: DataFormat::H265, |
| 434 | }, |
| 435 | ]; |
| 436 | let mut e = vec![]; |
| 437 | if let Some(info) = info { |
| 438 | ts.iter().for_each(|t| { |
| 439 | let codecs: Vec<_> = info |
| 440 | .codecs |
| 441 | .iter() |
| 442 | .filter(|c| { |
| 443 | c.is_encoder |
| 444 | && c.mime_type.as_str() == get_mime_type(t.data_format) |
| 445 | && c.nv12 |
| 446 | && c.hw == Some(true) //only use hardware codec |
| 447 | }) |
| 448 | .collect(); |
| 449 | log::debug!("available {:?} encoders: {codecs:?}", t.data_format); |
| 450 | let screen_wh = std::cmp::max(info.w, info.h); |
| 451 | let mut best = None; |
| 452 | if let Some(codec) = codecs |
| 453 | .iter() |
| 454 | .find(|c| c.max_width >= screen_wh && c.max_height >= screen_wh) |
| 455 | { |
| 456 | best = Some(codec.name.clone()); |
| 457 | } else { |
| 458 | // find the max resolution |
| 459 | let mut max_area = 0; |
| 460 | for codec in codecs.iter() { |
| 461 | if codec.max_width * codec.max_height > max_area { |
| 462 | best = Some(codec.name.clone()); |
| 463 | max_area = codec.max_width * codec.max_height; |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | if let Some(best) = best { |
| 468 | e.push(CodecInfo { |
| 469 | name: format!("{}_mediacodec", t.name_prefix), |
| 470 | mc_name: Some(best), |
| 471 | format: t.data_format, |
| 472 | hwdevice: hwcodec::ffmpeg::AVHWDeviceType::AV_HWDEVICE_TYPE_NONE, |
| 473 | priority: 0, |
| 474 | }); |
no test coverage detected