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-12-26 16:55:53 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use std::{marker::PhantomData, mem};
|
|
|
|
|
2021-04-27 15:15:46 +00:00
|
|
|
use glib::translate::IntoGlib;
|
2017-12-26 16:55:53 +00:00
|
|
|
|
2021-06-02 12:42:30 +00:00
|
|
|
#[repr(C)]
|
2018-01-03 15:36:44 +00:00
|
|
|
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
2017-12-26 16:55:53 +00:00
|
|
|
pub struct VideoRectangle {
|
|
|
|
pub x: i32,
|
|
|
|
pub y: i32,
|
|
|
|
pub w: i32,
|
|
|
|
pub h: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl VideoRectangle {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-12-26 16:55:53 +00:00
|
|
|
pub fn new(x: i32, y: i32, w: i32, h: i32) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2021-04-29 20:49:40 +00:00
|
|
|
Self { x, y, w, h }
|
2017-12-26 16:55:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-26 17:18:13 +00:00
|
|
|
pub fn center_video_rectangle(
|
2018-01-03 15:36:44 +00:00
|
|
|
src: &VideoRectangle,
|
|
|
|
dst: &VideoRectangle,
|
2017-12-26 17:18:13 +00:00
|
|
|
scale: bool,
|
|
|
|
) -> VideoRectangle {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2020-11-22 09:53:17 +00:00
|
|
|
let mut result = ffi::GstVideoRectangle {
|
2017-12-26 17:18:13 +00:00
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
w: 0,
|
|
|
|
h: 0,
|
|
|
|
};
|
2020-11-22 09:53:17 +00:00
|
|
|
let src_rect = ffi::GstVideoRectangle {
|
2017-12-26 17:18:13 +00:00
|
|
|
x: src.x,
|
|
|
|
y: src.y,
|
|
|
|
w: src.w,
|
|
|
|
h: src.h,
|
|
|
|
};
|
2020-11-22 09:53:17 +00:00
|
|
|
let dst_rect = ffi::GstVideoRectangle {
|
2017-12-26 17:18:13 +00:00
|
|
|
x: dst.x,
|
|
|
|
y: dst.y,
|
|
|
|
w: dst.w,
|
|
|
|
h: dst.h,
|
|
|
|
};
|
2017-12-26 16:55:53 +00:00
|
|
|
unsafe {
|
2021-04-27 15:15:46 +00:00
|
|
|
ffi::gst_video_sink_center_rect(src_rect, dst_rect, &mut result, scale.into_glib());
|
2017-12-26 16:55:53 +00:00
|
|
|
}
|
|
|
|
VideoRectangle::new(result.x, result.y, result.w, result.h)
|
|
|
|
}
|
2021-01-03 20:36:27 +00:00
|
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
impl glib::translate::Uninitialized for VideoRectangle {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-03 20:36:27 +00:00
|
|
|
unsafe fn uninitialized() -> Self {
|
|
|
|
mem::zeroed()
|
|
|
|
}
|
|
|
|
}
|
2021-01-03 21:42:01 +00:00
|
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
impl<'a> glib::translate::ToGlibPtrMut<'a, *mut ffi::GstVideoRectangle> for VideoRectangle {
|
2022-12-17 16:48:35 +00:00
|
|
|
type Storage = PhantomData<&'a mut Self>;
|
2021-01-03 21:42:01 +00:00
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-01-03 21:42:01 +00:00
|
|
|
fn to_glib_none_mut(
|
|
|
|
&'a mut self,
|
|
|
|
) -> glib::translate::StashMut<*mut ffi::GstVideoRectangle, Self> {
|
2022-12-17 16:48:35 +00:00
|
|
|
glib::translate::StashMut(self as *mut _ as *mut _, PhantomData)
|
2021-01-03 21:42:01 +00:00
|
|
|
}
|
|
|
|
}
|