Add accessors for various base class fields

And fix some other existing accessors to use the correct mutex.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1373>
This commit is contained in:
Sebastian Dröge 2024-01-05 15:35:40 +02:00
parent 0b4c602c6f
commit c66fc90566
12 changed files with 206 additions and 8 deletions

View file

@ -126,6 +126,26 @@ pub trait AudioDecoderExtManual: sealed::Sealed + IsA<AudioDecoder> + 'static {
&*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
}
}
fn input_segment(&self) -> gst::Segment {
unsafe {
let ptr: &ffi::GstAudioDecoder = &*(self.as_ptr() as *const _);
glib::ffi::g_rec_mutex_lock(mut_override(&ptr.stream_lock));
let segment = ptr.input_segment;
glib::ffi::g_rec_mutex_unlock(mut_override(&ptr.stream_lock));
from_glib_none(&segment as *const gst::ffi::GstSegment)
}
}
fn output_segment(&self) -> gst::Segment {
unsafe {
let ptr: &ffi::GstAudioDecoder = &*(self.as_ptr() as *const _);
glib::ffi::g_rec_mutex_lock(mut_override(&ptr.stream_lock));
let segment = ptr.output_segment;
glib::ffi::g_rec_mutex_unlock(mut_override(&ptr.stream_lock));
from_glib_none(&segment as *const gst::ffi::GstSegment)
}
}
}
impl<O: IsA<AudioDecoder>> AudioDecoderExtManual for O {}

View file

@ -82,6 +82,26 @@ pub trait AudioEncoderExtManual: sealed::Sealed + IsA<AudioEncoder> + 'static {
&*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
}
}
fn input_segment(&self) -> gst::Segment {
unsafe {
let ptr: &ffi::GstAudioDecoder = &*(self.as_ptr() as *const _);
glib::ffi::g_rec_mutex_lock(mut_override(&ptr.stream_lock));
let segment = ptr.input_segment;
glib::ffi::g_rec_mutex_unlock(mut_override(&ptr.stream_lock));
from_glib_none(&segment as *const gst::ffi::GstSegment)
}
}
fn output_segment(&self) -> gst::Segment {
unsafe {
let ptr: &ffi::GstAudioDecoder = &*(self.as_ptr() as *const _);
glib::ffi::g_rec_mutex_lock(mut_override(&ptr.stream_lock));
let segment = ptr.output_segment;
glib::ffi::g_rec_mutex_unlock(mut_override(&ptr.stream_lock));
from_glib_none(&segment as *const gst::ffi::GstSegment)
}
}
}
impl<O: IsA<AudioEncoder>> AudioEncoderExtManual for O {}

View file

@ -0,0 +1,30 @@
// Take a look at the license at the top of the repository in the LICENSE file.
use glib::{prelude::*, translate::*};
use gst_base::prelude::*;
use crate::{AudioFilter, AudioInfo};
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::AudioFilter>> Sealed for T {}
}
pub trait AudioFilterExtManual: sealed::Sealed + IsA<AudioFilter> + 'static {
fn audio_info(&self) -> Option<AudioInfo> {
unsafe {
let ptr: &ffi::GstAudioFilter = &*(self.as_ptr() as *const _);
let sinkpad = self.as_ref().sink_pad();
let _guard = sinkpad.stream_lock();
let info = &ptr.info;
if !info.finfo.is_null() && info.channels > 0 && info.rate > 0 && info.bpf > 0 {
return None;
}
Some(from_glib_none(info as *const ffi::GstAudioInfo))
}
}
}
impl<O: IsA<AudioFilter>> AudioFilterExtManual for O {}

View file

@ -58,6 +58,7 @@ pub use audio_buffer::{AudioBuffer, AudioBufferRef};
mod audio_decoder;
mod audio_encoder;
mod audio_filter;
mod audio_converter;
pub use crate::audio_converter::AudioConverterConfig;
@ -72,8 +73,8 @@ pub mod prelude {
pub use crate::{
audio_aggregator::AudioAggregatorExtManual,
audio_aggregator_convert_pad::AudioAggregatorConvertPadExtManual,
audio_aggregator_pad::AudioAggregatorPadExtManual, audio_format::AudioFormatIteratorExt,
auto::traits::*,
audio_aggregator_pad::AudioAggregatorPadExtManual, audio_filter::AudioFilterExtManual,
audio_format::AudioFormatIteratorExt, auto::traits::*,
};
}

