gstreamer/auto/
stream.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, Caps, Object, StreamFlags, StreamType, TagList};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// A high-level object representing a single stream. It might be backed, or
16    /// not, by an actual flow of data in a pipeline ([`Pad`][crate::Pad]).
17    ///
18    /// A [`Stream`][crate::Stream] does not care about data changes (such as decoding, encoding,
19    /// parsing,...) as long as the underlying data flow corresponds to the same
20    /// high-level flow (ex: a certain audio track).
21    ///
22    /// A [`Stream`][crate::Stream] contains all the information pertinent to a stream, such as
23    /// stream-id, tags, caps, type, ...
24    ///
25    /// Elements can subclass a [`Stream`][crate::Stream] for internal usage (to contain information
26    /// pertinent to streams of data).
27    ///
28    /// ## Properties
29    ///
30    ///
31    /// #### `caps`
32    ///  The [`Caps`][crate::Caps] of the [`Stream`][crate::Stream].
33    ///
34    /// Readable | Writeable
35    ///
36    ///
37    /// #### `stream-flags`
38    ///  Readable | Writeable | Construct
39    ///
40    ///
41    /// #### `stream-id`
42    ///  The unique identifier of the [`Stream`][crate::Stream]. Can only be set at construction
43    /// time.
44    ///
45    /// Readable | Writeable | Construct Only
46    ///
47    ///
48    /// #### `stream-type`
49    ///  The [`StreamType`][crate::StreamType] of the [`Stream`][crate::Stream]. Can only be set at construction time.
50    ///
51    /// Readable | Writeable | Construct
52    ///
53    ///
54    /// #### `tags`
55    ///  The [`TagList`][crate::TagList] of the [`Stream`][crate::Stream].
56    ///
57    /// Readable | Writeable
58    /// <details><summary><h4>Object</h4></summary>
59    ///
60    ///
61    /// #### `name`
62    ///  Readable | Writeable | Construct
63    ///
64    ///
65    /// #### `parent`
66    ///  The parent of the object. Please note, that when changing the 'parent'
67    /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::Object#deep-notify]
68    /// signals due to locking issues. In some cases one can use
69    /// [`element-added`][struct@crate::Bin#element-added] or [`element-removed`][struct@crate::Bin#element-removed] signals on the parent to
70    /// achieve a similar effect.
71    ///
72    /// Readable | Writeable
73    /// </details>
74    ///
75    /// # Implements
76    ///
77    /// [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`]
78    #[doc(alias = "GstStream")]
79    pub struct Stream(Object<ffi::GstStream, ffi::GstStreamClass>) @extends Object;
80
81    match fn {
82        type_ => || ffi::gst_stream_get_type(),
83    }
84}
85
86impl Stream {
87    /// Create a new [`Stream`][crate::Stream] for the given `stream_id`, `caps`, `type_`
88    /// and `flags`
89    /// ## `stream_id`
90    /// the id for the new stream. If [`None`],
91    /// a new one will be automatically generated
92    /// ## `caps`
93    /// the [`Caps`][crate::Caps] of the stream
94    /// ## `type_`
95    /// the [`StreamType`][crate::StreamType] of the stream
96    /// ## `flags`
97    /// the [`StreamFlags`][crate::StreamFlags] of the stream
98    ///
99    /// # Returns
100    ///
101    /// The new [`Stream`][crate::Stream]
102    #[doc(alias = "gst_stream_new")]
103    pub fn new(
104        stream_id: Option<&str>,
105        caps: Option<&Caps>,
106        type_: StreamType,
107        flags: StreamFlags,
108    ) -> Stream {
109        assert_initialized_main_thread!();
110        unsafe {
111            from_glib_full(ffi::gst_stream_new(
112                stream_id.to_glib_none().0,
113                caps.to_glib_none().0,
114                type_.into_glib(),
115                flags.into_glib(),
116            ))
117        }
118    }
119
120    /// Retrieve the caps for `self`, if any
121    ///
122    /// # Returns
123    ///
124    /// The [`Caps`][crate::Caps] for `self`
125    #[doc(alias = "gst_stream_get_caps")]
126    #[doc(alias = "get_caps")]
127    pub fn caps(&self) -> Option<Caps> {
128        unsafe { from_glib_full(ffi::gst_stream_get_caps(self.to_glib_none().0)) }
129    }
130
131    /// Retrieve the current stream flags for `self`
132    ///
133    /// # Returns
134    ///
135    /// The [`StreamFlags`][crate::StreamFlags] for `self`
136    #[doc(alias = "gst_stream_get_stream_flags")]
137    #[doc(alias = "get_stream_flags")]
138    #[doc(alias = "stream-flags")]
139    pub fn stream_flags(&self) -> StreamFlags {
140        unsafe { from_glib(ffi::gst_stream_get_stream_flags(self.to_glib_none().0)) }
141    }
142
143    /// Returns the stream ID of `self`.
144    ///
145    /// # Returns
146    ///
147    /// the stream ID of `self`. Only valid
148    /// during the lifetime of `self`.
149    #[doc(alias = "gst_stream_get_stream_id")]
150    #[doc(alias = "get_stream_id")]
151    #[doc(alias = "stream-id")]
152    pub fn stream_id(&self) -> Option<glib::GString> {
153        unsafe { from_glib_none(ffi::gst_stream_get_stream_id(self.to_glib_none().0)) }
154    }
155
156    /// Retrieve the stream type for `self`
157    ///
158    /// # Returns
159    ///
160    /// The [`StreamType`][crate::StreamType] for `self`
161    #[doc(alias = "gst_stream_get_stream_type")]
162    #[doc(alias = "get_stream_type")]
163    #[doc(alias = "stream-type")]
164    pub fn stream_type(&self) -> StreamType {
165        unsafe { from_glib(ffi::gst_stream_get_stream_type(self.to_glib_none().0)) }
166    }
167
168    /// Retrieve the tags for `self`, if any
169    ///
170    /// # Returns
171    ///
172    /// The [`TagList`][crate::TagList] for `self`
173    #[doc(alias = "gst_stream_get_tags")]
174    #[doc(alias = "get_tags")]
175    pub fn tags(&self) -> Option<TagList> {
176        unsafe { from_glib_full(ffi::gst_stream_get_tags(self.to_glib_none().0)) }
177    }
178
179    /// Set the caps for the [`Stream`][crate::Stream]
180    /// ## `caps`
181    /// a [`Caps`][crate::Caps]
182    #[doc(alias = "gst_stream_set_caps")]
183    #[doc(alias = "caps")]
184    pub fn set_caps(&self, caps: Option<&Caps>) {
185        unsafe {
186            ffi::gst_stream_set_caps(self.to_glib_none().0, caps.to_glib_none().0);
187        }
188    }
189
190    /// Set the `flags` for the `self`.
191    /// ## `flags`
192    /// the flags to set on `self`
193    #[doc(alias = "gst_stream_set_stream_flags")]
194    #[doc(alias = "stream-flags")]
195    pub fn set_stream_flags(&self, flags: StreamFlags) {
196        unsafe {
197            ffi::gst_stream_set_stream_flags(self.to_glib_none().0, flags.into_glib());
198        }
199    }
200
201    /// Set the stream type of `self`
202    /// ## `stream_type`
203    /// the type to set on `self`
204    #[doc(alias = "gst_stream_set_stream_type")]
205    #[doc(alias = "stream-type")]
206    pub fn set_stream_type(&self, stream_type: StreamType) {
207        unsafe {
208            ffi::gst_stream_set_stream_type(self.to_glib_none().0, stream_type.into_glib());
209        }
210    }
211
212    /// Set the tags for the [`Stream`][crate::Stream]
213    /// ## `tags`
214    /// a [`TagList`][crate::TagList]
215    #[doc(alias = "gst_stream_set_tags")]
216    #[doc(alias = "tags")]
217    pub fn set_tags(&self, tags: Option<&TagList>) {
218        unsafe {
219            ffi::gst_stream_set_tags(self.to_glib_none().0, tags.to_glib_none().0);
220        }
221    }
222
223    #[doc(alias = "caps")]
224    pub fn connect_caps_notify<F: Fn(&Self) + Send + Sync + 'static>(
225        &self,
226        f: F,
227    ) -> SignalHandlerId {
228        unsafe extern "C" fn notify_caps_trampoline<F: Fn(&Stream) + Send + Sync + 'static>(
229            this: *mut ffi::GstStream,
230            _param_spec: glib::ffi::gpointer,
231            f: glib::ffi::gpointer,
232        ) {
233            let f: &F = &*(f as *const F);
234            f(&from_glib_borrow(this))
235        }
236        unsafe {
237            let f: Box_<F> = Box_::new(f);
238            connect_raw(
239                self.as_ptr() as *mut _,
240                c"notify::caps".as_ptr() as *const _,
241                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
242                    notify_caps_trampoline::<F> as *const (),
243                )),
244                Box_::into_raw(f),
245            )
246        }
247    }
248
249    #[doc(alias = "stream-flags")]
250    pub fn connect_stream_flags_notify<F: Fn(&Self) + Send + Sync + 'static>(
251        &self,
252        f: F,
253    ) -> SignalHandlerId {
254        unsafe extern "C" fn notify_stream_flags_trampoline<
255            F: Fn(&Stream) + Send + Sync + 'static,
256        >(
257            this: *mut ffi::GstStream,
258            _param_spec: glib::ffi::gpointer,
259            f: glib::ffi::gpointer,
260        ) {
261            let f: &F = &*(f as *const F);
262            f(&from_glib_borrow(this))
263        }
264        unsafe {
265            let f: Box_<F> = Box_::new(f);
266            connect_raw(
267                self.as_ptr() as *mut _,
268                c"notify::stream-flags".as_ptr() as *const _,
269                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
270                    notify_stream_flags_trampoline::<F> as *const (),
271                )),
272                Box_::into_raw(f),
273            )
274        }
275    }
276
277    #[doc(alias = "stream-type")]
278    pub fn connect_stream_type_notify<F: Fn(&Self) + Send + Sync + 'static>(
279        &self,
280        f: F,
281    ) -> SignalHandlerId {
282        unsafe extern "C" fn notify_stream_type_trampoline<
283            F: Fn(&Stream) + Send + Sync + 'static,
284        >(
285            this: *mut ffi::GstStream,
286            _param_spec: glib::ffi::gpointer,
287            f: glib::ffi::gpointer,
288        ) {
289            let f: &F = &*(f as *const F);
290            f(&from_glib_borrow(this))
291        }
292        unsafe {
293            let f: Box_<F> = Box_::new(f);
294            connect_raw(
295                self.as_ptr() as *mut _,
296                c"notify::stream-type".as_ptr() as *const _,
297                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
298                    notify_stream_type_trampoline::<F> as *const (),
299                )),
300                Box_::into_raw(f),
301            )
302        }
303    }
304
305    #[doc(alias = "tags")]
306    pub fn connect_tags_notify<F: Fn(&Self) + Send + Sync + 'static>(
307        &self,
308        f: F,
309    ) -> SignalHandlerId {
310        unsafe extern "C" fn notify_tags_trampoline<F: Fn(&Stream) + Send + Sync + 'static>(
311            this: *mut ffi::GstStream,
312            _param_spec: glib::ffi::gpointer,
313            f: glib::ffi::gpointer,
314        ) {
315            let f: &F = &*(f as *const F);
316            f(&from_glib_borrow(this))
317        }
318        unsafe {
319            let f: Box_<F> = Box_::new(f);
320            connect_raw(
321                self.as_ptr() as *mut _,
322                c"notify::tags".as_ptr() as *const _,
323                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
324                    notify_tags_trampoline::<F> as *const (),
325                )),
326                Box_::into_raw(f),
327            )
328        }
329    }
330}
331
332unsafe impl Send for Stream {}
333unsafe impl Sync for Stream {}