forked from mirrors/gstreamer-rs
gstreamer: Split parsers for owned and borrowed views
When we have a view like `Caps<&EventRef>`, we can return a `CapsRef` borrowing from the wrapped `EventRef`. This way, the `CapsRef` we return can outlive the view itself. This is in contrast to a `Caps<Event>` view which owns the `Event`. Here, the `CapsRef` we return cannot outlive the view. gstreamer-rs 0.18 consolidated code and treated everything like the latter case. Fix this by duplicating the accessors for each case. Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/367
This commit is contained in:
parent
ee9157a239
commit
fb56bbda6e
2 changed files with 195 additions and 22 deletions
|
@ -470,20 +470,33 @@ impl StreamStart<Event> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
StreamStartBuilder::new(stream_id)
|
StreamStartBuilder::new(stream_id)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: AsPtr> StreamStart<T> {
|
|
||||||
#[doc(alias = "get_stream_id")]
|
#[doc(alias = "get_stream_id")]
|
||||||
#[doc(alias = "gst_event_parse_stream_start")]
|
#[doc(alias = "gst_event_parse_stream_start")]
|
||||||
pub fn stream_id(&self) -> &str {
|
pub fn stream_id(&self) -> &str {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut stream_id = ptr::null();
|
let mut stream_id = ptr::null();
|
||||||
|
|
||||||
ffi::gst_event_parse_stream_start(self.0.as_ptr(), &mut stream_id);
|
ffi::gst_event_parse_stream_start(AsPtr::as_ptr(&self.0), &mut stream_id);
|
||||||
CStr::from_ptr(stream_id).to_str().unwrap()
|
CStr::from_ptr(stream_id).to_str().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> StreamStart<&'a EventRef> {
|
||||||
|
#[doc(alias = "get_stream_id")]
|
||||||
|
#[doc(alias = "gst_event_parse_stream_start")]
|
||||||
|
pub fn stream_id(&self) -> &'a str {
|
||||||
|
unsafe {
|
||||||
|
let mut stream_id = ptr::null();
|
||||||
|
|
||||||
|
ffi::gst_event_parse_stream_start(AsPtr::as_ptr(&self.0), &mut stream_id);
|
||||||
|
CStr::from_ptr(stream_id).to_str().unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: AsPtr> StreamStart<T> {
|
||||||
#[doc(alias = "get_stream_flags")]
|
#[doc(alias = "get_stream_flags")]
|
||||||
#[doc(alias = "gst_event_parse_stream_flags")]
|
#[doc(alias = "gst_event_parse_stream_flags")]
|
||||||
pub fn stream_flags(&self) -> crate::StreamFlags {
|
pub fn stream_flags(&self) -> crate::StreamFlags {
|
||||||
|
@ -539,16 +552,33 @@ impl Caps<Event> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
CapsBuilder::new(caps)
|
CapsBuilder::new(caps)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: AsPtr> Caps<T> {
|
|
||||||
#[doc(alias = "get_caps")]
|
#[doc(alias = "get_caps")]
|
||||||
#[doc(alias = "gst_event_parse_caps")]
|
#[doc(alias = "gst_event_parse_caps")]
|
||||||
pub fn caps(&self) -> &crate::CapsRef {
|
pub fn caps(&self) -> &crate::CapsRef {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut caps = ptr::null_mut();
|
let mut caps = ptr::null_mut();
|
||||||
|
|
||||||
ffi::gst_event_parse_caps(self.0.as_ptr(), &mut caps);
|
ffi::gst_event_parse_caps(AsPtr::as_ptr(&self.0), &mut caps);
|
||||||
|
crate::CapsRef::from_ptr(caps)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(alias = "get_caps_owned")]
|
||||||
|
#[doc(alias = "gst_event_parse_caps")]
|
||||||
|
pub fn caps_owned(&self) -> crate::Caps {
|
||||||
|
unsafe { from_glib_none(self.caps().as_ptr()) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Caps<&'a EventRef> {
|
||||||
|
#[doc(alias = "get_caps")]
|
||||||
|
#[doc(alias = "gst_event_parse_caps")]
|
||||||
|
pub fn caps(&self) -> &'a crate::CapsRef {
|
||||||
|
unsafe {
|
||||||
|
let mut caps = ptr::null_mut();
|
||||||
|
|
||||||
|
ffi::gst_event_parse_caps(AsPtr::as_ptr(&self.0), &mut caps);
|
||||||
crate::CapsRef::from_ptr(caps)
|
crate::CapsRef::from_ptr(caps)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -575,16 +605,27 @@ impl Segment<Event> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
SegmentBuilder::new(segment.as_ref())
|
SegmentBuilder::new(segment.as_ref())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: AsPtr> Segment<T> {
|
|
||||||
#[doc(alias = "get_segment")]
|
#[doc(alias = "get_segment")]
|
||||||
#[doc(alias = "gst_event_parse_segment")]
|
#[doc(alias = "gst_event_parse_segment")]
|
||||||
pub fn segment(&self) -> &crate::Segment {
|
pub fn segment(&self) -> &crate::Segment {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut segment = ptr::null();
|
let mut segment = ptr::null();
|
||||||
|
|
||||||
ffi::gst_event_parse_segment(self.0.as_ptr(), &mut segment);
|
ffi::gst_event_parse_segment(AsPtr::as_ptr(&self.0), &mut segment);
|
||||||
|
&*(segment as *mut ffi::GstSegment as *mut crate::Segment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Segment<&'a EventRef> {
|
||||||
|
#[doc(alias = "get_segment")]
|
||||||
|
#[doc(alias = "gst_event_parse_segment")]
|
||||||
|
pub fn segment(&self) -> &'a crate::Segment {
|
||||||
|
unsafe {
|
||||||
|
let mut segment = ptr::null();
|
||||||
|
|
||||||
|
ffi::gst_event_parse_segment(AsPtr::as_ptr(&self.0), &mut segment);
|
||||||
&*(segment as *mut ffi::GstSegment as *mut crate::Segment)
|
&*(segment as *mut ffi::GstSegment as *mut crate::Segment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -643,16 +684,33 @@ impl Tag<Event> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
TagBuilder::new(tags)
|
TagBuilder::new(tags)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: AsPtr> Tag<T> {
|
|
||||||
#[doc(alias = "get_tag")]
|
#[doc(alias = "get_tag")]
|
||||||
#[doc(alias = "gst_event_parse_tag")]
|
#[doc(alias = "gst_event_parse_tag")]
|
||||||
pub fn tag(&self) -> &crate::TagListRef {
|
pub fn tag(&self) -> &crate::TagListRef {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut tags = ptr::null_mut();
|
let mut tags = ptr::null_mut();
|
||||||
|
|
||||||
ffi::gst_event_parse_tag(self.0.as_ptr(), &mut tags);
|
ffi::gst_event_parse_tag(AsPtr::as_ptr(&self.0), &mut tags);
|
||||||
|
crate::TagListRef::from_ptr(tags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(alias = "get_tag_owned")]
|
||||||
|
#[doc(alias = "gst_event_parse_tag")]
|
||||||
|
pub fn tag_owned(&self) -> crate::TagList {
|
||||||
|
unsafe { from_glib_none(self.tag().as_ptr()) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Tag<&'a EventRef> {
|
||||||
|
#[doc(alias = "get_tag")]
|
||||||
|
#[doc(alias = "gst_event_parse_tag")]
|
||||||
|
pub fn tag(&self) -> &'a crate::TagListRef {
|
||||||
|
unsafe {
|
||||||
|
let mut tags = ptr::null_mut();
|
||||||
|
|
||||||
|
ffi::gst_event_parse_tag(AsPtr::as_ptr(&self.0), &mut tags);
|
||||||
crate::TagListRef::from_ptr(tags)
|
crate::TagListRef::from_ptr(tags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1287,15 +1345,26 @@ impl TocSelect<Event> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
TocSelectBuilder::new(uid)
|
TocSelectBuilder::new(uid)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: AsPtr> TocSelect<T> {
|
|
||||||
#[doc(alias = "get_uid")]
|
#[doc(alias = "get_uid")]
|
||||||
pub fn uid(&self) -> &str {
|
pub fn uid(&self) -> &str {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut uid = ptr::null_mut();
|
let mut uid = ptr::null_mut();
|
||||||
|
|
||||||
ffi::gst_event_parse_toc_select(self.0.as_ptr(), &mut uid);
|
ffi::gst_event_parse_toc_select(AsPtr::as_ptr(&self.0), &mut uid);
|
||||||
|
|
||||||
|
CStr::from_ptr(uid).to_str().unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> TocSelect<&'a EventRef> {
|
||||||
|
#[doc(alias = "get_uid")]
|
||||||
|
pub fn uid(&self) -> &'a str {
|
||||||
|
unsafe {
|
||||||
|
let mut uid = ptr::null_mut();
|
||||||
|
|
||||||
|
ffi::gst_event_parse_toc_select(AsPtr::as_ptr(&self.0), &mut uid);
|
||||||
|
|
||||||
CStr::from_ptr(uid).to_str().unwrap()
|
CStr::from_ptr(uid).to_str().unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1318,15 +1318,13 @@ impl AcceptCaps<Query> {
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: AsPtr> AcceptCaps<T> {
|
|
||||||
#[doc(alias = "get_caps")]
|
#[doc(alias = "get_caps")]
|
||||||
#[doc(alias = "gst_query_parse_accept_caps")]
|
#[doc(alias = "gst_query_parse_accept_caps")]
|
||||||
pub fn caps(&self) -> &crate::CapsRef {
|
pub fn caps(&self) -> &crate::CapsRef {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut caps = ptr::null_mut();
|
let mut caps = ptr::null_mut();
|
||||||
ffi::gst_query_parse_accept_caps(self.0.as_ptr(), &mut caps);
|
ffi::gst_query_parse_accept_caps(AsPtr::as_ptr(&self.0), &mut caps);
|
||||||
crate::CapsRef::from_ptr(caps)
|
crate::CapsRef::from_ptr(caps)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1336,7 +1334,45 @@ impl<T: AsPtr> AcceptCaps<T> {
|
||||||
pub fn caps_owned(&self) -> crate::Caps {
|
pub fn caps_owned(&self) -> crate::Caps {
|
||||||
unsafe { from_glib_none(self.caps().as_ptr()) }
|
unsafe { from_glib_none(self.caps().as_ptr()) }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> AcceptCaps<&'a QueryRef> {
|
||||||
|
#[doc(alias = "get_caps")]
|
||||||
|
#[doc(alias = "gst_query_parse_accept_caps")]
|
||||||
|
pub fn caps(&self) -> &'a crate::CapsRef {
|
||||||
|
unsafe {
|
||||||
|
let mut caps = ptr::null_mut();
|
||||||
|
ffi::gst_query_parse_accept_caps(AsPtr::as_ptr(&self.0), &mut caps);
|
||||||
|
crate::CapsRef::from_ptr(caps)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(alias = "get_caps_owned")]
|
||||||
|
#[doc(alias = "gst_query_parse_accept_caps")]
|
||||||
|
pub fn caps_owned(&self) -> crate::Caps {
|
||||||
|
unsafe { from_glib_none(self.caps().as_ptr()) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> AcceptCaps<&'a mut QueryRef> {
|
||||||
|
#[doc(alias = "get_caps")]
|
||||||
|
#[doc(alias = "gst_query_parse_accept_caps")]
|
||||||
|
pub fn caps(&self) -> &'a crate::CapsRef {
|
||||||
|
unsafe {
|
||||||
|
let mut caps = ptr::null_mut();
|
||||||
|
ffi::gst_query_parse_accept_caps(AsPtr::as_ptr(&self.0), &mut caps);
|
||||||
|
crate::CapsRef::from_ptr(caps)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(alias = "get_caps_owned")]
|
||||||
|
#[doc(alias = "gst_query_parse_accept_caps")]
|
||||||
|
pub fn caps_owned(&self) -> crate::Caps {
|
||||||
|
unsafe { from_glib_none(self.caps().as_ptr()) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: AsPtr> AcceptCaps<T> {
|
||||||
#[doc(alias = "get_result")]
|
#[doc(alias = "get_result")]
|
||||||
#[doc(alias = "gst_query_parse_accept_caps_result")]
|
#[doc(alias = "gst_query_parse_accept_caps_result")]
|
||||||
pub fn result(&self) -> bool {
|
pub fn result(&self) -> bool {
|
||||||
|
@ -1447,15 +1483,13 @@ impl Context<Query> {
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: AsPtr> Context<T> {
|
|
||||||
#[doc(alias = "get_context")]
|
#[doc(alias = "get_context")]
|
||||||
#[doc(alias = "gst_query_parse_context")]
|
#[doc(alias = "gst_query_parse_context")]
|
||||||
pub fn context(&self) -> Option<&crate::ContextRef> {
|
pub fn context(&self) -> Option<&crate::ContextRef> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut context = ptr::null_mut();
|
let mut context = ptr::null_mut();
|
||||||
ffi::gst_query_parse_context(self.0.as_ptr(), &mut context);
|
ffi::gst_query_parse_context(AsPtr::as_ptr(&self.0), &mut context);
|
||||||
if context.is_null() {
|
if context.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -1478,7 +1512,77 @@ impl<T: AsPtr> Context<T> {
|
||||||
pub fn context_type(&self) -> &str {
|
pub fn context_type(&self) -> &str {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut context_type = ptr::null();
|
let mut context_type = ptr::null();
|
||||||
ffi::gst_query_parse_context_type(self.0.as_ptr(), &mut context_type);
|
ffi::gst_query_parse_context_type(AsPtr::as_ptr(&self.0), &mut context_type);
|
||||||
|
CStr::from_ptr(context_type).to_str().unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Context<&'a QueryRef> {
|
||||||
|
#[doc(alias = "get_context")]
|
||||||
|
#[doc(alias = "gst_query_parse_context")]
|
||||||
|
pub fn context(&self) -> Option<&'a crate::ContextRef> {
|
||||||
|
unsafe {
|
||||||
|
let mut context = ptr::null_mut();
|
||||||
|
ffi::gst_query_parse_context(AsPtr::as_ptr(&self.0), &mut context);
|
||||||
|
if context.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(crate::ContextRef::from_ptr(context))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(alias = "get_context_owned")]
|
||||||
|
#[doc(alias = "gst_query_parse_context")]
|
||||||
|
pub fn context_owned(&self) -> Option<crate::Context> {
|
||||||
|
unsafe {
|
||||||
|
self.context()
|
||||||
|
.map(|context| from_glib_none(context.as_ptr()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(alias = "get_context_type")]
|
||||||
|
#[doc(alias = "gst_query_parse_context_type")]
|
||||||
|
pub fn context_type(&self) -> &'a str {
|
||||||
|
unsafe {
|
||||||
|
let mut context_type = ptr::null();
|
||||||
|
ffi::gst_query_parse_context_type(AsPtr::as_ptr(&self.0), &mut context_type);
|
||||||
|
CStr::from_ptr(context_type).to_str().unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Context<&'a mut QueryRef> {
|
||||||
|
#[doc(alias = "get_context")]
|
||||||
|
#[doc(alias = "gst_query_parse_context")]
|
||||||
|
pub fn context(&self) -> Option<&'a crate::ContextRef> {
|
||||||
|
unsafe {
|
||||||
|
let mut context = ptr::null_mut();
|
||||||
|
ffi::gst_query_parse_context(AsPtr::as_ptr(&self.0), &mut context);
|
||||||
|
if context.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(crate::ContextRef::from_ptr(context))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(alias = "get_context_owned")]
|
||||||
|
#[doc(alias = "gst_query_parse_context")]
|
||||||
|
pub fn context_owned(&self) -> Option<crate::Context> {
|
||||||
|
unsafe {
|
||||||
|
self.context()
|
||||||
|
.map(|context| from_glib_none(context.as_ptr()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(alias = "get_context_type")]
|
||||||
|
#[doc(alias = "gst_query_parse_context_type")]
|
||||||
|
pub fn context_type(&self) -> &'a str {
|
||||||
|
unsafe {
|
||||||
|
let mut context_type = ptr::null();
|
||||||
|
ffi::gst_query_parse_context_type(AsPtr::as_ptr(&self.0), &mut context_type);
|
||||||
CStr::from_ptr(context_type).to_str().unwrap()
|
CStr::from_ptr(context_type).to_str().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue