gstreamer/
context.rs
1use std::{ffi::CStr, fmt};
4
5use glib::translate::{from_glib, from_glib_full, IntoGlib, ToGlibPtr};
6
7use crate::{ffi, StructureRef};
8
9mini_object_wrapper!(Context, ContextRef, ffi::GstContext, || {
10 ffi::gst_context_get_type()
11});
12
13impl Context {
14 #[doc(alias = "gst_context_new")]
24 pub fn new(context_type: &str, persistent: bool) -> Self {
25 assert_initialized_main_thread!();
26 unsafe {
27 from_glib_full(ffi::gst_context_new(
28 context_type.to_glib_none().0,
29 persistent.into_glib(),
30 ))
31 }
32 }
33}
34
35impl ContextRef {
36 #[doc(alias = "get_context_type")]
37 #[doc(alias = "gst_context_get_context_type")]
38 pub fn context_type(&self) -> &str {
39 unsafe {
40 let raw = ffi::gst_context_get_context_type(self.as_mut_ptr());
41 CStr::from_ptr(raw).to_str().unwrap()
42 }
43 }
44
45 #[doc(alias = "gst_context_has_context_type")]
46 pub fn has_context_type(&self, context_type: &str) -> bool {
47 unsafe {
48 from_glib(ffi::gst_context_has_context_type(
49 self.as_mut_ptr(),
50 context_type.to_glib_none().0,
51 ))
52 }
53 }
54
55 #[doc(alias = "gst_context_is_persistent")]
56 pub fn is_persistent(&self) -> bool {
57 unsafe { from_glib(ffi::gst_context_is_persistent(self.as_mut_ptr())) }
58 }
59
60 #[doc(alias = "get_structure")]
61 #[doc(alias = "gst_context_get_structure")]
62 pub fn structure(&self) -> &StructureRef {
63 unsafe { StructureRef::from_glib_borrow(ffi::gst_context_get_structure(self.as_mut_ptr())) }
64 }
65
66 #[doc(alias = "get_mut_structure")]
67 pub fn structure_mut(&mut self) -> &mut StructureRef {
68 unsafe {
69 StructureRef::from_glib_borrow_mut(ffi::gst_context_writable_structure(
70 self.as_mut_ptr(),
71 ))
72 }
73 }
74}
75
76impl fmt::Debug for Context {
77 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
78 ContextRef::fmt(self, f)
79 }
80}
81
82impl fmt::Debug for ContextRef {
83 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
84 f.debug_struct("Context")
85 .field("type", &self.context_type())
86 .field("structure", &self.structure())
87 .finish()
88 }
89}