1use crate::{Caps, Object, StreamFlags, StreamType, TagList, ffi};
7use glib::{
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GstStream")]
16 pub struct Stream(Object<ffi::GstStream, ffi::GstStreamClass>) @extends Object;
17
18 match fn {
19 type_ => || ffi::gst_stream_get_type(),
20 }
21}
22
23impl Stream {
24 #[doc(alias = "gst_stream_new")]
25 pub fn new(
26 stream_id: Option<&str>,
27 caps: Option<&Caps>,
28 type_: StreamType,
29 flags: StreamFlags,
30 ) -> Stream {
31 assert_initialized_main_thread!();
32 unsafe {
33 from_glib_full(ffi::gst_stream_new(
34 stream_id.to_glib_none().0,
35 caps.to_glib_none().0,
36 type_.into_glib(),
37 flags.into_glib(),
38 ))
39 }
40 }
41
42 #[doc(alias = "gst_stream_get_caps")]
43 #[doc(alias = "get_caps")]
44 pub fn caps(&self) -> Option<Caps> {
45 unsafe { from_glib_full(ffi::gst_stream_get_caps(self.to_glib_none().0)) }
46 }
47
48 #[doc(alias = "gst_stream_get_stream_flags")]
49 #[doc(alias = "get_stream_flags")]
50 #[doc(alias = "stream-flags")]
51 pub fn stream_flags(&self) -> StreamFlags {
52 unsafe { from_glib(ffi::gst_stream_get_stream_flags(self.to_glib_none().0)) }
53 }
54
55 #[doc(alias = "gst_stream_get_stream_id")]
56 #[doc(alias = "get_stream_id")]
57 #[doc(alias = "stream-id")]
58 pub fn stream_id(&self) -> Option<glib::GString> {
59 unsafe { from_glib_none(ffi::gst_stream_get_stream_id(self.to_glib_none().0)) }
60 }
61
62 #[doc(alias = "gst_stream_get_stream_type")]
63 #[doc(alias = "get_stream_type")]
64 #[doc(alias = "stream-type")]
65 pub fn stream_type(&self) -> StreamType {
66 unsafe { from_glib(ffi::gst_stream_get_stream_type(self.to_glib_none().0)) }
67 }
68
69 #[doc(alias = "gst_stream_get_tags")]
70 #[doc(alias = "get_tags")]
71 pub fn tags(&self) -> Option<TagList> {
72 unsafe { from_glib_full(ffi::gst_stream_get_tags(self.to_glib_none().0)) }
73 }
74
75 #[doc(alias = "gst_stream_set_caps")]
76 #[doc(alias = "caps")]
77 pub fn set_caps(&self, caps: Option<&Caps>) {
78 unsafe {
79 ffi::gst_stream_set_caps(self.to_glib_none().0, caps.to_glib_none().0);
80 }
81 }
82
83 #[doc(alias = "gst_stream_set_stream_flags")]
84 #[doc(alias = "stream-flags")]
85 pub fn set_stream_flags(&self, flags: StreamFlags) {
86 unsafe {
87 ffi::gst_stream_set_stream_flags(self.to_glib_none().0, flags.into_glib());
88 }
89 }
90
91 #[doc(alias = "gst_stream_set_stream_type")]
92 #[doc(alias = "stream-type")]
93 pub fn set_stream_type(&self, stream_type: StreamType) {
94 unsafe {
95 ffi::gst_stream_set_stream_type(self.to_glib_none().0, stream_type.into_glib());
96 }
97 }
98
99 #[doc(alias = "gst_stream_set_tags")]
100 #[doc(alias = "tags")]
101 pub fn set_tags(&self, tags: Option<&TagList>) {
102 unsafe {
103 ffi::gst_stream_set_tags(self.to_glib_none().0, tags.to_glib_none().0);
104 }
105 }
106
107 #[doc(alias = "caps")]
108 pub fn connect_caps_notify<F: Fn(&Self) + Send + Sync + 'static>(
109 &self,
110 f: F,
111 ) -> SignalHandlerId {
112 unsafe extern "C" fn notify_caps_trampoline<F: Fn(&Stream) + Send + Sync + 'static>(
113 this: *mut ffi::GstStream,
114 _param_spec: glib::ffi::gpointer,
115 f: glib::ffi::gpointer,
116 ) {
117 unsafe {
118 let f: &F = &*(f as *const F);
119 f(&from_glib_borrow(this))
120 }
121 }
122 unsafe {
123 let f: Box_<F> = Box_::new(f);
124 connect_raw(
125 self.as_ptr() as *mut _,
126 c"notify::caps".as_ptr(),
127 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
128 notify_caps_trampoline::<F> as *const (),
129 )),
130 Box_::into_raw(f),
131 )
132 }
133 }
134
135 #[doc(alias = "stream-flags")]
136 pub fn connect_stream_flags_notify<F: Fn(&Self) + Send + Sync + 'static>(
137 &self,
138 f: F,
139 ) -> SignalHandlerId {
140 unsafe extern "C" fn notify_stream_flags_trampoline<
141 F: Fn(&Stream) + Send + Sync + 'static,
142 >(
143 this: *mut ffi::GstStream,
144 _param_spec: glib::ffi::gpointer,
145 f: glib::ffi::gpointer,
146 ) {
147 unsafe {
148 let f: &F = &*(f as *const F);
149 f(&from_glib_borrow(this))
150 }
151 }
152 unsafe {
153 let f: Box_<F> = Box_::new(f);
154 connect_raw(
155 self.as_ptr() as *mut _,
156 c"notify::stream-flags".as_ptr(),
157 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
158 notify_stream_flags_trampoline::<F> as *const (),
159 )),
160 Box_::into_raw(f),
161 )
162 }
163 }
164
165 #[doc(alias = "stream-type")]
166 pub fn connect_stream_type_notify<F: Fn(&Self) + Send + Sync + 'static>(
167 &self,
168 f: F,
169 ) -> SignalHandlerId {
170 unsafe extern "C" fn notify_stream_type_trampoline<
171 F: Fn(&Stream) + Send + Sync + 'static,
172 >(
173 this: *mut ffi::GstStream,
174 _param_spec: glib::ffi::gpointer,
175 f: glib::ffi::gpointer,
176 ) {
177 unsafe {
178 let f: &F = &*(f as *const F);
179 f(&from_glib_borrow(this))
180 }
181 }
182 unsafe {
183 let f: Box_<F> = Box_::new(f);
184 connect_raw(
185 self.as_ptr() as *mut _,
186 c"notify::stream-type".as_ptr(),
187 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
188 notify_stream_type_trampoline::<F> as *const (),
189 )),
190 Box_::into_raw(f),
191 )
192 }
193 }
194
195 #[doc(alias = "tags")]
196 pub fn connect_tags_notify<F: Fn(&Self) + Send + Sync + 'static>(
197 &self,
198 f: F,
199 ) -> SignalHandlerId {
200 unsafe extern "C" fn notify_tags_trampoline<F: Fn(&Stream) + Send + Sync + 'static>(
201 this: *mut ffi::GstStream,
202 _param_spec: glib::ffi::gpointer,
203 f: glib::ffi::gpointer,
204 ) {
205 unsafe {
206 let f: &F = &*(f as *const F);
207 f(&from_glib_borrow(this))
208 }
209 }
210 unsafe {
211 let f: Box_<F> = Box_::new(f);
212 connect_raw(
213 self.as_ptr() as *mut _,
214 c"notify::tags".as_ptr(),
215 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
216 notify_tags_trampoline::<F> as *const (),
217 )),
218 Box_::into_raw(f),
219 )
220 }
221 }
222}
223
224unsafe impl Send for Stream {}
225unsafe impl Sync for Stream {}