2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2017-08-10 21:41:55 +00:00
|
|
|
|
2020-05-28 10:57:35 +00:00
|
|
|
use once_cell::sync::Lazy;
|
2017-08-10 21:41:55 +00:00
|
|
|
use std::ffi::CStr;
|
|
|
|
use std::str;
|
|
|
|
|
2021-04-27 15:15:46 +00:00
|
|
|
use glib::translate::{from_glib, FromGlib, IntoGlib};
|
2017-08-10 21:41:55 +00:00
|
|
|
|
2020-05-28 10:57:35 +00:00
|
|
|
#[cfg(feature = "v1_18")]
|
2020-11-22 09:53:17 +00:00
|
|
|
pub static VIDEO_FORMATS_ALL: Lazy<Box<[crate::VideoFormat]>> = Lazy::new(|| unsafe {
|
2020-05-28 10:57:35 +00:00
|
|
|
let mut len: u32 = 0;
|
|
|
|
let mut res = Vec::with_capacity(len as usize);
|
2020-11-22 09:53:17 +00:00
|
|
|
let formats = ffi::gst_video_formats_raw(&mut len);
|
2020-05-28 10:57:35 +00:00
|
|
|
for i in 0..len {
|
|
|
|
let format = formats.offset(i as isize);
|
|
|
|
res.push(from_glib(*format));
|
|
|
|
}
|
|
|
|
res.into_boxed_slice()
|
|
|
|
});
|
|
|
|
|
|
|
|
#[cfg(not(feature = "v1_18"))]
|
2020-11-22 09:53:17 +00:00
|
|
|
pub static VIDEO_FORMATS_ALL: Lazy<Box<[crate::VideoFormat]>> = Lazy::new(|| {
|
2020-06-05 10:22:08 +00:00
|
|
|
#[cfg(target_endian = "little")]
|
|
|
|
{
|
|
|
|
Box::new([
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Ayuv64,
|
|
|
|
crate::VideoFormat::Argb64,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Gbra12le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Gbra12be,
|
|
|
|
crate::VideoFormat::A44410le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Gbra10le,
|
|
|
|
crate::VideoFormat::A44410be,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Gbra10be,
|
|
|
|
crate::VideoFormat::A42210le,
|
|
|
|
crate::VideoFormat::A42210be,
|
|
|
|
crate::VideoFormat::A42010le,
|
|
|
|
crate::VideoFormat::A42010be,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_16")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Bgr10a2Le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_16")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Y410,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Gbra,
|
|
|
|
crate::VideoFormat::Abgr,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_16")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Vuya,
|
|
|
|
crate::VideoFormat::Bgra,
|
|
|
|
crate::VideoFormat::Ayuv,
|
|
|
|
crate::VideoFormat::Argb,
|
|
|
|
crate::VideoFormat::Rgba,
|
|
|
|
crate::VideoFormat::A420,
|
|
|
|
crate::VideoFormat::V216,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Y44412le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Gbr12le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Y44412be,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Gbr12be,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::I42212le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::I42212be,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::I42012le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::I42012be,
|
|
|
|
crate::VideoFormat::Y44410le,
|
|
|
|
crate::VideoFormat::Gbr10le,
|
|
|
|
crate::VideoFormat::Y44410be,
|
|
|
|
crate::VideoFormat::Gbr10be,
|
|
|
|
crate::VideoFormat::R210,
|
|
|
|
crate::VideoFormat::I42210le,
|
|
|
|
crate::VideoFormat::I42210be,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_14")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Nv1610le32,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_16")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Y210,
|
|
|
|
crate::VideoFormat::V210,
|
|
|
|
crate::VideoFormat::Uyvp,
|
|
|
|
crate::VideoFormat::I42010le,
|
|
|
|
crate::VideoFormat::I42010be,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_10")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::P01010le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_14")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Nv1210le32,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_16")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Nv1210le40,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_10")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::P01010be,
|
|
|
|
crate::VideoFormat::Y444,
|
|
|
|
crate::VideoFormat::Gbr,
|
|
|
|
crate::VideoFormat::Nv24,
|
|
|
|
crate::VideoFormat::Xbgr,
|
|
|
|
crate::VideoFormat::Bgrx,
|
|
|
|
crate::VideoFormat::Xrgb,
|
|
|
|
crate::VideoFormat::Rgbx,
|
|
|
|
crate::VideoFormat::Bgr,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_10")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Iyu2,
|
|
|
|
crate::VideoFormat::V308,
|
|
|
|
crate::VideoFormat::Rgb,
|
|
|
|
crate::VideoFormat::Y42b,
|
|
|
|
crate::VideoFormat::Nv61,
|
|
|
|
crate::VideoFormat::Nv16,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Vyuy,
|
|
|
|
crate::VideoFormat::Uyvy,
|
|
|
|
crate::VideoFormat::Yvyu,
|
|
|
|
crate::VideoFormat::Yuy2,
|
|
|
|
crate::VideoFormat::I420,
|
|
|
|
crate::VideoFormat::Yv12,
|
|
|
|
crate::VideoFormat::Nv21,
|
|
|
|
crate::VideoFormat::Nv12,
|
|
|
|
crate::VideoFormat::Nv1264z32,
|
|
|
|
crate::VideoFormat::Y41b,
|
|
|
|
crate::VideoFormat::Iyu1,
|
|
|
|
crate::VideoFormat::Yvu9,
|
|
|
|
crate::VideoFormat::Yuv9,
|
|
|
|
crate::VideoFormat::Rgb16,
|
|
|
|
crate::VideoFormat::Bgr16,
|
|
|
|
crate::VideoFormat::Rgb15,
|
|
|
|
crate::VideoFormat::Bgr15,
|
|
|
|
crate::VideoFormat::Rgb8p,
|
|
|
|
crate::VideoFormat::Gray16Le,
|
|
|
|
crate::VideoFormat::Gray16Be,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_14")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Gray10Le32,
|
|
|
|
crate::VideoFormat::Gray8,
|
2020-06-05 10:22:08 +00:00
|
|
|
])
|
|
|
|
}
|
|
|
|
#[cfg(target_endian = "big")]
|
|
|
|
{
|
|
|
|
Box::new([
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Ayuv64,
|
|
|
|
crate::VideoFormat::Argb64,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Gbra12be,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Gbra12le,
|
|
|
|
crate::VideoFormat::A44410be,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Gbra10be,
|
|
|
|
crate::VideoFormat::A44410le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Gbra10le,
|
|
|
|
crate::VideoFormat::A42210be,
|
|
|
|
crate::VideoFormat::A42210le,
|
|
|
|
crate::VideoFormat::A42010be,
|
|
|
|
crate::VideoFormat::A42010le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_16")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Y410,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_16")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Bgr10a2Le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Gbra,
|
|
|
|
crate::VideoFormat::Abgr,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_16")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Vuya,
|
|
|
|
crate::VideoFormat::Bgra,
|
|
|
|
crate::VideoFormat::Ayuv,
|
|
|
|
crate::VideoFormat::Argb,
|
|
|
|
crate::VideoFormat::Rgba,
|
|
|
|
crate::VideoFormat::A420,
|
|
|
|
crate::VideoFormat::V216,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Y44412be,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Gbr12be,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Y44412le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Gbr12le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::I42212be,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::I42212le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::I42012be,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::I42012le,
|
|
|
|
crate::VideoFormat::Y44410be,
|
|
|
|
crate::VideoFormat::Gbr10be,
|
|
|
|
crate::VideoFormat::Y44410le,
|
|
|
|
crate::VideoFormat::Gbr10le,
|
|
|
|
crate::VideoFormat::R210,
|
|
|
|
crate::VideoFormat::I42210be,
|
|
|
|
crate::VideoFormat::I42210le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_14")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Nv1610le32,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_16")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Y210,
|
|
|
|
crate::VideoFormat::V210,
|
|
|
|
crate::VideoFormat::Uyvp,
|
|
|
|
crate::VideoFormat::I42010be,
|
|
|
|
crate::VideoFormat::I42010le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_10")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::P01010be,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_10")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::P01010le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_14")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Nv1210le32,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_16")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Nv1210le40,
|
|
|
|
crate::VideoFormat::Y444,
|
|
|
|
crate::VideoFormat::Gbr,
|
|
|
|
crate::VideoFormat::Nv24,
|
|
|
|
crate::VideoFormat::Xbgr,
|
|
|
|
crate::VideoFormat::Bgrx,
|
|
|
|
crate::VideoFormat::Xrgb,
|
|
|
|
crate::VideoFormat::Rgbx,
|
|
|
|
crate::VideoFormat::Bgr,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_10")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Iyu2,
|
|
|
|
crate::VideoFormat::V308,
|
|
|
|
crate::VideoFormat::Rgb,
|
|
|
|
crate::VideoFormat::Y42b,
|
|
|
|
crate::VideoFormat::Nv61,
|
|
|
|
crate::VideoFormat::Nv16,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_12")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Vyuy,
|
|
|
|
crate::VideoFormat::Uyvy,
|
|
|
|
crate::VideoFormat::Yvyu,
|
|
|
|
crate::VideoFormat::Yuy2,
|
|
|
|
crate::VideoFormat::I420,
|
|
|
|
crate::VideoFormat::Yv12,
|
|
|
|
crate::VideoFormat::Nv21,
|
|
|
|
crate::VideoFormat::Nv12,
|
|
|
|
crate::VideoFormat::Nv1264z32,
|
|
|
|
crate::VideoFormat::Y41b,
|
|
|
|
crate::VideoFormat::Iyu1,
|
|
|
|
crate::VideoFormat::Yvu9,
|
|
|
|
crate::VideoFormat::Yuv9,
|
|
|
|
crate::VideoFormat::Rgb16,
|
|
|
|
crate::VideoFormat::Bgr16,
|
|
|
|
crate::VideoFormat::Rgb15,
|
|
|
|
crate::VideoFormat::Bgr15,
|
|
|
|
crate::VideoFormat::Rgb8p,
|
|
|
|
crate::VideoFormat::Gray16Be,
|
|
|
|
crate::VideoFormat::Gray16Le,
|
2020-06-24 12:02:16 +00:00
|
|
|
#[cfg(feature = "v1_14")]
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::Gray10Le32,
|
|
|
|
crate::VideoFormat::Gray8,
|
2020-06-05 10:22:08 +00:00
|
|
|
])
|
|
|
|
}
|
2020-05-28 10:57:35 +00:00
|
|
|
});
|
|
|
|
|
2017-11-26 21:50:39 +00:00
|
|
|
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)]
|
2017-08-10 21:41:55 +00:00
|
|
|
pub enum VideoEndianness {
|
|
|
|
Unknown,
|
|
|
|
LittleEndian = 1234,
|
|
|
|
BigEndian = 4321,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromGlib<i32> for VideoEndianness {
|
2020-12-08 14:07:12 +00:00
|
|
|
unsafe fn from_glib(value: i32) -> Self {
|
2017-08-30 09:48:01 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
|
2017-08-10 21:41:55 +00:00
|
|
|
match value {
|
|
|
|
1234 => VideoEndianness::LittleEndian,
|
|
|
|
4321 => VideoEndianness::BigEndian,
|
|
|
|
_ => VideoEndianness::Unknown,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-27 15:15:46 +00:00
|
|
|
impl IntoGlib for VideoEndianness {
|
2017-08-10 21:41:55 +00:00
|
|
|
type GlibType = i32;
|
|
|
|
|
2021-04-27 15:15:46 +00:00
|
|
|
fn into_glib(self) -> i32 {
|
|
|
|
match self {
|
2017-08-10 21:41:55 +00:00
|
|
|
VideoEndianness::LittleEndian => 1234,
|
|
|
|
VideoEndianness::BigEndian => 4321,
|
|
|
|
_ => 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
impl crate::VideoFormat {
|
2017-08-10 21:41:55 +00:00
|
|
|
pub fn from_masks(
|
|
|
|
depth: u32,
|
|
|
|
bpp: u32,
|
2020-11-22 09:53:17 +00:00
|
|
|
endianness: crate::VideoEndianness,
|
2017-08-10 21:41:55 +00:00
|
|
|
red_mask: u32,
|
|
|
|
blue_mask: u32,
|
|
|
|
green_mask: u32,
|
|
|
|
alpha_mask: u32,
|
2020-11-22 09:53:17 +00:00
|
|
|
) -> crate::VideoFormat {
|
2017-08-30 09:48:01 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
|
2017-08-10 21:41:55 +00:00
|
|
|
unsafe {
|
2020-11-22 09:53:17 +00:00
|
|
|
from_glib(ffi::gst_video_format_from_masks(
|
2017-08-10 21:41:55 +00:00
|
|
|
depth as i32,
|
|
|
|
bpp as i32,
|
2021-04-27 15:15:46 +00:00
|
|
|
endianness.into_glib(),
|
2017-08-10 21:41:55 +00:00
|
|
|
red_mask,
|
|
|
|
blue_mask,
|
|
|
|
green_mask,
|
|
|
|
alpha_mask,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-04 06:11:30 +00:00
|
|
|
pub fn to_str<'a>(self) -> &'a str {
|
2020-11-30 19:33:18 +00:00
|
|
|
if self == Self::Unknown {
|
2017-12-16 08:58:10 +00:00
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
2017-08-10 21:41:55 +00:00
|
|
|
unsafe {
|
2020-11-30 19:33:18 +00:00
|
|
|
CStr::from_ptr(
|
2021-04-27 15:15:46 +00:00
|
|
|
ffi::gst_video_format_to_string(self.into_glib())
|
2020-11-30 19:33:18 +00:00
|
|
|
.as_ref()
|
|
|
|
.expect("gst_video_format_to_string returned NULL"),
|
|
|
|
)
|
|
|
|
.to_str()
|
|
|
|
.expect("gst_video_format_to_string returned an invalid string")
|
2017-08-10 21:41:55 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-28 10:57:35 +00:00
|
|
|
|
|
|
|
pub fn iter_raw() -> VideoFormatIterator {
|
|
|
|
VideoFormatIterator::default()
|
|
|
|
}
|
2017-08-10 21:41:55 +00:00
|
|
|
}
|
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
impl str::FromStr for crate::VideoFormat {
|
2019-12-17 19:00:42 +00:00
|
|
|
type Err = glib::BoolError;
|
2017-08-10 21:41:55 +00:00
|
|
|
|
2020-11-28 11:34:36 +00:00
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
2020-11-15 15:49:07 +00:00
|
|
|
skip_assert_initialized!();
|
2017-08-30 09:48:01 +00:00
|
|
|
|
2020-11-15 15:49:07 +00:00
|
|
|
let fmt = Self::from_string(s);
|
|
|
|
if fmt == Self::Unknown {
|
2020-12-17 22:38:06 +00:00
|
|
|
Err(glib::bool_error!(
|
2020-11-15 15:49:07 +00:00
|
|
|
"Failed to parse video format from string"
|
|
|
|
))
|
|
|
|
} else {
|
|
|
|
Ok(fmt)
|
2017-08-10 21:41:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
impl PartialOrd for crate::VideoFormat {
|
|
|
|
fn partial_cmp(&self, other: &crate::VideoFormat) -> Option<std::cmp::Ordering> {
|
|
|
|
crate::VideoFormatInfo::from_format(*self)
|
|
|
|
.partial_cmp(&crate::VideoFormatInfo::from_format(*other))
|
2020-06-05 09:57:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
impl Ord for crate::VideoFormat {
|
|
|
|
fn cmp(&self, other: &crate::VideoFormat) -> std::cmp::Ordering {
|
|
|
|
crate::VideoFormatInfo::from_format(*self).cmp(&crate::VideoFormatInfo::from_format(*other))
|
2020-06-05 09:57:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-28 10:57:35 +00:00
|
|
|
pub struct VideoFormatIterator {
|
|
|
|
idx: usize,
|
|
|
|
len: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for VideoFormatIterator {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
idx: 0,
|
|
|
|
len: VIDEO_FORMATS_ALL.len(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Iterator for VideoFormatIterator {
|
2020-11-22 09:53:17 +00:00
|
|
|
type Item = crate::VideoFormat;
|
2020-05-28 10:57:35 +00:00
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
if self.idx >= self.len {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
let fmt = VIDEO_FORMATS_ALL[self.idx];
|
|
|
|
self.idx += 1;
|
|
|
|
Some(fmt)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-09 08:30:44 +00:00
|
|
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
|
|
if self.idx == self.len {
|
|
|
|
return (0, Some(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
let remaining = (self.len - self.idx) as usize;
|
|
|
|
|
|
|
|
(remaining, Some(remaining))
|
2020-05-28 10:57:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-09 08:30:44 +00:00
|
|
|
impl ExactSizeIterator for VideoFormatIterator {}
|
|
|
|
|
2020-05-28 10:57:35 +00:00
|
|
|
impl DoubleEndedIterator for VideoFormatIterator {
|
|
|
|
fn next_back(&mut self) -> Option<Self::Item> {
|
|
|
|
if self.idx >= self.len {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
let fmt = VIDEO_FORMATS_ALL[self.len - 1];
|
|
|
|
self.len -= 1;
|
|
|
|
Some(fmt)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub trait VideoFormatIteratorExt {
|
|
|
|
fn into_video_caps(self) -> Option<gst::caps::Builder<gst::caps::NoFeature>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> VideoFormatIteratorExt for T
|
|
|
|
where
|
2020-11-22 09:53:17 +00:00
|
|
|
T: Iterator<Item = crate::VideoFormat>,
|
2020-05-28 10:57:35 +00:00
|
|
|
{
|
|
|
|
fn into_video_caps(self) -> Option<gst::caps::Builder<gst::caps::NoFeature>> {
|
2020-11-22 09:53:17 +00:00
|
|
|
let formats: Vec<crate::VideoFormat> = self.collect();
|
2020-05-28 10:57:35 +00:00
|
|
|
if !formats.is_empty() {
|
2020-11-22 09:53:17 +00:00
|
|
|
Some(crate::functions::video_make_raw_caps(&formats))
|
2020-05-28 10:57:35 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait VideoFormatIteratorExtRef {
|
|
|
|
fn into_video_caps(self) -> Option<gst::caps::Builder<gst::caps::NoFeature>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T> VideoFormatIteratorExtRef for T
|
|
|
|
where
|
2020-11-22 09:53:17 +00:00
|
|
|
T: Iterator<Item = &'a crate::VideoFormat>,
|
2020-05-28 10:57:35 +00:00
|
|
|
{
|
|
|
|
fn into_video_caps(self) -> Option<gst::caps::Builder<gst::caps::NoFeature>> {
|
2020-11-22 09:53:17 +00:00
|
|
|
let formats: Vec<crate::VideoFormat> = self.copied().collect();
|
2020-05-28 10:57:35 +00:00
|
|
|
if !formats.is_empty() {
|
2020-11-22 09:53:17 +00:00
|
|
|
Some(crate::functions::video_make_raw_caps(&formats))
|
2020-05-28 10:57:35 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-18 10:15:33 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
2020-11-18 21:47:50 +00:00
|
|
|
#[test]
|
|
|
|
fn enum_to_string() {
|
|
|
|
gst::init().unwrap();
|
|
|
|
|
|
|
|
assert_eq!(&format!("{}", crate::VideoFormat::Argb), "ARGB");
|
|
|
|
assert_eq!(&format!("{:?}", crate::VideoFormat::Argb), "Argb");
|
|
|
|
assert_eq!(crate::VideoFormat::Argb.to_str(), "ARGB");
|
|
|
|
|
|
|
|
assert_eq!(&format!("{}", crate::VideoFormat::Unknown), "UNKNOWN");
|
|
|
|
assert_eq!(&format!("{:?}", crate::VideoFormat::Unknown), "Unknown");
|
|
|
|
assert_eq!(crate::VideoFormat::Unknown.to_str(), "UNKNOWN");
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
&format!("{:?}", crate::VideoFormat::__Unknown(-1)),
|
|
|
|
"__Unknown(-1)"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic]
|
|
|
|
fn enum_to_string_panics() {
|
|
|
|
assert_eq!(&format!("{}", crate::VideoFormat::__Unknown(-1)), "UNKNOWN");
|
|
|
|
assert_eq!(crate::VideoFormat::__Unknown(-1).to_str(), "UNKNOWN");
|
|
|
|
}
|
|
|
|
|
2019-06-18 10:15:33 +00:00
|
|
|
#[test]
|
|
|
|
fn test_display() {
|
|
|
|
gst::init().unwrap();
|
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
format!("{}", crate::VideoFormat::Nv16);
|
2017-08-10 21:41:55 +00:00
|
|
|
}
|
2020-05-28 10:57:35 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn iter() {
|
|
|
|
use super::*;
|
|
|
|
gst::init().unwrap();
|
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
assert!(crate::VideoFormat::iter_raw().count() > 0);
|
2020-05-28 10:57:35 +00:00
|
|
|
assert_eq!(
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::iter_raw().count(),
|
|
|
|
crate::VideoFormat::iter_raw().len()
|
2020-05-28 10:57:35 +00:00
|
|
|
);
|
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
let mut i = crate::VideoFormat::iter_raw();
|
2020-05-28 10:57:35 +00:00
|
|
|
let mut count = 0;
|
|
|
|
loop {
|
|
|
|
if i.next().is_none() {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count += 1;
|
|
|
|
if i.next_back().is_none() {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count += 1;
|
|
|
|
}
|
2020-11-22 09:53:17 +00:00
|
|
|
assert_eq!(count, crate::VideoFormat::iter_raw().len());
|
2020-05-28 10:57:35 +00:00
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
assert!(crate::VideoFormat::iter_raw().any(|f| f == crate::VideoFormat::Nv12));
|
|
|
|
assert!(crate::VideoFormat::iter_raw()
|
|
|
|
.find(|f| *f == crate::VideoFormat::Encoded)
|
2020-05-28 10:57:35 +00:00
|
|
|
.is_none());
|
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
let caps = crate::VideoFormat::iter_raw().into_video_caps();
|
2020-05-28 10:57:35 +00:00
|
|
|
assert!(caps.is_some());
|
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
let caps = crate::VideoFormat::iter_raw()
|
|
|
|
.filter(|f| crate::VideoFormatInfo::from_format(*f).is_gray())
|
2020-05-28 10:57:35 +00:00
|
|
|
.into_video_caps();
|
|
|
|
assert!(caps.is_some());
|
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
let caps = crate::VideoFormat::iter_raw().skip(1000).into_video_caps();
|
2020-05-28 10:57:35 +00:00
|
|
|
assert!(caps.is_none());
|
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
let caps = [crate::VideoFormat::Nv12, crate::VideoFormat::Nv16]
|
2020-05-28 10:57:35 +00:00
|
|
|
.iter()
|
|
|
|
.into_video_caps()
|
|
|
|
.unwrap()
|
|
|
|
.build();
|
|
|
|
assert_eq!(caps.to_string(), "video/x-raw, format=(string){ NV12, NV16 }, width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ], framerate=(fraction)[ 0/1, 2147483647/1 ]");
|
|
|
|
}
|
2020-06-05 09:57:29 +00:00
|
|
|
|
2020-06-24 07:58:47 +00:00
|
|
|
#[cfg(feature = "v1_18")]
|
2020-06-05 09:57:29 +00:00
|
|
|
#[test]
|
|
|
|
fn sort() {
|
2020-06-24 07:58:47 +00:00
|
|
|
use itertools::Itertools;
|
|
|
|
|
2020-06-05 09:57:29 +00:00
|
|
|
gst::init().unwrap();
|
|
|
|
|
|
|
|
assert!(
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormatInfo::from_format(crate::VideoFormat::Nv16)
|
|
|
|
> crate::VideoFormatInfo::from_format(crate::VideoFormat::Nv12)
|
2020-06-05 09:57:29 +00:00
|
|
|
);
|
2020-11-22 09:53:17 +00:00
|
|
|
assert!(crate::VideoFormat::I420 > crate::VideoFormat::Yv12);
|
2020-06-05 10:22:08 +00:00
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
let sorted: Vec<crate::VideoFormat> =
|
|
|
|
crate::VideoFormat::iter_raw().sorted().rev().collect();
|
2020-06-05 10:22:08 +00:00
|
|
|
// FIXME: use is_sorted_by() once API is in stable
|
|
|
|
assert_eq!(
|
|
|
|
sorted,
|
2020-11-22 09:53:17 +00:00
|
|
|
crate::VideoFormat::iter_raw().collect::<Vec<crate::VideoFormat>>()
|
2020-06-05 10:22:08 +00:00
|
|
|
);
|
2020-06-05 09:57:29 +00:00
|
|
|
}
|
2017-08-10 21:41:55 +00:00
|
|
|
}
|