View file

@ -3,7 +3,10 @@
use std::mem;
use glib::{prelude::*, translate::*};
use gst::format::{FormattedValue, SpecificFormattedValueFullRange};
use gst::{
format::{FormattedValue, SpecificFormattedValueFullRange},
prelude::*,
};
use crate::{BaseParse, BaseParseFrame};
@ -29,6 +32,33 @@ pub trait BaseParseExtManual: sealed::Sealed + IsA<BaseParse> + 'static {
}
}
fn segment(&self) -> gst::Segment {
unsafe {
let ptr: &ffi::GstBaseParse = &*(self.as_ptr() as *const _);
let sinkpad = self.sink_pad();
let _guard = sinkpad.stream_lock();
from_glib_none(&ptr.segment as *const gst::ffi::GstSegment)
}
}
fn lost_sync(&self) -> bool {
unsafe {
let ptr: &ffi::GstBaseParse = &*(self.as_ptr() as *const _);
let sinkpad = self.sink_pad();
let _guard = sinkpad.stream_lock();
ptr.flags & ffi::GST_BASE_PARSE_FLAG_LOST_SYNC as u32 != 0
}
}
fn is_draining(&self) -> bool {
unsafe {
let ptr: &ffi::GstBaseParse = &*(self.as_ptr() as *const _);
let sinkpad = self.sink_pad();
let _guard = sinkpad.stream_lock();
ptr.flags & ffi::GST_BASE_PARSE_FLAG_DRAINING as u32 != 0
}
}
#[doc(alias = "gst_base_parse_set_duration")]
fn set_duration(&self, duration: impl FormattedValue, interval: u32) {
unsafe {

View file

@ -17,8 +17,9 @@ pub trait BaseSinkExtManual: sealed::Sealed + IsA<BaseSink> + 'static {
fn segment(&self) -> gst::Segment {
unsafe {
let sink: &ffi::GstBaseSink = &*(self.as_ptr() as *const _);
let _guard = self.as_ref().object_lock();
from_glib_none(&sink.segment as *const _)
let sinkpad = self.sink_pad();
let _guard = sinkpad.stream_lock();
from_glib_none(&sink.segment as *const gst::ffi::GstSegment)
}
}

View file

@ -32,6 +32,8 @@ pub trait BaseSrcExtManual: sealed::Sealed + IsA<BaseSrc> + 'static {
fn segment(&self) -> gst::Segment {
unsafe {
let src: &ffi::GstBaseSrc = &*(self.as_ptr() as *const _);
let srcpad = self.src_pad();
let _guard = srcpad.stream_lock();
let _guard = self.as_ref().object_lock();
from_glib_none(&src.segment as *const _)
}

View file

@ -32,7 +32,8 @@ pub trait BaseTransformExtManual: sealed::Sealed + IsA<BaseTransform> + 'static
fn segment(&self) -> gst::Segment {
unsafe {
let trans: &ffi::GstBaseTransform = &*(self.as_ptr() as *const _);
let _guard = self.as_ref().object_lock();
let sinkpad = self.sink_pad();
let _guard = sinkpad.stream_lock();
from_glib_none(&trans.segment as *const _)
}
}

View file

@ -108,6 +108,7 @@ pub use crate::video_converter::{VideoConverter, VideoConverterConfig};
mod video_codec_frame;
mod video_decoder;
mod video_encoder;
mod video_filter;
pub use crate::video_codec_frame::VideoCodecFrame;
pub mod video_codec_state;
pub use crate::video_codec_state::{VideoCodecState, VideoCodecStateContext};
@ -175,8 +176,8 @@ pub mod prelude {
pub use crate::{
auto::traits::*, video_buffer_pool::VideoBufferPoolConfig,
video_decoder::VideoDecoderExtManual, video_encoder::VideoEncoderExtManual,
video_format::VideoFormatIteratorExt, video_frame::VideoBufferExt,
video_overlay::VideoOverlayExtManual,
video_filter::VideoFilterExtManual, video_format::VideoFormatIteratorExt,
video_frame::VideoBufferExt, video_overlay::VideoOverlayExtManual,
};
}

View file

@ -281,6 +281,26 @@ pub trait VideoDecoderExtManual: sealed::Sealed + IsA<VideoDecoder> + 'static {
&*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
}
}
fn input_segment(&self) -> gst::Segment {
unsafe {
let ptr: &ffi::GstVideoDecoder = &*(self.as_ptr() as *const _);
glib::ffi::g_rec_mutex_lock(mut_override(&ptr.stream_lock));
let segment = ptr.input_segment;
glib::ffi::g_rec_mutex_unlock(mut_override(&ptr.stream_lock));
from_glib_none(&segment as *const gst::ffi::GstSegment)
}
}
fn output_segment(&self) -> gst::Segment {
unsafe {
let ptr: &ffi::GstVideoDecoder = &*(self.as_ptr() as *const _);
glib::ffi::g_rec_mutex_lock(mut_override(&ptr.stream_lock));
let segment = ptr.output_segment;
glib::ffi::g_rec_mutex_unlock(mut_override(&ptr.stream_lock));
from_glib_none(&segment as *const gst::ffi::GstSegment)
}
}
}
impl<O: IsA<VideoDecoder>> VideoDecoderExtManual for O {}

