2022-05-29 18:16:35 +08:00
|
|
|
pub use self::vpxcodec::*;
|
2023-03-31 16:10:52 +08:00
|
|
|
use hbb_common::message_proto::{video_frame, VideoFrame};
|
2021-03-29 15:59:14 +08:00
|
|
|
|
|
|
|
cfg_if! {
|
|
|
|
if #[cfg(quartz)] {
|
|
|
|
mod quartz;
|
|
|
|
pub use self::quartz::*;
|
|
|
|
} else if #[cfg(x11)] {
|
2021-07-23 17:52:38 +08:00
|
|
|
cfg_if! {
|
|
|
|
if #[cfg(feature="wayland")] {
|
|
|
|
mod linux;
|
|
|
|
mod wayland;
|
2021-03-29 15:59:14 +08:00
|
|
|
mod x11;
|
2021-07-23 17:52:38 +08:00
|
|
|
pub use self::linux::*;
|
2022-07-07 01:27:21 +08:00
|
|
|
pub use self::x11::Frame;
|
2023-01-29 10:58:04 +08:00
|
|
|
pub use self::wayland::set_map_err;
|
2021-07-23 17:52:38 +08:00
|
|
|
} else {
|
|
|
|
mod x11;
|
|
|
|
pub use self::x11::*;
|
|
|
|
}
|
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
} else if #[cfg(dxgi)] {
|
|
|
|
mod dxgi;
|
|
|
|
pub use self::dxgi::*;
|
2022-06-01 17:52:21 +08:00
|
|
|
} else if #[cfg(target_os = "android")] {
|
2022-05-12 17:35:25 +08:00
|
|
|
mod android;
|
|
|
|
pub use self::android::*;
|
|
|
|
}else {
|
2021-03-29 15:59:14 +08:00
|
|
|
//TODO: Fallback implementation.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub mod codec;
|
2023-03-03 22:43:02 +08:00
|
|
|
pub mod convert;
|
2022-05-29 17:23:14 +08:00
|
|
|
#[cfg(feature = "hwcodec")]
|
|
|
|
pub mod hwcodec;
|
2022-09-15 20:40:29 +08:00
|
|
|
#[cfg(feature = "mediacodec")]
|
|
|
|
pub mod mediacodec;
|
2022-05-29 18:16:35 +08:00
|
|
|
pub mod vpxcodec;
|
2021-03-29 15:59:14 +08:00
|
|
|
pub use self::convert::*;
|
2023-03-03 13:18:34 +08:00
|
|
|
pub const STRIDE_ALIGN: usize = 64; // commonly used in libvpx vpx_img_alloc caller
|
|
|
|
pub const HW_STRIDE_ALIGN: usize = 0; // recommended by av_frame_get_buffer
|
2021-03-29 15:59:14 +08:00
|
|
|
|
2022-09-15 17:31:28 +08:00
|
|
|
pub mod record;
|
2021-03-29 15:59:14 +08:00
|
|
|
mod vpx;
|
2022-04-24 02:50:28 +08:00
|
|
|
|
2023-02-21 23:46:13 +08:00
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub enum ImageFormat {
|
|
|
|
Raw,
|
|
|
|
ABGR,
|
|
|
|
ARGB,
|
|
|
|
}
|
|
|
|
|
2023-04-28 11:44:52 +08:00
|
|
|
pub struct ImageRgb {
|
|
|
|
pub raw: Vec<u8>,
|
|
|
|
pub w: usize,
|
|
|
|
pub h: usize,
|
2023-04-28 12:35:46 +08:00
|
|
|
fmt: ImageFormat,
|
|
|
|
stride: usize,
|
2023-04-28 11:44:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ImageRgb {
|
|
|
|
pub fn new(fmt: ImageFormat, stride: usize) -> Self {
|
|
|
|
Self {
|
|
|
|
raw: Vec::new(),
|
|
|
|
w: 0,
|
|
|
|
h: 0,
|
2023-04-28 12:35:46 +08:00
|
|
|
fmt,
|
2023-04-28 11:44:52 +08:00
|
|
|
stride,
|
|
|
|
}
|
|
|
|
}
|
2023-04-28 12:35:46 +08:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn fmt(&self) -> ImageFormat {
|
|
|
|
self.fmt
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn stride(&self) -> usize {
|
|
|
|
self.stride
|
|
|
|
}
|
2023-04-28 11:44:52 +08:00
|
|
|
}
|
|
|
|
|
2022-04-24 02:50:28 +08:00
|
|
|
#[inline]
|
2022-12-26 17:44:29 +08:00
|
|
|
pub fn would_block_if_equal(old: &mut Vec<u8>, b: &[u8]) -> std::io::Result<()> {
|
|
|
|
// does this really help?
|
2022-04-24 02:50:28 +08:00
|
|
|
if b == &old[..] {
|
|
|
|
return Err(std::io::ErrorKind::WouldBlock.into());
|
|
|
|
}
|
|
|
|
old.resize(b.len(), 0);
|
|
|
|
old.copy_from_slice(b);
|
|
|
|
Ok(())
|
2022-06-01 17:52:21 +08:00
|
|
|
}
|
2022-07-21 20:04:39 +08:00
|
|
|
|
|
|
|
pub trait TraitCapturer {
|
|
|
|
fn set_use_yuv(&mut self, use_yuv: bool);
|
2023-04-17 19:26:39 +08:00
|
|
|
|
|
|
|
// We doesn't support
|
|
|
|
#[cfg(not(any(target_os = "ios")))]
|
2022-07-21 20:04:39 +08:00
|
|
|
fn frame<'a>(&'a mut self, timeout: std::time::Duration) -> std::io::Result<Frame<'a>>;
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
fn is_gdi(&self) -> bool;
|
|
|
|
#[cfg(windows)]
|
|
|
|
fn set_gdi(&mut self) -> bool;
|
|
|
|
}
|
2022-07-27 06:34:27 -07:00
|
|
|
|
|
|
|
#[cfg(x11)]
|
|
|
|
#[inline]
|
|
|
|
pub fn is_x11() -> bool {
|
2023-03-31 16:42:35 +08:00
|
|
|
hbb_common::platform::linux::is_x11_or_headless()
|
2022-07-27 06:34:27 -07:00
|
|
|
}
|
2022-11-29 16:36:35 +08:00
|
|
|
|
|
|
|
#[cfg(x11)]
|
|
|
|
#[inline]
|
2022-12-31 21:41:16 +08:00
|
|
|
pub fn is_cursor_embedded() -> bool {
|
2022-11-29 16:36:35 +08:00
|
|
|
if is_x11() {
|
2023-01-05 14:58:38 +08:00
|
|
|
x11::IS_CURSOR_EMBEDDED
|
2022-11-29 16:36:35 +08:00
|
|
|
} else {
|
2023-01-29 10:58:04 +08:00
|
|
|
wayland::is_cursor_embedded()
|
2022-11-29 16:36:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(x11))]
|
|
|
|
#[inline]
|
2022-12-31 21:41:16 +08:00
|
|
|
pub fn is_cursor_embedded() -> bool {
|
2022-11-29 16:36:35 +08:00
|
|
|
false
|
|
|
|
}
|
2023-03-31 16:10:52 +08:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
pub enum CodecName {
|
|
|
|
VP8,
|
|
|
|
VP9,
|
|
|
|
H264(String),
|
|
|
|
H265(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug, Clone)]
|
|
|
|
pub enum CodecFormat {
|
|
|
|
VP8,
|
|
|
|
VP9,
|
|
|
|
H264,
|
|
|
|
H265,
|
|
|
|
Unknown,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<&VideoFrame> for CodecFormat {
|
|
|
|
fn from(it: &VideoFrame) -> Self {
|
|
|
|
match it.union {
|
|
|
|
Some(video_frame::Union::Vp8s(_)) => CodecFormat::VP8,
|
|
|
|
Some(video_frame::Union::Vp9s(_)) => CodecFormat::VP9,
|
|
|
|
Some(video_frame::Union::H264s(_)) => CodecFormat::H264,
|
|
|
|
Some(video_frame::Union::H265s(_)) => CodecFormat::H265,
|
|
|
|
_ => CodecFormat::Unknown,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<&CodecName> for CodecFormat {
|
|
|
|
fn from(value: &CodecName) -> Self {
|
|
|
|
match value {
|
|
|
|
CodecName::VP8 => Self::VP8,
|
|
|
|
CodecName::VP9 => Self::VP9,
|
|
|
|
CodecName::H264(_) => Self::H264,
|
|
|
|
CodecName::H265(_) => Self::H265,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToString for CodecFormat {
|
|
|
|
fn to_string(&self) -> String {
|
|
|
|
match self {
|
|
|
|
CodecFormat::VP8 => "VP8".into(),
|
|
|
|
CodecFormat::VP9 => "VP9".into(),
|
|
|
|
CodecFormat::H264 => "H264".into(),
|
|
|
|
CodecFormat::H265 => "H265".into(),
|
|
|
|
CodecFormat::Unknown => "Unknow".into(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|