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,
|
|
|
|
crate::VideoFormat::Gbra12le,
|
|
|
|
crate::VideoFormat::Gbra12be,
|
|
|
|
crate::VideoFormat::A44410le,
|
|
|
|
crate::VideoFormat::Gbra10le,
|
|
|
|
crate::VideoFormat::A44410be,
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
crate::VideoFormat::Y44412le,
|
|
|
|
crate::VideoFormat::Gbr12le,
|
|
|
|
crate::VideoFormat::Y44412be,
|
|
|
|
crate::VideoFormat::Gbr12be,
|
|
|
|
crate::VideoFormat::I42212le,
|
|
|
|
crate::VideoFormat::I42212be,
|
|
|
|
crate::VideoFormat::I42012le,
|
|
|
|
crate::VideoFormat::I42012be,
|
|
|
|
crate::VideoFormat::Y44410le,
|
|
|
|
crate::VideoFormat::Gbr10le,
|
|
|
|
crate::VideoFormat::Y44410be,
|
|
|
|
crate::VideoFormat::Gbr10be,
|
|
|
|
crate::VideoFormat::R210,
|
|
|
|
crate::VideoFormat::I42210le,
|
|
|
|
crate::VideoFormat::I42210be,
|
|
|
|
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,
|
|
|
|
crate::VideoFormat::P01010le,
|
|
|
|
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::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,
|
|
|
|
crate::VideoFormat::Iyu2,
|
|
|
|
crate::VideoFormat::V308,
|
|
|
|
crate::VideoFormat::Rgb,
|
|
|
|
crate::VideoFormat::Y42b,
|
|
|
|
crate::VideoFormat::Nv61,
|
|
|
|
crate::VideoFormat::Nv16,
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
crate::VideoFormat::Gbra12be,
|
|
|
|
crate::VideoFormat::Gbra12le,
|
|
|
|
crate::VideoFormat::A44410be,
|
|
|
|
crate::VideoFormat::Gbra10be,
|
|
|
|
crate::VideoFormat::A44410le,
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
crate::VideoFormat::Y44412be,
|
|
|
|
crate::VideoFormat::Gbr12be,
|
|
|
|
crate::VideoFormat::Y44412le,
|
|
|
|
crate::VideoFormat::Gbr12le,
|
|
|
|
crate::VideoFormat::I42212be,
|
|
|
|
crate::VideoFormat::I42212le,
|
|
|
|
crate::VideoFormat::I42012be,
|
|
|
|
crate::VideoFormat::I42012le,
|
|
|
|
crate::VideoFormat::Y44410be,
|
|
|
|
crate::VideoFormat::Gbr10be,
|
|
|
|
crate::VideoFormat::Y44410le,
|
|
|
|
crate::VideoFormat::Gbr10le,
|
|
|
|
crate::VideoFormat::R210,
|
|
|
|
crate::VideoFormat::I42210be,
|
|
|
|
crate::VideoFormat::I42210le,
|
|
|
|
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,
|
|
|
|
crate::VideoFormat::P01010be,
|
|
|
|
crate::VideoFormat::P01010le,
|
|
|
|
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,
|
|
|
|
crate::VideoFormat::Iyu2,
|
|
|
|
crate::VideoFormat::V308,
|
|
|
|
crate::VideoFormat::Rgb,
|
|
|
|
crate::VideoFormat::Y42b,
|
|
|
|
crate::VideoFormat::Nv61,
|
|
|
|
crate::VideoFormat::Nv16,
|
|
|
|
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,
|
|
|
|
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 {
|
2021-04-29 20:49:40 +00:00
|
|
|
1234 => Self::LittleEndian,
|
|
|
|
4321 => Self::BigEndian,
|
|
|
|
_ => Self::Unknown,
|
2017-08-10 21:41:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2021-04-29 20:49:40 +00:00
|
|
|
Self::LittleEndian => 1234,
|
|
|
|
Self::BigEndian => 4321,
|
2017-08-10 21:41:55 +00:00
|
|
|
_ => 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
impl crate::VideoFormat {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_video_format_from_masks")]
|
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,
|
2021-04-29 20:49:40 +00:00
|
|
|
) -> Self {
|
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,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_video_format_to_string")]
|
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 {
|
2021-04-29 20:49:40 +00:00
|
|
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
2020-11-22 09:53:17 +00:00
|
|
|
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 {
|
2021-04-29 20:49:40 +00:00
|
|
|
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
2020-11-22 09:53:17 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2022-12-13 09:28:00 +00:00
|
|
|
let remaining = self.len - self.idx;
|
2020-10-09 08:30:44 +00:00
|
|
|
|
|
|
|
(remaining, Some(remaining))
|
2020-05-28 10:57:35 +00:00
|
|
|
}
|
2022-05-20 13:58:46 +00:00
|
|
|
|
|
|
|
fn count(self) -> usize {
|
|
|
|
self.len - self.idx
|
|
|
|
}
|
|
|
|
|
|
|
|
fn nth(&mut self, n: usize) -> Option<Self::Item> {
|
|
|
|
let (end, overflow) = self.idx.overflowing_add(n);
|
|
|
|
if end >= self.len || overflow {
|
|
|
|
self.idx = self.len;
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
self.idx = end + 1;
|
|
|
|
Some(VIDEO_FORMATS_ALL[end])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn last(self) -> Option<Self::Item> {
|
|
|
|
if self.idx == self.len {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(VIDEO_FORMATS_ALL[self.len - 1])
|
|
|
|
}
|
|
|
|
}
|
2020-05-28 10:57:35 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 08:30:44 +00:00
|
|
|
impl ExactSizeIterator for VideoFormatIterator {}
|
|
|
|
|
2022-05-20 13:58:46 +00:00
|
|
|
impl std::iter::FusedIterator 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)
|
|
|
|
}
|
|
|
|
}
|
2022-05-20 13:58:46 +00:00
|
|
|
|
|
|
|
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
|
|
|
|
let (end, overflow) = self.len.overflowing_sub(n);
|
|
|
|
if end <= self.idx || overflow {
|
|
|
|
self.idx = self.len;
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
self.len = end - 1;
|
|
|
|
let fmt = VIDEO_FORMATS_ALL[self.len];
|
|
|
|
Some(fmt)
|
|
|
|
}
|
|
|
|
}
|
2020-05-28 10:57:35 +00:00
|
|
|
}
|
|
|
|
pub trait VideoFormatIteratorExt {
|
2022-10-14 10:19:49 +00:00
|
|
|
fn into_video_caps(self) -> Option<crate::VideoCapsBuilder<gst::caps::NoFeature>>;
|
2020-05-28 10:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2022-10-14 10:19:49 +00:00
|
|
|
fn into_video_caps(self) -> Option<crate::VideoCapsBuilder<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 {
|
2022-10-14 10:19:49 +00:00
|
|
|
fn into_video_caps(self) -> Option<crate::VideoCapsBuilder<gst::caps::NoFeature>>;
|
2020-05-28 10:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2022-10-14 10:19:49 +00:00
|
|
|
fn into_video_caps(self) -> Option<crate::VideoCapsBuilder<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]
|
2021-05-26 20:18:12 +00:00
|
|
|
#[should_panic(expected = "gst_video_format_to_string returned NULL")]
|
2020-11-18 21:47:50 +00:00
|
|
|
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));
|
2021-06-20 07:03:46 +00:00
|
|
|
assert!(!crate::VideoFormat::iter_raw().any(|f| f == crate::VideoFormat::Encoded));
|
2020-05-28 10:57:35 +00:00
|
|
|
|
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
|
|
|
}
|