Skip to main content

gstreamer_mse/auto/
media_source.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::{
7    MediaSourceEOSError, MediaSourceRange, MediaSourceReadyState, MseSrc, SourceBuffer,
8    SourceBufferList, ffi,
9};
10use glib::{
11    object::ObjectType as _,
12    prelude::*,
13    signal::{SignalHandlerId, connect_raw},
14    translate::*,
15};
16use std::boxed::Box as Box_;
17
18glib::wrapper! {
19    #[doc(alias = "GstMediaSource")]
20    pub struct MediaSource(Object<ffi::GstMediaSource, ffi::GstMediaSourceClass>) @extends gst::Object;
21
22    match fn {
23        type_ => || ffi::gst_media_source_get_type(),
24    }
25}
26
27impl MediaSource {
28    #[doc(alias = "gst_media_source_new")]
29    pub fn new() -> MediaSource {
30        assert_initialized_main_thread!();
31        unsafe { from_glib_full(ffi::gst_media_source_new()) }
32    }
33
34    #[doc(alias = "gst_media_source_add_source_buffer")]
35    pub fn add_source_buffer(&self, type_: &str) -> Result<SourceBuffer, glib::Error> {
36        unsafe {
37            let mut error = std::ptr::null_mut();
38            let ret = ffi::gst_media_source_add_source_buffer(
39                self.to_glib_none().0,
40                type_.to_glib_none().0,
41                &mut error,
42            );
43            if error.is_null() {
44                Ok(from_glib_full(ret))
45            } else {
46                Err(from_glib_full(error))
47            }
48        }
49    }
50
51    #[doc(alias = "gst_media_source_attach")]
52    pub fn attach(&self, element: &MseSrc) {
53        unsafe {
54            ffi::gst_media_source_attach(self.to_glib_none().0, element.to_glib_none().0);
55        }
56    }
57
58    #[doc(alias = "gst_media_source_clear_live_seekable_range")]
59    pub fn clear_live_seekable_range(&self) -> Result<(), glib::Error> {
60        unsafe {
61            let mut error = std::ptr::null_mut();
62            let is_ok =
63                ffi::gst_media_source_clear_live_seekable_range(self.to_glib_none().0, &mut error);
64            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
65            if error.is_null() {
66                Ok(())
67            } else {
68                Err(from_glib_full(error))
69            }
70        }
71    }
72
73    #[doc(alias = "gst_media_source_detach")]
74    pub fn detach(&self) {
75        unsafe {
76            ffi::gst_media_source_detach(self.to_glib_none().0);
77        }
78    }
79
80    #[doc(alias = "gst_media_source_end_of_stream")]
81    pub fn end_of_stream(&self, eos_error: MediaSourceEOSError) -> Result<(), glib::Error> {
82        unsafe {
83            let mut error = std::ptr::null_mut();
84            let is_ok = ffi::gst_media_source_end_of_stream(
85                self.to_glib_none().0,
86                eos_error.into_glib(),
87                &mut error,
88            );
89            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
90            if error.is_null() {
91                Ok(())
92            } else {
93                Err(from_glib_full(error))
94            }
95        }
96    }
97
98    #[doc(alias = "gst_media_source_get_active_source_buffers")]
99    #[doc(alias = "get_active_source_buffers")]
100    #[doc(alias = "active-source-buffers")]
101    pub fn active_source_buffers(&self) -> SourceBufferList {
102        unsafe {
103            from_glib_full(ffi::gst_media_source_get_active_source_buffers(
104                self.to_glib_none().0,
105            ))
106        }
107    }
108
109    #[doc(alias = "gst_media_source_get_duration")]
110    #[doc(alias = "get_duration")]
111    pub fn duration(&self) -> Option<gst::ClockTime> {
112        unsafe { from_glib(ffi::gst_media_source_get_duration(self.to_glib_none().0)) }
113    }
114
115    #[doc(alias = "gst_media_source_get_live_seekable_range")]
116    #[doc(alias = "get_live_seekable_range")]
117    pub fn live_seekable_range(&self) -> MediaSourceRange {
118        unsafe {
119            let mut range = MediaSourceRange::uninitialized();
120            ffi::gst_media_source_get_live_seekable_range(
121                self.to_glib_none().0,
122                range.to_glib_none_mut().0,
123            );
124            range
125        }
126    }
127
128    #[doc(alias = "gst_media_source_get_position")]
129    #[doc(alias = "get_position")]
130    pub fn position(&self) -> Option<gst::ClockTime> {
131        unsafe { from_glib(ffi::gst_media_source_get_position(self.to_glib_none().0)) }
132    }
133
134    #[doc(alias = "gst_media_source_get_ready_state")]
135    #[doc(alias = "get_ready_state")]
136    #[doc(alias = "ready-state")]
137    pub fn ready_state(&self) -> MediaSourceReadyState {
138        unsafe { from_glib(ffi::gst_media_source_get_ready_state(self.to_glib_none().0)) }
139    }
140
141    #[doc(alias = "gst_media_source_get_source_buffers")]
142    #[doc(alias = "get_source_buffers")]
143    #[doc(alias = "source-buffers")]
144    pub fn source_buffers(&self) -> SourceBufferList {
145        unsafe {
146            from_glib_full(ffi::gst_media_source_get_source_buffers(
147                self.to_glib_none().0,
148            ))
149        }
150    }
151
152    #[doc(alias = "gst_media_source_remove_source_buffer")]
153    pub fn remove_source_buffer(&self, buffer: &SourceBuffer) -> Result<(), glib::Error> {
154        unsafe {
155            let mut error = std::ptr::null_mut();
156            let is_ok = ffi::gst_media_source_remove_source_buffer(
157                self.to_glib_none().0,
158                buffer.to_glib_none().0,
159                &mut error,
160            );
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    #[doc(alias = "gst_media_source_set_duration")]
171    #[doc(alias = "duration")]
172    pub fn set_duration(
173        &self,
174        duration: impl Into<Option<gst::ClockTime>>,
175    ) -> Result<(), glib::Error> {
176        unsafe {
177            let mut error = std::ptr::null_mut();
178            let is_ok = ffi::gst_media_source_set_duration(
179                self.to_glib_none().0,
180                duration.into().into_glib(),
181                &mut error,
182            );
183            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
184            if error.is_null() {
185                Ok(())
186            } else {
187                Err(from_glib_full(error))
188            }
189        }
190    }
191
192    #[doc(alias = "gst_media_source_set_live_seekable_range")]
193    pub fn set_live_seekable_range(
194        &self,
195        start: impl Into<Option<gst::ClockTime>>,
196        end: impl Into<Option<gst::ClockTime>>,
197    ) -> Result<(), glib::Error> {
198        unsafe {
199            let mut error = std::ptr::null_mut();
200            let is_ok = ffi::gst_media_source_set_live_seekable_range(
201                self.to_glib_none().0,
202                start.into().into_glib(),
203                end.into().into_glib(),
204                &mut error,
205            );
206            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
207            if error.is_null() {
208                Ok(())
209            } else {
210                Err(from_glib_full(error))
211            }
212        }
213    }
214
215    #[doc(alias = "gst_media_source_is_type_supported")]
216    pub fn is_type_supported(type_: &str) -> bool {
217        assert_initialized_main_thread!();
218        unsafe {
219            from_glib(ffi::gst_media_source_is_type_supported(
220                type_.to_glib_none().0,
221            ))
222        }
223    }
224
225    #[doc(alias = "on-source-close")]
226    pub fn connect_on_source_close<F: Fn(&Self) + Send + Sync + 'static>(
227        &self,
228        f: F,
229    ) -> SignalHandlerId {
230        unsafe extern "C" fn on_source_close_trampoline<
231            F: Fn(&MediaSource) + Send + Sync + 'static,
232        >(
233            this: *mut ffi::GstMediaSource,
234            f: glib::ffi::gpointer,
235        ) {
236            unsafe {
237                let f: &F = &*(f as *const F);
238                f(&from_glib_borrow(this))
239            }
240        }
241        unsafe {
242            let f: Box_<F> = Box_::new(f);
243            connect_raw(
244                self.as_ptr() as *mut _,
245                c"on-source-close".as_ptr(),
246                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
247                    on_source_close_trampoline::<F> as *const (),
248                )),
249                Box_::into_raw(f),
250            )
251        }
252    }
253
254    #[doc(alias = "on-source-ended")]
255    pub fn connect_on_source_ended<F: Fn(&Self) + Send + Sync + 'static>(
256        &self,
257        f: F,
258    ) -> SignalHandlerId {
259        unsafe extern "C" fn on_source_ended_trampoline<
260            F: Fn(&MediaSource) + Send + Sync + 'static,
261        >(
262            this: *mut ffi::GstMediaSource,
263            f: glib::ffi::gpointer,
264        ) {
265            unsafe {
266                let f: &F = &*(f as *const F);
267                f(&from_glib_borrow(this))
268            }
269        }
270        unsafe {
271            let f: Box_<F> = Box_::new(f);
272            connect_raw(
273                self.as_ptr() as *mut _,
274                c"on-source-ended".as_ptr(),
275                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
276                    on_source_ended_trampoline::<F> as *const (),
277                )),
278                Box_::into_raw(f),
279            )
280        }
281    }
282
283    #[doc(alias = "on-source-open")]
284    pub fn connect_on_source_open<F: Fn(&Self) + Send + Sync + 'static>(
285        &self,
286        f: F,
287    ) -> SignalHandlerId {
288        unsafe extern "C" fn on_source_open_trampoline<
289            F: Fn(&MediaSource) + Send + Sync + 'static,
290        >(
291            this: *mut ffi::GstMediaSource,
292            f: glib::ffi::gpointer,
293        ) {
294            unsafe {
295                let f: &F = &*(f as *const F);
296                f(&from_glib_borrow(this))
297            }
298        }
299        unsafe {
300            let f: Box_<F> = Box_::new(f);
301            connect_raw(
302                self.as_ptr() as *mut _,
303                c"on-source-open".as_ptr(),
304                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
305                    on_source_open_trampoline::<F> as *const (),
306                )),
307                Box_::into_raw(f),
308            )
309        }
310    }
311
312    #[doc(alias = "active-source-buffers")]
313    pub fn connect_active_source_buffers_notify<F: Fn(&Self) + Send + Sync + 'static>(
314        &self,
315        f: F,
316    ) -> SignalHandlerId {
317        unsafe extern "C" fn notify_active_source_buffers_trampoline<
318            F: Fn(&MediaSource) + Send + Sync + 'static,
319        >(
320            this: *mut ffi::GstMediaSource,
321            _param_spec: glib::ffi::gpointer,
322            f: glib::ffi::gpointer,
323        ) {
324            unsafe {
325                let f: &F = &*(f as *const F);
326                f(&from_glib_borrow(this))
327            }
328        }
329        unsafe {
330            let f: Box_<F> = Box_::new(f);
331            connect_raw(
332                self.as_ptr() as *mut _,
333                c"notify::active-source-buffers".as_ptr(),
334                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
335                    notify_active_source_buffers_trampoline::<F> as *const (),
336                )),
337                Box_::into_raw(f),
338            )
339        }
340    }
341
342    #[doc(alias = "duration")]
343    pub fn connect_duration_notify<F: Fn(&Self) + Send + Sync + 'static>(
344        &self,
345        f: F,
346    ) -> SignalHandlerId {
347        unsafe extern "C" fn notify_duration_trampoline<
348            F: Fn(&MediaSource) + Send + Sync + 'static,
349        >(
350            this: *mut ffi::GstMediaSource,
351            _param_spec: glib::ffi::gpointer,
352            f: glib::ffi::gpointer,
353        ) {
354            unsafe {
355                let f: &F = &*(f as *const F);
356                f(&from_glib_borrow(this))
357            }
358        }
359        unsafe {
360            let f: Box_<F> = Box_::new(f);
361            connect_raw(
362                self.as_ptr() as *mut _,
363                c"notify::duration".as_ptr(),
364                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
365                    notify_duration_trampoline::<F> as *const (),
366                )),
367                Box_::into_raw(f),
368            )
369        }
370    }
371
372    #[doc(alias = "position")]
373    pub fn connect_position_notify<F: Fn(&Self) + Send + Sync + 'static>(
374        &self,
375        f: F,
376    ) -> SignalHandlerId {
377        unsafe extern "C" fn notify_position_trampoline<
378            F: Fn(&MediaSource) + Send + Sync + 'static,
379        >(
380            this: *mut ffi::GstMediaSource,
381            _param_spec: glib::ffi::gpointer,
382            f: glib::ffi::gpointer,
383        ) {
384            unsafe {
385                let f: &F = &*(f as *const F);
386                f(&from_glib_borrow(this))
387            }
388        }
389        unsafe {
390            let f: Box_<F> = Box_::new(f);
391            connect_raw(
392                self.as_ptr() as *mut _,
393                c"notify::position".as_ptr(),
394                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
395                    notify_position_trampoline::<F> as *const (),
396                )),
397                Box_::into_raw(f),
398            )
399        }
400    }
401
402    #[doc(alias = "ready-state")]
403    pub fn connect_ready_state_notify<F: Fn(&Self) + Send + Sync + 'static>(
404        &self,
405        f: F,
406    ) -> SignalHandlerId {
407        unsafe extern "C" fn notify_ready_state_trampoline<
408            F: Fn(&MediaSource) + Send + Sync + 'static,
409        >(
410            this: *mut ffi::GstMediaSource,
411            _param_spec: glib::ffi::gpointer,
412            f: glib::ffi::gpointer,
413        ) {
414            unsafe {
415                let f: &F = &*(f as *const F);
416                f(&from_glib_borrow(this))
417            }
418        }
419        unsafe {
420            let f: Box_<F> = Box_::new(f);
421            connect_raw(
422                self.as_ptr() as *mut _,
423                c"notify::ready-state".as_ptr(),
424                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
425                    notify_ready_state_trampoline::<F> as *const (),
426                )),
427                Box_::into_raw(f),
428            )
429        }
430    }
431
432    #[doc(alias = "source-buffers")]
433    pub fn connect_source_buffers_notify<F: Fn(&Self) + Send + Sync + 'static>(
434        &self,
435        f: F,
436    ) -> SignalHandlerId {
437        unsafe extern "C" fn notify_source_buffers_trampoline<
438            F: Fn(&MediaSource) + Send + Sync + 'static,
439        >(
440            this: *mut ffi::GstMediaSource,
441            _param_spec: glib::ffi::gpointer,
442            f: glib::ffi::gpointer,
443        ) {
444            unsafe {
445                let f: &F = &*(f as *const F);
446                f(&from_glib_borrow(this))
447            }
448        }
449        unsafe {
450            let f: Box_<F> = Box_::new(f);
451            connect_raw(
452                self.as_ptr() as *mut _,
453                c"notify::source-buffers".as_ptr(),
454                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
455                    notify_source_buffers_trampoline::<F> as *const (),
456                )),
457                Box_::into_raw(f),
458            )
459        }
460    }
461}
462
463impl Default for MediaSource {
464    fn default() -> Self {
465        Self::new()
466    }
467}
468
469unsafe impl Send for MediaSource {}
470unsafe impl Sync for MediaSource {}