View file

@ -224,6 +224,26 @@ pub trait VideoEncoderExtManual: sealed::Sealed + IsA<VideoEncoder> + 'static {
&*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
}
}
fn input_segment(&self) -> gst::Segment {
unsafe {
let ptr: &ffi::GstVideoDecoder = &*(self.as_ptr() as *const _);
glib::ffi::g_rec_mutex_lock(mut_override(&ptr.stream_lock));
let segment = ptr.input_segment;
glib::ffi::g_rec_mutex_unlock(mut_override(&ptr.stream_lock));
from_glib_none(&segment as *const gst::ffi::GstSegment)
}
}
fn output_segment(&self) -> gst::Segment {
unsafe {
let ptr: &ffi::GstVideoDecoder = &*(self.as_ptr() as *const _);
glib::ffi::g_rec_mutex_lock(mut_override(&ptr.stream_lock));
let segment = ptr.output_segment;
glib::ffi::g_rec_mutex_unlock(mut_override(&ptr.stream_lock));
from_glib_none(&segment as *const gst::ffi::GstSegment)
}
}
}
impl<O: IsA<VideoEncoder>> VideoEncoderExtManual for O {}

View file

@ -0,0 +1,52 @@
// Take a look at the license at the top of the repository in the LICENSE file.
use glib::{prelude::*, translate::*};
use gst::prelude::*;
use gst_base::prelude::*;
use crate::VideoFilter;
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::VideoFilter>> Sealed for T {}
}
pub trait VideoFilterExtManual: sealed::Sealed + IsA<VideoFilter> + 'static {
fn input_video_info(&self) -> Option<crate::VideoInfo> {
unsafe {
let ptr = self.as_ptr() as *mut ffi::GstVideoFilter;
let sinkpad = self.as_ref().sink_pad();
let _guard = sinkpad.stream_lock();
let info = &(*ptr).in_info;
if info.finfo.is_null() || info.width <= 0 || info.height <= 0 {
return None;
}
Some(from_glib_none(mut_override(
info as *const ffi::GstVideoInfo,
)))
}
}
fn output_video_info(&self) -> Option<crate::VideoInfo> {
unsafe {
let ptr = self.as_ptr() as *mut ffi::GstVideoFilter;
let sinkpad = self.as_ref().sink_pad();
let _guard = sinkpad.stream_lock();
let info = &(*ptr).out_info;
if info.finfo.is_null() || info.width <= 0 || info.height <= 0 {
return None;
}
Some(from_glib_none(mut_override(
info as *const ffi::GstVideoInfo,
)))
}
}
}
impl<O: IsA<VideoFilter>> VideoFilterExtManual for O {}