gstreamer-rs/gstreamer/src/context.rs

81 lines
2.3 KiB
Rust
Raw Permalink Normal View History

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-02 17:34:37 +00:00
use std::{ffi::CStr, fmt};
2017-08-02 17:34:37 +00:00
use glib::translate::{from_glib, from_glib_full, IntoGlib, ToGlibPtr};
2017-08-02 17:34:37 +00:00
use crate::StructureRef;
2017-08-02 17:34:37 +00:00
mini_object_wrapper!(Context, ContextRef, ffi::GstContext, || {
ffi::gst_context_get_type()
});
2017-08-02 17:34:37 +00:00
impl Context {
#[doc(alias = "gst_context_new")]
2017-08-02 17:34:37 +00:00
pub fn new(context_type: &str, persistent: bool) -> Self {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::gst_context_new(
2017-08-02 17:34:37 +00:00
context_type.to_glib_none().0,
persistent.into_glib(),
2017-08-02 17:34:37 +00:00
))
}
}
}
impl ContextRef {
#[doc(alias = "get_context_type")]
#[doc(alias = "gst_context_get_context_type")]
2021-04-11 19:39:50 +00:00
pub fn context_type(&self) -> &str {
2017-08-02 17:34:37 +00:00
unsafe {
let raw = ffi::gst_context_get_context_type(self.as_mut_ptr());
2017-08-02 17:34:37 +00:00
CStr::from_ptr(raw).to_str().unwrap()
}
}
#[doc(alias = "gst_context_has_context_type")]
2017-08-02 17:34:37 +00:00
pub fn has_context_type(&self, context_type: &str) -> bool {
unsafe {
from_glib(ffi::gst_context_has_context_type(
2017-08-02 17:34:37 +00:00
self.as_mut_ptr(),
context_type.to_glib_none().0,
))
}
}
#[doc(alias = "gst_context_is_persistent")]
2017-08-02 17:34:37 +00:00
pub fn is_persistent(&self) -> bool {
unsafe { from_glib(ffi::gst_context_is_persistent(self.as_mut_ptr())) }
2017-08-02 17:34:37 +00:00
}
#[doc(alias = "get_structure")]
#[doc(alias = "gst_context_get_structure")]
2021-04-11 19:39:50 +00:00
pub fn structure(&self) -> &StructureRef {
unsafe { StructureRef::from_glib_borrow(ffi::gst_context_get_structure(self.as_mut_ptr())) }
2017-08-02 17:34:37 +00:00
}
#[doc(alias = "get_mut_structure")]
2021-04-11 19:39:50 +00:00
pub fn structure_mut(&mut self) -> &mut StructureRef {
2017-08-02 17:34:37 +00:00
unsafe {
StructureRef::from_glib_borrow_mut(ffi::gst_context_writable_structure(
2017-12-20 17:30:14 +00:00
self.as_mut_ptr(),
))
2017-08-02 17:34:37 +00:00
}
}
}
impl fmt::Debug for Context {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
ContextRef::fmt(self, f)
}
}
impl fmt::Debug for ContextRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Context")
2021-04-11 19:39:50 +00:00
.field("type", &self.context_type())
.field("structure", &self.structure())
.finish()
}
}