video: Fix all clippy::use_self warnings

This commit is contained in:
Marijn Suijten 2021-04-29 22:49:40 +02:00
parent 66b60a0822
commit 28cf8434d0
10 changed files with 89 additions and 98 deletions

View file

@ -67,12 +67,12 @@ impl VideoAlignment {
stride_align: *stride_align, stride_align: *stride_align,
}; };
VideoAlignment(videoalignment) Self(videoalignment)
} }
} }
impl PartialEq for VideoAlignment { impl PartialEq for VideoAlignment {
fn eq(&self, other: &VideoAlignment) -> bool { fn eq(&self, other: &Self) -> bool {
self.padding_top() == other.padding_top() self.padding_top() == other.padding_top()
&& self.padding_bottom() == other.padding_bottom() && self.padding_bottom() == other.padding_bottom()
&& self.padding_left() == other.padding_left() && self.padding_left() == other.padding_left()

View file

@ -44,7 +44,7 @@ impl VideoConverter {
if ptr.is_null() { if ptr.is_null() {
Err(glib::bool_error!("Failed to create video converter")) Err(glib::bool_error!("Failed to create video converter"))
} else { } else {
Ok(VideoConverter(ptr::NonNull::new_unchecked(ptr))) Ok(Self(ptr::NonNull::new_unchecked(ptr)))
} }
} }
} }
@ -118,17 +118,17 @@ impl AsMut<gst::StructureRef> for VideoConverterConfig {
impl Default for VideoConverterConfig { impl Default for VideoConverterConfig {
fn default() -> Self { fn default() -> Self {
VideoConverterConfig::new() Self::new()
} }
} }
impl convert::TryFrom<gst::Structure> for VideoConverterConfig { impl convert::TryFrom<gst::Structure> for VideoConverterConfig {
type Error = glib::BoolError; type Error = glib::BoolError;
fn try_from(v: gst::Structure) -> Result<VideoConverterConfig, Self::Error> { fn try_from(v: gst::Structure) -> Result<Self, Self::Error> {
skip_assert_initialized!(); skip_assert_initialized!();
if v.name() == "GstVideoConverter" { if v.name() == "GstVideoConverter" {
Ok(VideoConverterConfig(v)) Ok(Self(v))
} else { } else {
Err(glib::bool_error!("Structure is no VideoConverterConfig")) Err(glib::bool_error!("Structure is no VideoConverterConfig"))
} }
@ -138,14 +138,14 @@ impl convert::TryFrom<gst::Structure> for VideoConverterConfig {
impl<'a> convert::TryFrom<&'a gst::StructureRef> for VideoConverterConfig { impl<'a> convert::TryFrom<&'a gst::StructureRef> for VideoConverterConfig {
type Error = glib::BoolError; type Error = glib::BoolError;
fn try_from(v: &'a gst::StructureRef) -> Result<VideoConverterConfig, Self::Error> { fn try_from(v: &'a gst::StructureRef) -> Result<Self, Self::Error> {
skip_assert_initialized!(); skip_assert_initialized!();
VideoConverterConfig::try_from(v.to_owned()) Self::try_from(v.to_owned())
} }
} }
impl From<VideoConverterConfig> for gst::Structure { impl From<VideoConverterConfig> for gst::Structure {
fn from(v: VideoConverterConfig) -> gst::Structure { fn from(v: VideoConverterConfig) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
v.0 v.0
} }
@ -153,7 +153,7 @@ impl From<VideoConverterConfig> for gst::Structure {
impl VideoConverterConfig { impl VideoConverterConfig {
pub fn new() -> Self { pub fn new() -> Self {
VideoConverterConfig(gst::Structure::new_empty("GstVideoConverter")) Self(gst::Structure::new_empty("GstVideoConverter"))
} }
pub fn set_resampler_method(&mut self, v: crate::VideoResamplerMethod) { pub fn set_resampler_method(&mut self, v: crate::VideoResamplerMethod) {

View file

@ -144,9 +144,7 @@ impl DownstreamForceKeyUnitEvent {
DownstreamForceKeyUnitEventBuilder::new() DownstreamForceKeyUnitEventBuilder::new()
} }
pub fn parse( pub fn parse(event: &gst::EventRef) -> Result<Self, glib::error::BoolError> {
event: &gst::EventRef,
) -> Result<DownstreamForceKeyUnitEvent, glib::error::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let mut timestamp = mem::MaybeUninit::uninit(); let mut timestamp = mem::MaybeUninit::uninit();
@ -164,7 +162,7 @@ impl DownstreamForceKeyUnitEvent {
count.as_mut_ptr(), count.as_mut_ptr(),
)); ));
if res { if res {
Ok(DownstreamForceKeyUnitEvent { Ok(Self {
timestamp: from_glib(timestamp.assume_init()), timestamp: from_glib(timestamp.assume_init()),
stream_time: from_glib(stream_time.assume_init()), stream_time: from_glib(stream_time.assume_init()),
running_time: from_glib(running_time.assume_init()), running_time: from_glib(running_time.assume_init()),
@ -239,9 +237,7 @@ impl UpstreamForceKeyUnitEvent {
UpstreamForceKeyUnitEventBuilder::new() UpstreamForceKeyUnitEventBuilder::new()
} }
pub fn parse( pub fn parse(event: &gst::EventRef) -> Result<Self, glib::error::BoolError> {
event: &gst::EventRef,
) -> Result<UpstreamForceKeyUnitEvent, glib::error::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let mut running_time = mem::MaybeUninit::uninit(); let mut running_time = mem::MaybeUninit::uninit();
@ -255,7 +251,7 @@ impl UpstreamForceKeyUnitEvent {
count.as_mut_ptr(), count.as_mut_ptr(),
)); ));
if res { if res {
Ok(UpstreamForceKeyUnitEvent { Ok(Self {
running_time: from_glib(running_time.assume_init()), running_time: from_glib(running_time.assume_init()),
all_headers: from_glib(all_headers.assume_init()), all_headers: from_glib(all_headers.assume_init()),
count: count.assume_init(), count: count.assume_init(),
@ -279,12 +275,12 @@ impl ForceKeyUnitEvent {
unsafe { from_glib(ffi::gst_video_event_is_force_key_unit(event.as_mut_ptr())) } unsafe { from_glib(ffi::gst_video_event_is_force_key_unit(event.as_mut_ptr())) }
} }
pub fn parse(event: &gst::EventRef) -> Result<ForceKeyUnitEvent, glib::error::BoolError> { pub fn parse(event: &gst::EventRef) -> Result<Self, glib::error::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
if event.is_upstream() { if event.is_upstream() {
UpstreamForceKeyUnitEvent::parse(event).map(ForceKeyUnitEvent::Upstream) UpstreamForceKeyUnitEvent::parse(event).map(Self::Upstream)
} else { } else {
DownstreamForceKeyUnitEvent::parse(event).map(ForceKeyUnitEvent::Downstream) DownstreamForceKeyUnitEvent::parse(event).map(Self::Downstream)
} }
} }
} }
@ -323,7 +319,7 @@ impl StillFrameEvent {
StillFrameEventBuilder::new(in_still) StillFrameEventBuilder::new(in_still)
} }
pub fn parse(event: &gst::EventRef) -> Result<StillFrameEvent, glib::error::BoolError> { pub fn parse(event: &gst::EventRef) -> Result<Self, glib::error::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let mut in_still = mem::MaybeUninit::uninit(); let mut in_still = mem::MaybeUninit::uninit();
@ -333,7 +329,7 @@ impl StillFrameEvent {
in_still.as_mut_ptr(), in_still.as_mut_ptr(),
)); ));
if res { if res {
Ok(StillFrameEvent { Ok(Self {
in_still: from_glib(in_still.assume_init()), in_still: from_glib(in_still.assume_init()),
}) })
} else { } else {

View file

@ -262,9 +262,9 @@ impl FromGlib<i32> for VideoEndianness {
skip_assert_initialized!(); skip_assert_initialized!();
match value { match value {
1234 => VideoEndianness::LittleEndian, 1234 => Self::LittleEndian,
4321 => VideoEndianness::BigEndian, 4321 => Self::BigEndian,
_ => VideoEndianness::Unknown, _ => Self::Unknown,
} }
} }
} }
@ -274,8 +274,8 @@ impl IntoGlib for VideoEndianness {
fn into_glib(self) -> i32 { fn into_glib(self) -> i32 {
match self { match self {
VideoEndianness::LittleEndian => 1234, Self::LittleEndian => 1234,
VideoEndianness::BigEndian => 4321, Self::BigEndian => 4321,
_ => 0, _ => 0,
} }
} }
@ -290,7 +290,7 @@ impl crate::VideoFormat {
blue_mask: u32, blue_mask: u32,
green_mask: u32, green_mask: u32,
alpha_mask: u32, alpha_mask: u32,
) -> crate::VideoFormat { ) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
@ -344,14 +344,14 @@ impl str::FromStr for crate::VideoFormat {
} }
impl PartialOrd for crate::VideoFormat { impl PartialOrd for crate::VideoFormat {
fn partial_cmp(&self, other: &crate::VideoFormat) -> Option<std::cmp::Ordering> { fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
crate::VideoFormatInfo::from_format(*self) crate::VideoFormatInfo::from_format(*self)
.partial_cmp(&crate::VideoFormatInfo::from_format(*other)) .partial_cmp(&crate::VideoFormatInfo::from_format(*other))
} }
} }
impl Ord for crate::VideoFormat { impl Ord for crate::VideoFormat {
fn cmp(&self, other: &crate::VideoFormat) -> std::cmp::Ordering { fn cmp(&self, other: &Self) -> std::cmp::Ordering {
crate::VideoFormatInfo::from_format(*self).cmp(&crate::VideoFormatInfo::from_format(*other)) crate::VideoFormatInfo::from_format(*self).cmp(&crate::VideoFormatInfo::from_format(*other))
} }
} }

View file

@ -10,14 +10,14 @@ use glib::translate::{from_glib, IntoGlib};
pub struct VideoFormatInfo(&'static ffi::GstVideoFormatInfo); pub struct VideoFormatInfo(&'static ffi::GstVideoFormatInfo);
impl VideoFormatInfo { impl VideoFormatInfo {
pub fn from_format(format: crate::VideoFormat) -> VideoFormatInfo { pub fn from_format(format: crate::VideoFormat) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let info = ffi::gst_video_format_get_info(format.into_glib()); let info = ffi::gst_video_format_get_info(format.into_glib());
assert!(!info.is_null()); assert!(!info.is_null());
VideoFormatInfo(&*info) Self(&*info)
} }
} }
@ -302,14 +302,14 @@ impl PartialEq for VideoFormatInfo {
impl Eq for VideoFormatInfo {} impl Eq for VideoFormatInfo {}
impl PartialOrd for VideoFormatInfo { impl PartialOrd for VideoFormatInfo {
fn partial_cmp(&self, other: &VideoFormatInfo) -> Option<Ordering> { fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other)) Some(self.cmp(other))
} }
} }
impl Ord for VideoFormatInfo { impl Ord for VideoFormatInfo {
// See GST_VIDEO_FORMATS_ALL for the sorting algorithm // See GST_VIDEO_FORMATS_ALL for the sorting algorithm
fn cmp(&self, other: &VideoFormatInfo) -> Ordering { fn cmp(&self, other: &Self) -> Ordering {
self.n_components() self.n_components()
.cmp(&other.n_components()) .cmp(&other.n_components())
.then_with(|| self.depth().cmp(&other.depth())) .then_with(|| self.depth().cmp(&other.depth()))
@ -446,7 +446,7 @@ impl glib::translate::GlibPtrDefault for VideoFormatInfo {
#[doc(hidden)] #[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstVideoFormatInfo> for VideoFormatInfo { impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstVideoFormatInfo> for VideoFormatInfo {
type Storage = &'a VideoFormatInfo; type Storage = &'a Self;
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstVideoFormatInfo, Self> { fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstVideoFormatInfo, Self> {
glib::translate::Stash(self.0, self) glib::translate::Stash(self.0, self)
@ -461,7 +461,7 @@ impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstVideoFormatInfo> for Vide
impl glib::translate::FromGlibPtrNone<*mut ffi::GstVideoFormatInfo> for VideoFormatInfo { impl glib::translate::FromGlibPtrNone<*mut ffi::GstVideoFormatInfo> for VideoFormatInfo {
#[inline] #[inline]
unsafe fn from_glib_none(ptr: *mut ffi::GstVideoFormatInfo) -> Self { unsafe fn from_glib_none(ptr: *mut ffi::GstVideoFormatInfo) -> Self {
VideoFormatInfo(&*ptr) Self(&*ptr)
} }
} }
@ -469,7 +469,7 @@ impl glib::translate::FromGlibPtrNone<*mut ffi::GstVideoFormatInfo> for VideoFor
impl glib::translate::FromGlibPtrNone<*const ffi::GstVideoFormatInfo> for VideoFormatInfo { impl glib::translate::FromGlibPtrNone<*const ffi::GstVideoFormatInfo> for VideoFormatInfo {
#[inline] #[inline]
unsafe fn from_glib_none(ptr: *const ffi::GstVideoFormatInfo) -> Self { unsafe fn from_glib_none(ptr: *const ffi::GstVideoFormatInfo) -> Self {
VideoFormatInfo(&*ptr) Self(&*ptr)
} }
} }

View file

@ -173,7 +173,7 @@ impl<T> VideoFrame<T> {
pub unsafe fn from_glib_full(frame: ffi::GstVideoFrame) -> Self { pub unsafe fn from_glib_full(frame: ffi::GstVideoFrame) -> Self {
let info = crate::VideoInfo(ptr::read(&frame.info)); let info = crate::VideoInfo(ptr::read(&frame.info));
let buffer = gst::Buffer::from_glib_none(frame.buffer); let buffer = gst::Buffer::from_glib_none(frame.buffer);
VideoFrame { Self {
frame, frame,
buffer: Some(buffer), buffer: Some(buffer),
info, info,
@ -209,7 +209,7 @@ impl VideoFrame<Readable> {
pub fn from_buffer_readable( pub fn from_buffer_readable(
buffer: gst::Buffer, buffer: gst::Buffer,
info: &crate::VideoInfo, info: &crate::VideoInfo,
) -> Result<VideoFrame<Readable>, gst::Buffer> { ) -> Result<Self, gst::Buffer> {
skip_assert_initialized!(); skip_assert_initialized!();
assert!(info.is_valid()); assert!(info.is_valid());
@ -228,7 +228,7 @@ impl VideoFrame<Readable> {
} else { } else {
let frame = frame.assume_init(); let frame = frame.assume_init();
let info = crate::VideoInfo(ptr::read(&frame.info)); let info = crate::VideoInfo(ptr::read(&frame.info));
Ok(VideoFrame { Ok(Self {
frame, frame,
buffer: Some(buffer), buffer: Some(buffer),
info, info,
@ -242,7 +242,7 @@ impl VideoFrame<Readable> {
buffer: gst::Buffer, buffer: gst::Buffer,
id: i32, id: i32,
info: &crate::VideoInfo, info: &crate::VideoInfo,
) -> Result<VideoFrame<Readable>, gst::Buffer> { ) -> Result<Self, gst::Buffer> {
skip_assert_initialized!(); skip_assert_initialized!();
assert!(info.is_valid()); assert!(info.is_valid());
@ -262,7 +262,7 @@ impl VideoFrame<Readable> {
} else { } else {
let frame = frame.assume_init(); let frame = frame.assume_init();
let info = crate::VideoInfo(ptr::read(&frame.info)); let info = crate::VideoInfo(ptr::read(&frame.info));
Ok(VideoFrame { Ok(Self {
frame, frame,
buffer: Some(buffer), buffer: Some(buffer),
info, info,
@ -281,7 +281,7 @@ impl VideoFrame<Writable> {
pub fn from_buffer_writable( pub fn from_buffer_writable(
buffer: gst::Buffer, buffer: gst::Buffer,
info: &crate::VideoInfo, info: &crate::VideoInfo,
) -> Result<VideoFrame<Writable>, gst::Buffer> { ) -> Result<Self, gst::Buffer> {
skip_assert_initialized!(); skip_assert_initialized!();
assert!(info.is_valid()); assert!(info.is_valid());
@ -302,7 +302,7 @@ impl VideoFrame<Writable> {
} else { } else {
let frame = frame.assume_init(); let frame = frame.assume_init();
let info = crate::VideoInfo(ptr::read(&frame.info)); let info = crate::VideoInfo(ptr::read(&frame.info));
Ok(VideoFrame { Ok(Self {
frame, frame,
buffer: Some(buffer), buffer: Some(buffer),
info, info,
@ -316,7 +316,7 @@ impl VideoFrame<Writable> {
buffer: gst::Buffer, buffer: gst::Buffer,
id: i32, id: i32,
info: &crate::VideoInfo, info: &crate::VideoInfo,
) -> Result<VideoFrame<Writable>, gst::Buffer> { ) -> Result<Self, gst::Buffer> {
skip_assert_initialized!(); skip_assert_initialized!();
assert!(info.is_valid()); assert!(info.is_valid());
@ -338,7 +338,7 @@ impl VideoFrame<Writable> {
} else { } else {
let frame = frame.assume_init(); let frame = frame.assume_init();
let info = crate::VideoInfo(ptr::read(&frame.info)); let info = crate::VideoInfo(ptr::read(&frame.info));
Ok(VideoFrame { Ok(Self {
frame, frame,
buffer: Some(buffer), buffer: Some(buffer),
info, info,
@ -552,7 +552,7 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> {
let frame = ptr::read(frame); let frame = ptr::read(frame);
let info = crate::VideoInfo(ptr::read(&frame.info)); let info = crate::VideoInfo(ptr::read(&frame.info));
let buffer = gst::BufferRef::from_ptr(frame.buffer); let buffer = gst::BufferRef::from_ptr(frame.buffer);
Borrowed::new(VideoFrameRef { Borrowed::new(Self {
frame, frame,
buffer: Some(buffer), buffer: Some(buffer),
info, info,
@ -563,7 +563,7 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> {
pub unsafe fn from_glib_full(frame: ffi::GstVideoFrame) -> Self { pub unsafe fn from_glib_full(frame: ffi::GstVideoFrame) -> Self {
let info = crate::VideoInfo(ptr::read(&frame.info)); let info = crate::VideoInfo(ptr::read(&frame.info));
let buffer = gst::BufferRef::from_ptr(frame.buffer); let buffer = gst::BufferRef::from_ptr(frame.buffer);
VideoFrameRef { Self {
frame, frame,
buffer: Some(buffer), buffer: Some(buffer),
info, info,
@ -574,7 +574,7 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> {
pub fn from_buffer_ref_readable<'b>( pub fn from_buffer_ref_readable<'b>(
buffer: &'a gst::BufferRef, buffer: &'a gst::BufferRef,
info: &'b crate::VideoInfo, info: &'b crate::VideoInfo,
) -> Result<VideoFrameRef<&'a gst::BufferRef>, glib::BoolError> { ) -> Result<Self, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
assert!(info.is_valid()); assert!(info.is_valid());
@ -593,7 +593,7 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> {
} else { } else {
let frame = frame.assume_init(); let frame = frame.assume_init();
let info = crate::VideoInfo(ptr::read(&frame.info)); let info = crate::VideoInfo(ptr::read(&frame.info));
Ok(VideoFrameRef { Ok(Self {
frame, frame,
buffer: Some(buffer), buffer: Some(buffer),
info, info,
@ -607,7 +607,7 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> {
buffer: &'a gst::BufferRef, buffer: &'a gst::BufferRef,
id: i32, id: i32,
info: &'b crate::VideoInfo, info: &'b crate::VideoInfo,
) -> Result<VideoFrameRef<&'a gst::BufferRef>, glib::BoolError> { ) -> Result<Self, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
assert!(info.is_valid()); assert!(info.is_valid());
@ -627,7 +627,7 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> {
} else { } else {
let frame = frame.assume_init(); let frame = frame.assume_init();
let info = crate::VideoInfo(ptr::read(&frame.info)); let info = crate::VideoInfo(ptr::read(&frame.info));
Ok(VideoFrameRef { Ok(Self {
frame, frame,
buffer: Some(buffer), buffer: Some(buffer),
info, info,
@ -649,7 +649,7 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> {
let frame = ptr::read(frame); let frame = ptr::read(frame);
let info = crate::VideoInfo(ptr::read(&frame.info)); let info = crate::VideoInfo(ptr::read(&frame.info));
let buffer = gst::BufferRef::from_mut_ptr(frame.buffer); let buffer = gst::BufferRef::from_mut_ptr(frame.buffer);
Borrowed::new(VideoFrameRef { Borrowed::new(Self {
frame, frame,
buffer: Some(buffer), buffer: Some(buffer),
info, info,
@ -660,7 +660,7 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> {
pub unsafe fn from_glib_full_mut(frame: ffi::GstVideoFrame) -> Self { pub unsafe fn from_glib_full_mut(frame: ffi::GstVideoFrame) -> Self {
let info = crate::VideoInfo(ptr::read(&frame.info)); let info = crate::VideoInfo(ptr::read(&frame.info));
let buffer = gst::BufferRef::from_mut_ptr(frame.buffer); let buffer = gst::BufferRef::from_mut_ptr(frame.buffer);
VideoFrameRef { Self {
frame, frame,
buffer: Some(buffer), buffer: Some(buffer),
info, info,
@ -671,7 +671,7 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> {
pub fn from_buffer_ref_writable<'b>( pub fn from_buffer_ref_writable<'b>(
buffer: &'a mut gst::BufferRef, buffer: &'a mut gst::BufferRef,
info: &'b crate::VideoInfo, info: &'b crate::VideoInfo,
) -> Result<VideoFrameRef<&'a mut gst::BufferRef>, glib::BoolError> { ) -> Result<Self, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
assert!(info.is_valid()); assert!(info.is_valid());
@ -692,7 +692,7 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> {
} else { } else {
let frame = frame.assume_init(); let frame = frame.assume_init();
let info = crate::VideoInfo(ptr::read(&frame.info)); let info = crate::VideoInfo(ptr::read(&frame.info));
Ok(VideoFrameRef { Ok(Self {
frame, frame,
buffer: Some(buffer), buffer: Some(buffer),
info, info,
@ -706,7 +706,7 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> {
buffer: &'a mut gst::BufferRef, buffer: &'a mut gst::BufferRef,
id: i32, id: i32,
info: &'b crate::VideoInfo, info: &'b crate::VideoInfo,
) -> Result<VideoFrameRef<&'a mut gst::BufferRef>, glib::BoolError> { ) -> Result<Self, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
assert!(info.is_valid()); assert!(info.is_valid());
@ -728,7 +728,7 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> {
} else { } else {
let frame = frame.assume_init(); let frame = frame.assume_init();
let info = crate::VideoInfo(ptr::read(&frame.info)); let info = crate::VideoInfo(ptr::read(&frame.info));
Ok(VideoFrameRef { Ok(Self {
frame, frame,
buffer: Some(buffer), buffer: Some(buffer),
info, info,
@ -783,10 +783,7 @@ impl<'a> ops::Deref for VideoFrameRef<&'a mut gst::BufferRef> {
type Target = VideoFrameRef<&'a gst::BufferRef>; type Target = VideoFrameRef<&'a gst::BufferRef>;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
unsafe { unsafe { &*(self as *const Self as *const Self::Target) }
&*(self as *const VideoFrameRef<&'a mut gst::BufferRef>
as *const VideoFrameRef<&'a gst::BufferRef>)
}
} }
} }

View file

@ -28,10 +28,10 @@ impl IntoGlib for VideoColorRange {
fn into_glib(self) -> ffi::GstVideoColorRange { fn into_glib(self) -> ffi::GstVideoColorRange {
match self { match self {
VideoColorRange::Unknown => ffi::GST_VIDEO_COLOR_RANGE_UNKNOWN, Self::Unknown => ffi::GST_VIDEO_COLOR_RANGE_UNKNOWN,
VideoColorRange::Range0255 => ffi::GST_VIDEO_COLOR_RANGE_0_255, Self::Range0255 => ffi::GST_VIDEO_COLOR_RANGE_0_255,
VideoColorRange::Range16235 => ffi::GST_VIDEO_COLOR_RANGE_16_235, Self::Range16235 => ffi::GST_VIDEO_COLOR_RANGE_16_235,
VideoColorRange::__Unknown(value) => value, Self::__Unknown(value) => value,
} }
} }
} }
@ -41,10 +41,10 @@ impl FromGlib<ffi::GstVideoColorRange> for VideoColorRange {
unsafe fn from_glib(value: ffi::GstVideoColorRange) -> Self { unsafe fn from_glib(value: ffi::GstVideoColorRange) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
match value as i32 { match value as i32 {
0 => VideoColorRange::Unknown, 0 => Self::Unknown,
1 => VideoColorRange::Range0255, 1 => Self::Range0255,
2 => VideoColorRange::Range16235, 2 => Self::Range16235,
value => VideoColorRange::__Unknown(value), value => Self::__Unknown(value),
} }
} }
} }
@ -98,7 +98,7 @@ impl VideoColorimetry {
primaries: primaries.into_glib(), primaries: primaries.into_glib(),
}; };
VideoColorimetry(colorimetry) Self(colorimetry)
} }
pub fn range(&self) -> crate::VideoColorRange { pub fn range(&self) -> crate::VideoColorRange {
@ -120,7 +120,7 @@ impl VideoColorimetry {
impl Clone for VideoColorimetry { impl Clone for VideoColorimetry {
fn clone(&self) -> Self { fn clone(&self) -> Self {
unsafe { VideoColorimetry(ptr::read(&self.0)) } unsafe { Self(ptr::read(&self.0)) }
} }
} }
@ -228,14 +228,12 @@ impl From<crate::VideoMultiviewFramePacking> for crate::VideoMultiviewMode {
impl std::convert::TryFrom<crate::VideoMultiviewMode> for crate::VideoMultiviewFramePacking { impl std::convert::TryFrom<crate::VideoMultiviewMode> for crate::VideoMultiviewFramePacking {
type Error = glib::BoolError; type Error = glib::BoolError;
fn try_from( fn try_from(v: crate::VideoMultiviewMode) -> Result<Self, glib::BoolError> {
v: crate::VideoMultiviewMode,
) -> Result<crate::VideoMultiviewFramePacking, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
let v2 = unsafe { from_glib(v.into_glib()) }; let v2 = unsafe { from_glib(v.into_glib()) };
if let crate::VideoMultiviewFramePacking::__Unknown(_) = v2 { if let Self::__Unknown(_) = v2 {
Err(glib::bool_error!("Invalid frame packing mode")) Err(glib::bool_error!("Invalid frame packing mode"))
} else { } else {
Ok(v2) Ok(v2)
@ -607,7 +605,7 @@ impl VideoInfo {
info.as_mut_ptr(), info.as_mut_ptr(),
caps.as_ptr(), caps.as_ptr(),
)) { )) {
Ok(VideoInfo(info.assume_init())) Ok(Self(info.assume_init()))
} else { } else {
Err(glib::bool_error!("Failed to create VideoInfo from caps")) Err(glib::bool_error!("Failed to create VideoInfo from caps"))
} }
@ -844,7 +842,7 @@ impl VideoInfo {
impl Clone for VideoInfo { impl Clone for VideoInfo {
fn clone(&self) -> Self { fn clone(&self) -> Self {
unsafe { VideoInfo(ptr::read(&self.0)) } unsafe { Self(ptr::read(&self.0)) }
} }
} }
@ -928,7 +926,7 @@ impl glib::translate::GlibPtrDefault for VideoInfo {
#[doc(hidden)] #[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstVideoInfo> for VideoInfo { impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstVideoInfo> for VideoInfo {
type Storage = &'a VideoInfo; type Storage = &'a Self;
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstVideoInfo, Self> { fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstVideoInfo, Self> {
glib::translate::Stash(&self.0, self) glib::translate::Stash(&self.0, self)
@ -943,7 +941,7 @@ impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstVideoInfo> for VideoInfo
impl glib::translate::FromGlibPtrNone<*mut ffi::GstVideoInfo> for VideoInfo { impl glib::translate::FromGlibPtrNone<*mut ffi::GstVideoInfo> for VideoInfo {
#[inline] #[inline]
unsafe fn from_glib_none(ptr: *mut ffi::GstVideoInfo) -> Self { unsafe fn from_glib_none(ptr: *mut ffi::GstVideoInfo) -> Self {
VideoInfo(ptr::read(ptr)) Self(ptr::read(ptr))
} }
} }

View file

@ -13,7 +13,7 @@ pub struct VideoRectangle {
impl VideoRectangle { impl VideoRectangle {
pub fn new(x: i32, y: i32, w: i32, h: i32) -> Self { pub fn new(x: i32, y: i32, w: i32, h: i32) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
VideoRectangle { x, y, w, h } Self { x, y, w, h }
} }
} }

View file

@ -20,12 +20,12 @@ pub struct VideoTimeCode(ffi::GstVideoTimeCode);
pub struct ValidVideoTimeCode(ffi::GstVideoTimeCode); pub struct ValidVideoTimeCode(ffi::GstVideoTimeCode);
impl VideoTimeCode { impl VideoTimeCode {
pub fn new_empty() -> VideoTimeCode { pub fn new_empty() -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let mut v = mem::MaybeUninit::zeroed(); let mut v = mem::MaybeUninit::zeroed();
ffi::gst_video_time_code_clear(v.as_mut_ptr()); ffi::gst_video_time_code_clear(v.as_mut_ptr());
VideoTimeCode(v.assume_init()) Self(v.assume_init())
} }
} }
@ -56,7 +56,7 @@ impl VideoTimeCode {
field_count, field_count,
); );
VideoTimeCode(v.assume_init()) Self(v.assume_init())
} }
} }
@ -67,7 +67,7 @@ impl VideoTimeCode {
dt: &glib::DateTime, dt: &glib::DateTime,
flags: VideoTimeCodeFlags, flags: VideoTimeCodeFlags,
field_count: u32, field_count: u32,
) -> Result<VideoTimeCode, glib::error::BoolError> { ) -> Result<Self, glib::error::BoolError> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
assert!(*fps.denom() > 0); assert!(*fps.denom() > 0);
unsafe { unsafe {
@ -84,7 +84,7 @@ impl VideoTimeCode {
if res == glib::ffi::GFALSE { if res == glib::ffi::GFALSE {
Err(glib::bool_error!("Failed to init video time code")) Err(glib::bool_error!("Failed to init video time code"))
} else { } else {
Ok(VideoTimeCode(v.assume_init())) Ok(Self(v.assume_init()))
} }
} }
} }
@ -129,14 +129,14 @@ impl VideoTimeCode {
impl TryFrom<VideoTimeCode> for ValidVideoTimeCode { impl TryFrom<VideoTimeCode> for ValidVideoTimeCode {
type Error = VideoTimeCode; type Error = VideoTimeCode;
fn try_from(v: VideoTimeCode) -> Result<ValidVideoTimeCode, VideoTimeCode> { fn try_from(v: VideoTimeCode) -> Result<Self, VideoTimeCode> {
skip_assert_initialized!(); skip_assert_initialized!();
if v.is_valid() { if v.is_valid() {
// Use ManuallyDrop here to prevent the Drop impl of VideoTimeCode // Use ManuallyDrop here to prevent the Drop impl of VideoTimeCode
// from running as we don't move v.0 out here but copy it. // from running as we don't move v.0 out here but copy it.
// GstVideoTimeCode implements Copy. // GstVideoTimeCode implements Copy.
let v = mem::ManuallyDrop::new(v); let v = mem::ManuallyDrop::new(v);
Ok(ValidVideoTimeCode(v.0)) Ok(Self(v.0))
} else { } else {
Err(v) Err(v)
} }
@ -195,7 +195,7 @@ impl ValidVideoTimeCode {
pub fn add_interval( pub fn add_interval(
&self, &self,
tc_inter: &VideoTimeCodeInterval, tc_inter: &VideoTimeCodeInterval,
) -> Result<ValidVideoTimeCode, glib::error::BoolError> { ) -> Result<Self, glib::error::BoolError> {
unsafe { unsafe {
match from_glib_full(ffi::gst_video_time_code_add_interval( match from_glib_full(ffi::gst_video_time_code_add_interval(
self.to_glib_none().0, self.to_glib_none().0,
@ -207,7 +207,7 @@ impl ValidVideoTimeCode {
} }
} }
fn compare(&self, tc2: &ValidVideoTimeCode) -> i32 { fn compare(&self, tc2: &Self) -> i32 {
unsafe { ffi::gst_video_time_code_compare(self.to_glib_none().0, tc2.to_glib_none().0) } unsafe { ffi::gst_video_time_code_compare(self.to_glib_none().0, tc2.to_glib_none().0) }
} }
@ -520,13 +520,13 @@ impl Ord for ValidVideoTimeCode {
} }
impl From<ValidVideoTimeCode> for VideoTimeCode { impl From<ValidVideoTimeCode> for VideoTimeCode {
fn from(v: ValidVideoTimeCode) -> VideoTimeCode { fn from(v: ValidVideoTimeCode) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
// Use ManuallyDrop here to prevent the Drop impl of VideoTimeCode // Use ManuallyDrop here to prevent the Drop impl of VideoTimeCode
// from running as we don't move v.0 out here but copy it. // from running as we don't move v.0 out here but copy it.
// GstVideoTimeCode implements Copy. // GstVideoTimeCode implements Copy.
let v = mem::ManuallyDrop::new(v); let v = mem::ManuallyDrop::new(v);
VideoTimeCode(v.0) Self(v.0)
} }
} }

View file

@ -17,7 +17,7 @@ impl VideoTimeCodeInterval {
unsafe { unsafe {
let mut v = mem::MaybeUninit::zeroed(); let mut v = mem::MaybeUninit::zeroed();
ffi::gst_video_time_code_interval_init(v.as_mut_ptr(), hours, minutes, seconds, frames); ffi::gst_video_time_code_interval_init(v.as_mut_ptr(), hours, minutes, seconds, frames);
VideoTimeCodeInterval(v.assume_init()) Self(v.assume_init())
} }
} }
@ -160,7 +160,7 @@ impl FromGlibPtrNone<*mut ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterv
#[inline] #[inline]
unsafe fn from_glib_none(ptr: *mut ffi::GstVideoTimeCodeInterval) -> Self { unsafe fn from_glib_none(ptr: *mut ffi::GstVideoTimeCodeInterval) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
VideoTimeCodeInterval(ptr::read(ptr)) Self(ptr::read(ptr))
} }
} }
@ -169,7 +169,7 @@ impl FromGlibPtrNone<*const ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInte
#[inline] #[inline]
unsafe fn from_glib_none(ptr: *const ffi::GstVideoTimeCodeInterval) -> Self { unsafe fn from_glib_none(ptr: *const ffi::GstVideoTimeCodeInterval) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
VideoTimeCodeInterval(ptr::read(ptr)) Self(ptr::read(ptr))
} }
} }
@ -178,7 +178,7 @@ impl FromGlibPtrFull<*mut ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInterv
#[inline] #[inline]
unsafe fn from_glib_full(ptr: *mut ffi::GstVideoTimeCodeInterval) -> Self { unsafe fn from_glib_full(ptr: *mut ffi::GstVideoTimeCodeInterval) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
let res = VideoTimeCodeInterval(ptr::read(ptr)); let res = Self(ptr::read(ptr));
ffi::gst_video_time_code_interval_free(ptr); ffi::gst_video_time_code_interval_free(ptr);
res res
@ -190,7 +190,7 @@ impl FromGlibPtrBorrow<*mut ffi::GstVideoTimeCodeInterval> for VideoTimeCodeInte
#[inline] #[inline]
unsafe fn from_glib_borrow(ptr: *mut ffi::GstVideoTimeCodeInterval) -> Borrowed<Self> { unsafe fn from_glib_borrow(ptr: *mut ffi::GstVideoTimeCodeInterval) -> Borrowed<Self> {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Borrowed::new(VideoTimeCodeInterval(ptr::read(ptr))) Borrowed::new(Self(ptr::read(ptr)))
} }
} }