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
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use std::{ffi::CStr, fmt};
|
2017-08-02 17:34:37 +00:00
|
|
|
|
2021-04-27 15:15:46 +00:00
|
|
|
use glib::translate::{from_glib, from_glib_full, IntoGlib, ToGlibPtr};
|
2017-08-02 17:34:37 +00:00
|
|
|
|
2024-06-02 08:48:53 +00:00
|
|
|
use crate::{ffi, StructureRef};
|
2017-08-02 17:34:37 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
mini_object_wrapper!(Context, ContextRef, ffi::GstContext, || {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_context_get_type()
|
2018-09-28 15:11:46 +00:00
|
|
|
});
|
2017-08-02 17:34:37 +00:00
|
|
|
|
2018-09-28 15:11:46 +00:00
|
|
|
impl Context {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[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 {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib_full(ffi::gst_context_new(
|
2017-08-02 17:34:37 +00:00
|
|
|
context_type.to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
persistent.into_glib(),
|
2017-08-02 17:34:37 +00:00
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ContextRef {
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_context_type")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[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 {
|
2020-11-21 13:46:48 +00:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[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 {
|
2020-11-21 13:46:48 +00:00
|
|
|
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,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_context_is_persistent")]
|
2017-08-02 17:34:37 +00:00
|
|
|
pub fn is_persistent(&self) -> bool {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_context_is_persistent(self.as_mut_ptr())) }
|
2017-08-02 17:34:37 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_structure")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_context_get_structure")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn structure(&self) -> &StructureRef {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { StructureRef::from_glib_borrow(ffi::gst_context_get_structure(self.as_mut_ptr())) }
|
2017-08-02 17:34:37 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +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 {
|
2020-11-21 13:46:48 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
impl fmt::Debug for Context {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
ContextRef::fmt(self, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 09:21:20 +00:00
|
|
|
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())
|
2017-12-01 09:21:20 +00:00
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|