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    #[doc(alias = "GstEncodingTarget")]
11    pub struct EncodingTarget(Object<ffi::GstEncodingTarget>);
12
13    match fn {
14        type_ => || ffi::gst_encoding_target_get_type(),
15    }
16}
17
18impl EncodingTarget {
19    #[doc(alias = "gst_encoding_target_new")]
20    pub fn new(
21        name: &str,
22        category: &str,
23        description: &str,
24        profiles: &[EncodingProfile],
25    ) -> Result<EncodingTarget, glib::BoolError> {
26        assert_initialized_main_thread!();
27        unsafe {
28            Option::<_>::from_glib_full(ffi::gst_encoding_target_new(
29                name.to_glib_none().0,
30                category.to_glib_none().0,
31                description.to_glib_none().0,
32                profiles.to_glib_none().0,
33            ))
34            .ok_or_else(|| glib::bool_error!("Failed to create EncodingTarget"))
35        }
36    }
37
38    #[doc(alias = "gst_encoding_target_get_category")]
39    #[doc(alias = "get_category")]
40    pub fn category(&self) -> glib::GString {
41        unsafe { from_glib_none(ffi::gst_encoding_target_get_category(self.to_glib_none().0)) }
42    }
43
44    #[doc(alias = "gst_encoding_target_get_description")]
45    #[doc(alias = "get_description")]
46    pub fn description(&self) -> glib::GString {
47        unsafe {
48            from_glib_none(ffi::gst_encoding_target_get_description(
49                self.to_glib_none().0,
50            ))
51        }
52    }
53
54    #[doc(alias = "gst_encoding_target_get_name")]
55    #[doc(alias = "get_name")]
56    pub fn name(&self) -> glib::GString {
57        unsafe { from_glib_none(ffi::gst_encoding_target_get_name(self.to_glib_none().0)) }
58    }
59
60    #[cfg(feature = "v1_18")]
61    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
62    #[doc(alias = "gst_encoding_target_get_path")]
63    #[doc(alias = "get_path")]
64    pub fn path(&self) -> Option<std::path::PathBuf> {
65        unsafe { from_glib_none(ffi::gst_encoding_target_get_path(self.to_glib_none().0)) }
66    }
67
68    #[doc(alias = "gst_encoding_target_get_profile")]
69    #[doc(alias = "get_profile")]
70    pub fn profile(&self, name: &str) -> Option<EncodingProfile> {
71        unsafe {
72            from_glib_full(ffi::gst_encoding_target_get_profile(
73                self.to_glib_none().0,
74                name.to_glib_none().0,
75            ))
76        }
77    }
78
79    #[doc(alias = "gst_encoding_target_get_profiles")]
80    #[doc(alias = "get_profiles")]
81    pub fn profiles(&self) -> Vec<EncodingProfile> {
82        unsafe {
83            FromGlibPtrContainer::from_glib_none(ffi::gst_encoding_target_get_profiles(
84                self.to_glib_none().0,
85            ))
86        }
87    }
88
89    #[doc(alias = "gst_encoding_target_save")]
90    pub fn save(&self) -> Result<(), glib::Error> {
91        unsafe {
92            let mut error = std::ptr::null_mut();
93            let is_ok = ffi::gst_encoding_target_save(self.to_glib_none().0, &mut error);
94            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
95            if error.is_null() {
96                Ok(())
97            } else {
98                Err(from_glib_full(error))
99            }
100        }
101    }
102
103    #[doc(alias = "gst_encoding_target_save_to_file")]
104    pub fn save_to_file(&self, filepath: impl AsRef<std::path::Path>) -> Result<(), glib::Error> {
105        unsafe {
106            let mut error = std::ptr::null_mut();
107            let is_ok = ffi::gst_encoding_target_save_to_file(
108                self.to_glib_none().0,
109                filepath.as_ref().to_glib_none().0,
110                &mut error,
111            );
112            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
113            if error.is_null() {
114                Ok(())
115            } else {
116                Err(from_glib_full(error))
117            }
118        }
119    }
120
121    #[doc(alias = "gst_encoding_target_load")]
122    pub fn load(name: &str, category: Option<&str>) -> Result<EncodingTarget, glib::Error> {
123        assert_initialized_main_thread!();
124        unsafe {
125            let mut error = std::ptr::null_mut();
126            let ret = ffi::gst_encoding_target_load(
127                name.to_glib_none().0,
128                category.to_glib_none().0,
129                &mut error,
130            );
131            if error.is_null() {
132                Ok(from_glib_full(ret))
133            } else {
134                Err(from_glib_full(error))
135            }
136        }
137    }
138
139    #[doc(alias = "gst_encoding_target_load_from_file")]
140    pub fn load_from_file(
141        filepath: impl AsRef<std::path::Path>,
142    ) -> Result<EncodingTarget, glib::Error> {
143        assert_initialized_main_thread!();
144        unsafe {
145            let mut error = std::ptr::null_mut();
146            let ret = ffi::gst_encoding_target_load_from_file(
147                filepath.as_ref().to_glib_none().0,
148                &mut error,
149            );
150            if error.is_null() {
151                Ok(from_glib_full(ret))
152            } else {
153                Err(from_glib_full(error))
154            }
155        }
156    }
157}
158
159impl std::fmt::Display for EncodingTarget {
160    #[inline]
161    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
162        f.write_str(&self.name())
163    }
164}
165
166unsafe impl Send for EncodingTarget {}
167unsafe impl Sync for EncodingTarget {}