gstreamer_validate/
action.rs1use glib::prelude::*;
4use glib::translate::*;
5
6use crate::{ffi, ActionType, Scenario};
7
8gst::mini_object_wrapper!(Action, ActionRef, ffi::GstValidateAction, || {
9 ffi::gst_validate_action_get_type()
10});
11
12impl ActionRef {
13 pub fn structure(&self) -> &gst::StructureRef {
14 unsafe {
15 let action = &self.0 as *const ffi::GstValidateAction;
16
17 gst::StructureRef::from_glib_borrow((*action).structure)
18 }
19 }
20
21 pub fn structure_mut(&mut self) -> &mut gst::StructureRef {
22 unsafe {
23 let action = &mut self.0 as *mut ffi::GstValidateAction;
24
25 gst::StructureRef::from_glib_borrow_mut((*action).structure)
26 }
27 }
28}
29
30impl Action {
31 #[doc(alias = "gst_validate_action_new")]
32 pub fn new(
33 scenario: Option<&impl IsA<Scenario>>,
34 action_type: &ActionType,
35 structure: &gst::StructureRef,
36 add_to_lists: bool,
37 ) -> Action {
38 assert_initialized_main_thread!();
39 unsafe {
40 from_glib_full(ffi::gst_validate_action_new(
41 scenario.map(|p| p.as_ref()).to_glib_none().0,
42 action_type.to_glib_none().0,
43 structure.as_mut_ptr(),
44 add_to_lists.into_glib(),
45 ))
46 }
47 }
48
49 #[doc(alias = "gst_validate_execute_action")]
50 pub fn execute(&self) -> Result<crate::ActionSuccess, crate::ActionError> {
51 unsafe {
52 let action: *mut ffi::GstValidateAction = self.to_glib_none().0;
53 let action_type = ffi::gst_validate_get_action_type((*action).type_);
54
55 let res = ffi::gst_validate_execute_action(action_type, action);
56
57 if let Some(v) = crate::ActionSuccess::from_value(res) {
58 Ok(v)
59 } else {
60 Err(crate::ActionError::from_value(res))
61 }
62 }
63 }
64}