gstreamer/parse_context.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::ffi;
4use glib::translate::*;
5
6glib::wrapper! {
7 /// Opaque structure.
8 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
9 #[doc(alias = "GstParseContext")]
10 pub struct ParseContext(Boxed<ffi::GstParseContext>);
11
12 match fn {
13 copy => |ptr| ffi::gst_parse_context_copy(ptr),
14 free => |ptr| ffi::gst_parse_context_free(ptr),
15 type_ => || ffi::gst_parse_context_get_type(),
16 }
17}
18
19unsafe impl Send for ParseContext {}
20unsafe impl Sync for ParseContext {}
21
22impl ParseContext {
23 /// Allocates a parse context for use with `gst_parse_launch_full()` or
24 /// `gst_parse_launchv_full()`.
25 ///
26 /// Free-function: gst_parse_context_free
27 ///
28 /// # Returns
29 ///
30 /// a newly-allocated parse context. Free
31 /// with `gst_parse_context_free()` when no longer needed.
32 #[doc(alias = "gst_parse_context_new")]
33 pub fn new() -> Self {
34 unsafe { from_glib_full(ffi::gst_parse_context_new()) }
35 }
36
37 /// Retrieve missing elements from a previous run of `gst_parse_launch_full()`
38 /// or `gst_parse_launchv_full()`. Will only return results if an error code
39 /// of [`ParseError::NoSuchElement`][crate::ParseError::NoSuchElement] was returned.
40 ///
41 /// # Returns
42 ///
43 /// a
44 /// [`None`]-terminated array of element factory name strings of missing
45 /// elements. Free with `g_strfreev()` when no longer needed.
46 #[doc(alias = "get_missing_elements")]
47 #[doc(alias = "gst_parse_context_get_missing_elements")]
48 pub fn missing_elements(&self) -> Vec<String> {
49 unsafe {
50 FromGlibPtrContainer::from_glib_full(ffi::gst_parse_context_get_missing_elements(
51 mut_override(self.to_glib_none().0),
52 ))
53 }
54 }
55
56 /// Retrieve what a previous run of `gst_parse_launch_full()` or
57 /// `gst_parse_launchv_full()` refused because [`ParseFlags::NO_UNTRUSTED`][crate::ParseFlags::NO_UNTRUSTED] was
58 /// set, so an application can tell the user exactly what a description was
59 /// refused for and decide whether to build it in a trusted mode.
60 ///
61 /// Everything that was refused is listed, whichever error the parse reported.
62 /// The result is a [`Structure`][crate::Structure] named `untrusted-content` with:
63 ///
64 /// * `elements`: a list of the factory names that are not marked
65 /// untrusted-aware, see [`ElementClass::mark_as_untrusted_aware()`][crate::ElementClass::mark_as_untrusted_aware()]. Absent
66 /// when no element was refused.
67 /// * `properties`: a [`Structure`][crate::Structure] named `untrusted-sensitive-properties`, with
68 /// one field per refused assignment named `element-name:property`, where
69 /// `element-name` is the unique name of the element instance and `property`
70 /// is the property as written in the description, possibly a
71 /// `child::property` path. The field holds the refused value, parsed into the
72 /// property's own type when that type is known and parsing the value cannot
73 /// have side effects, and the string as written otherwise. A refused value is
74 /// never handed to the property setter. Absent when no property was refused.
75 /// * `unresolved-properties`: a [`Structure`][crate::Structure] named
76 /// `untrusted-unresolved-properties`, same field shape, for assignments to a
77 /// child that never materialized during the parse (demuxer pads and other
78 /// runtime-only children). The value is always the string as written, since
79 /// the property type is not known. Absent when no such assignment was
80 /// refused.
81 ///
82 /// [`parse_untrusted_report()`][crate::parse_untrusted_report()] unpacks these fields without knowing the
83 /// layout.
84 ///
85 /// # Returns
86 ///
87 /// a structure describing what was
88 /// refused, or [`None`] if nothing was. Free with `gst_structure_free()`.
89 #[cfg(feature = "v1_30")]
90 #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
91 #[doc(alias = "gst_parse_context_get_untrusted_report")]
92 #[doc(alias = "get_untrusted_report")]
93 pub fn untrusted_report(&self) -> Option<crate::Structure> {
94 unsafe {
95 from_glib_full(ffi::gst_parse_context_get_untrusted_report(mut_override(
96 self.to_glib_none().0,
97 )))
98 }
99 }
100}
101
102impl Default for ParseContext {
103 fn default() -> Self {
104 Self::new()
105 }
106}