gstreamer_validate/
action.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use 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    /// ## `scenario`
32    /// The scenario executing the action
33    /// ## `action_type`
34    /// The action type
35    /// ## `structure`
36    /// The structure containing the action arguments
37    /// ## `add_to_lists`
38    /// Weather the action should be added to the scenario action list
39    ///
40    /// # Returns
41    ///
42    /// A newly created [`Action`][crate::Action]
43    #[doc(alias = "gst_validate_action_new")]
44    pub fn new(
45        scenario: Option<&impl IsA<Scenario>>,
46        action_type: &ActionType,
47        structure: &gst::StructureRef,
48        add_to_lists: bool,
49    ) -> Action {
50        assert_initialized_main_thread!();
51        unsafe {
52            from_glib_full(ffi::gst_validate_action_new(
53                scenario.map(|p| p.as_ref()).to_glib_none().0,
54                action_type.to_glib_none().0,
55                structure.as_mut_ptr(),
56                add_to_lists.into_glib(),
57            ))
58        }
59    }
60
61    #[doc(alias = "gst_validate_execute_action")]
62    pub fn execute(&self) -> Result<crate::ActionSuccess, crate::ActionError> {
63        unsafe {
64            let action: *mut ffi::GstValidateAction = self.to_glib_none().0;
65            let action_type = ffi::gst_validate_get_action_type((*action).type_);
66
67            let res = ffi::gst_validate_execute_action(action_type, action);
68
69            if let Some(v) = crate::ActionSuccess::from_value(res) {
70                Ok(v)
71            } else {
72                Err(crate::ActionError::from_value(res))
73            }
74        }
75    }
76}