gstreamer_pbutils/auto/encoding_target.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{ffi, EncodingProfile};
7use glib::translate::*;
8
9glib::wrapper! {
10 /// Collection of [`EncodingProfile`][crate::EncodingProfile] for a specific target or use-case.
11 ///
12 /// When being stored/loaded, targets come from a specific category, like
13 /// `GST_ENCODING_CATEGORY_DEVICE`.
14 ///
15 /// # Implements
16 ///
17 /// [`trait@glib::ObjectExt`]
18 #[doc(alias = "GstEncodingTarget")]
19 pub struct EncodingTarget(Object<ffi::GstEncodingTarget>);
20
21 match fn {
22 type_ => || ffi::gst_encoding_target_get_type(),
23 }
24}
25
26impl EncodingTarget {
27 /// Creates a new [`EncodingTarget`][crate::EncodingTarget].
28 ///
29 /// The name and category can only consist of lowercase ASCII letters for the
30 /// first character, followed by either lowercase ASCII letters, digits or
31 /// hyphens ('-').
32 ///
33 /// The `category` *should* be one of the existing
34 /// well-defined categories, like `GST_ENCODING_CATEGORY_DEVICE`, but it
35 /// *can* be a application or user specific category if
36 /// needed.
37 /// ## `name`
38 /// The name of the target.
39 /// ## `category`
40 /// The name of the category to which this `target`
41 /// belongs. For example: `GST_ENCODING_CATEGORY_DEVICE`.
42 /// ## `description`
43 /// A description of [`EncodingTarget`][crate::EncodingTarget] in the
44 /// current locale.
45 /// ## `profiles`
46 /// A `GList` of
47 /// [`EncodingProfile`][crate::EncodingProfile].
48 ///
49 /// # Returns
50 ///
51 /// The newly created [`EncodingTarget`][crate::EncodingTarget] or [`None`] if
52 /// there was an error.
53 #[doc(alias = "gst_encoding_target_new")]
54 pub fn new(
55 name: &str,
56 category: &str,
57 description: &str,
58 profiles: &[EncodingProfile],
59 ) -> Result<EncodingTarget, glib::BoolError> {
60 assert_initialized_main_thread!();
61 unsafe {
62 Option::<_>::from_glib_full(ffi::gst_encoding_target_new(
63 name.to_glib_none().0,
64 category.to_glib_none().0,
65 description.to_glib_none().0,
66 profiles.to_glib_none().0,
67 ))
68 .ok_or_else(|| glib::bool_error!("Failed to create EncodingTarget"))
69 }
70 }
71
72 ///
73 /// # Returns
74 ///
75 /// The category of the `self`. For example:
76 /// `GST_ENCODING_CATEGORY_DEVICE`.
77 #[doc(alias = "gst_encoding_target_get_category")]
78 #[doc(alias = "get_category")]
79 pub fn category(&self) -> glib::GString {
80 unsafe { from_glib_none(ffi::gst_encoding_target_get_category(self.to_glib_none().0)) }
81 }
82
83 ///
84 /// # Returns
85 ///
86 /// The description of the `self`.
87 #[doc(alias = "gst_encoding_target_get_description")]
88 #[doc(alias = "get_description")]
89 pub fn description(&self) -> glib::GString {
90 unsafe {
91 from_glib_none(ffi::gst_encoding_target_get_description(
92 self.to_glib_none().0,
93 ))
94 }
95 }
96
97 ///
98 /// # Returns
99 ///
100 /// The name of the `self`.
101 #[doc(alias = "gst_encoding_target_get_name")]
102 #[doc(alias = "get_name")]
103 pub fn name(&self) -> glib::GString {
104 unsafe { from_glib_none(ffi::gst_encoding_target_get_name(self.to_glib_none().0)) }
105 }
106
107 ///
108 /// # Returns
109 ///
110 /// The path to the `self` file.
111 #[cfg(feature = "v1_18")]
112 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
113 #[doc(alias = "gst_encoding_target_get_path")]
114 #[doc(alias = "get_path")]
115 pub fn path(&self) -> Option<std::path::PathBuf> {
116 unsafe { from_glib_none(ffi::gst_encoding_target_get_path(self.to_glib_none().0)) }
117 }
118
119 /// ## `name`
120 /// the name of the profile to retrieve
121 ///
122 /// # Returns
123 ///
124 /// The matching [`EncodingProfile`][crate::EncodingProfile], or [`None`].
125 #[doc(alias = "gst_encoding_target_get_profile")]
126 #[doc(alias = "get_profile")]
127 pub fn profile(&self, name: &str) -> Option<EncodingProfile> {
128 unsafe {
129 from_glib_full(ffi::gst_encoding_target_get_profile(
130 self.to_glib_none().0,
131 name.to_glib_none().0,
132 ))
133 }
134 }
135
136 ///
137 /// # Returns
138 ///
139 /// A list of
140 /// [`EncodingProfile`][crate::EncodingProfile](s) this `self` handles.
141 #[doc(alias = "gst_encoding_target_get_profiles")]
142 #[doc(alias = "get_profiles")]
143 pub fn profiles(&self) -> Vec<EncodingProfile> {
144 unsafe {
145 FromGlibPtrContainer::from_glib_none(ffi::gst_encoding_target_get_profiles(
146 self.to_glib_none().0,
147 ))
148 }
149 }
150
151 /// Saves the `self` to a default user-local directory.
152 ///
153 /// # Returns
154 ///
155 /// [`true`] if the target was correctly saved, else [`false`].
156 #[doc(alias = "gst_encoding_target_save")]
157 pub fn save(&self) -> Result<(), glib::Error> {
158 unsafe {
159 let mut error = std::ptr::null_mut();
160 let is_ok = ffi::gst_encoding_target_save(self.to_glib_none().0, &mut error);
161 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
162 if error.is_null() {
163 Ok(())
164 } else {
165 Err(from_glib_full(error))
166 }
167 }
168 }
169
170 /// Saves the `self` to the provided file location.
171 /// ## `filepath`
172 /// the location to store the `self` at.
173 ///
174 /// # Returns
175 ///
176 /// [`true`] if the target was correctly saved, else [`false`].
177 #[doc(alias = "gst_encoding_target_save_to_file")]
178 pub fn save_to_file(&self, filepath: impl AsRef<std::path::Path>) -> Result<(), glib::Error> {
179 unsafe {
180 let mut error = std::ptr::null_mut();
181 let is_ok = ffi::gst_encoding_target_save_to_file(
182 self.to_glib_none().0,
183 filepath.as_ref().to_glib_none().0,
184 &mut error,
185 );
186 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
187 if error.is_null() {
188 Ok(())
189 } else {
190 Err(from_glib_full(error))
191 }
192 }
193 }
194
195 /// Searches for the [`EncodingTarget`][crate::EncodingTarget] with the given name, loads it
196 /// and returns it.
197 ///
198 /// If the category name is specified only targets from that category will be
199 /// searched for.
200 /// ## `name`
201 /// the name of the [`EncodingTarget`][crate::EncodingTarget] to load (automatically
202 /// converted to lower case internally as capital letters are not
203 /// valid for target names).
204 /// ## `category`
205 /// the name of the target category, like
206 /// `GST_ENCODING_CATEGORY_DEVICE`. Can be [`None`]
207 ///
208 /// # Returns
209 ///
210 /// The [`EncodingTarget`][crate::EncodingTarget] if available, else [`None`].
211 #[doc(alias = "gst_encoding_target_load")]
212 pub fn load(name: &str, category: Option<&str>) -> Result<EncodingTarget, glib::Error> {
213 assert_initialized_main_thread!();
214 unsafe {
215 let mut error = std::ptr::null_mut();
216 let ret = ffi::gst_encoding_target_load(
217 name.to_glib_none().0,
218 category.to_glib_none().0,
219 &mut error,
220 );
221 if error.is_null() {
222 Ok(from_glib_full(ret))
223 } else {
224 Err(from_glib_full(error))
225 }
226 }
227 }
228
229 /// Opens the provided file and returns the contained [`EncodingTarget`][crate::EncodingTarget].
230 /// ## `filepath`
231 /// The file location to load the [`EncodingTarget`][crate::EncodingTarget] from
232 ///
233 /// # Returns
234 ///
235 /// The [`EncodingTarget`][crate::EncodingTarget] contained in the file, else
236 /// [`None`]
237 #[doc(alias = "gst_encoding_target_load_from_file")]
238 pub fn load_from_file(
239 filepath: impl AsRef<std::path::Path>,
240 ) -> Result<EncodingTarget, glib::Error> {
241 assert_initialized_main_thread!();
242 unsafe {
243 let mut error = std::ptr::null_mut();
244 let ret = ffi::gst_encoding_target_load_from_file(
245 filepath.as_ref().to_glib_none().0,
246 &mut error,
247 );
248 if error.is_null() {
249 Ok(from_glib_full(ret))
250 } else {
251 Err(from_glib_full(error))
252 }
253 }
254 }
255}
256
257impl std::fmt::Display for EncodingTarget {
258 #[inline]
259 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
260 f.write_str(&self.name())
261 }
262}
263
264unsafe impl Send for EncodingTarget {}
265unsafe impl Sync for EncodingTarget {}