1use crate::{SourceBufferAppendMode, ffi};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{SignalHandlerId, connect_raw},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 #[doc(alias = "GstSourceBuffer")]
17 pub struct SourceBuffer(Object<ffi::GstSourceBuffer, ffi::GstSourceBufferClass>) @extends gst::Object;
18
19 match fn {
20 type_ => || ffi::gst_source_buffer_get_type(),
21 }
22}
23
24impl SourceBuffer {
25 #[doc(alias = "gst_source_buffer_abort")]
26 pub fn abort(&self) -> Result<(), glib::Error> {
27 unsafe {
28 let mut error = std::ptr::null_mut();
29 let is_ok = ffi::gst_source_buffer_abort(self.to_glib_none().0, &mut error);
30 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
31 if error.is_null() {
32 Ok(())
33 } else {
34 Err(from_glib_full(error))
35 }
36 }
37 }
38
39 #[doc(alias = "gst_source_buffer_append_buffer")]
40 pub fn append_buffer(&self, buf: gst::Buffer) -> Result<(), glib::Error> {
41 unsafe {
42 let mut error = std::ptr::null_mut();
43 let is_ok = ffi::gst_source_buffer_append_buffer(
44 self.to_glib_none().0,
45 buf.into_glib_ptr(),
46 &mut error,
47 );
48 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
49 if error.is_null() {
50 Ok(())
51 } else {
52 Err(from_glib_full(error))
53 }
54 }
55 }
56
57 #[doc(alias = "gst_source_buffer_change_content_type")]
58 pub fn change_content_type(&self, type_: &str) -> Result<(), glib::Error> {
59 unsafe {
60 let mut error = std::ptr::null_mut();
61 let is_ok = ffi::gst_source_buffer_change_content_type(
62 self.to_glib_none().0,
63 type_.to_glib_none().0,
64 &mut error,
65 );
66 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
67 if error.is_null() {
68 Ok(())
69 } else {
70 Err(from_glib_full(error))
71 }
72 }
73 }
74
75 #[doc(alias = "gst_source_buffer_get_append_mode")]
76 #[doc(alias = "get_append_mode")]
77 #[doc(alias = "append-mode")]
78 pub fn append_mode(&self) -> SourceBufferAppendMode {
79 unsafe {
80 from_glib(ffi::gst_source_buffer_get_append_mode(
81 self.to_glib_none().0,
82 ))
83 }
84 }
85
86 #[doc(alias = "gst_source_buffer_get_append_window_end")]
87 #[doc(alias = "get_append_window_end")]
88 #[doc(alias = "append-window-end")]
89 pub fn append_window_end(&self) -> Option<gst::ClockTime> {
90 unsafe {
91 from_glib(ffi::gst_source_buffer_get_append_window_end(
92 self.to_glib_none().0,
93 ))
94 }
95 }
96
97 #[doc(alias = "gst_source_buffer_get_append_window_start")]
98 #[doc(alias = "get_append_window_start")]
99 #[doc(alias = "append-window-start")]
100 pub fn append_window_start(&self) -> Option<gst::ClockTime> {
101 unsafe {
102 from_glib(ffi::gst_source_buffer_get_append_window_start(
103 self.to_glib_none().0,
104 ))
105 }
106 }
107
108 #[doc(alias = "gst_source_buffer_get_content_type")]
115 #[doc(alias = "get_content_type")]
116 #[doc(alias = "content-type")]
117 pub fn content_type(&self) -> glib::GString {
118 unsafe {
119 from_glib_full(ffi::gst_source_buffer_get_content_type(
120 self.to_glib_none().0,
121 ))
122 }
123 }
124
125 #[doc(alias = "gst_source_buffer_get_timestamp_offset")]
126 #[doc(alias = "get_timestamp_offset")]
127 #[doc(alias = "timestamp-offset")]
128 pub fn timestamp_offset(&self) -> Option<gst::ClockTime> {
129 unsafe {
130 from_glib(ffi::gst_source_buffer_get_timestamp_offset(
131 self.to_glib_none().0,
132 ))
133 }
134 }
135
136 #[doc(alias = "gst_source_buffer_get_updating")]
137 #[doc(alias = "get_updating")]
138 #[doc(alias = "updating")]
139 pub fn is_updating(&self) -> bool {
140 unsafe { from_glib(ffi::gst_source_buffer_get_updating(self.to_glib_none().0)) }
141 }
142
143 #[doc(alias = "gst_source_buffer_remove")]
144 pub fn remove(
145 &self,
146 start: impl Into<Option<gst::ClockTime>>,
147 end: impl Into<Option<gst::ClockTime>>,
148 ) -> Result<(), glib::Error> {
149 unsafe {
150 let mut error = std::ptr::null_mut();
151 let is_ok = ffi::gst_source_buffer_remove(
152 self.to_glib_none().0,
153 start.into().into_glib(),
154 end.into().into_glib(),
155 &mut error,
156 );
157 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
158 if error.is_null() {
159 Ok(())
160 } else {
161 Err(from_glib_full(error))
162 }
163 }
164 }
165
166 #[doc(alias = "gst_source_buffer_set_append_mode")]
167 #[doc(alias = "append-mode")]
168 pub fn set_append_mode(&self, mode: SourceBufferAppendMode) -> Result<(), glib::Error> {
169 unsafe {
170 let mut error = std::ptr::null_mut();
171 let is_ok = ffi::gst_source_buffer_set_append_mode(
172 self.to_glib_none().0,
173 mode.into_glib(),
174 &mut error,
175 );
176 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
177 if error.is_null() {
178 Ok(())
179 } else {
180 Err(from_glib_full(error))
181 }
182 }
183 }
184
185 #[doc(alias = "gst_source_buffer_set_append_window_end")]
186 pub fn set_append_window_end(
187 &self,
188 end: impl Into<Option<gst::ClockTime>>,
189 ) -> Result<(), glib::Error> {
190 unsafe {
191 let mut error = std::ptr::null_mut();
192 let is_ok = ffi::gst_source_buffer_set_append_window_end(
193 self.to_glib_none().0,
194 end.into().into_glib(),
195 &mut error,
196 );
197 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
198 if error.is_null() {
199 Ok(())
200 } else {
201 Err(from_glib_full(error))
202 }
203 }
204 }
205
206 #[doc(alias = "gst_source_buffer_set_append_window_start")]
207 pub fn set_append_window_start(
208 &self,
209 start: impl Into<Option<gst::ClockTime>>,
210 ) -> Result<(), glib::Error> {
211 unsafe {
212 let mut error = std::ptr::null_mut();
213 let is_ok = ffi::gst_source_buffer_set_append_window_start(
214 self.to_glib_none().0,
215 start.into().into_glib(),
216 &mut error,
217 );
218 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
219 if error.is_null() {
220 Ok(())
221 } else {
222 Err(from_glib_full(error))
223 }
224 }
225 }
226
227 #[doc(alias = "gst_source_buffer_set_timestamp_offset")]
228 #[doc(alias = "timestamp-offset")]
229 pub fn set_timestamp_offset(
230 &self,
231 offset: impl Into<Option<gst::ClockTime>>,
232 ) -> Result<(), glib::Error> {
233 unsafe {
234 let mut error = std::ptr::null_mut();
235 let is_ok = ffi::gst_source_buffer_set_timestamp_offset(
236 self.to_glib_none().0,
237 offset.into().into_glib(),
238 &mut error,
239 );
240 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
241 if error.is_null() {
242 Ok(())
243 } else {
244 Err(from_glib_full(error))
245 }
246 }
247 }
248
249 #[doc(alias = "content-type")]
250 pub fn set_content_type(&self, content_type: Option<&str>) {
251 ObjectExt::set_property(self, "content-type", content_type)
252 }
253
254 #[doc(alias = "on-abort")]
255 pub fn connect_on_abort<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
256 unsafe extern "C" fn on_abort_trampoline<F: Fn(&SourceBuffer) + Send + Sync + 'static>(
257 this: *mut ffi::GstSourceBuffer,
258 f: glib::ffi::gpointer,
259 ) {
260 unsafe {
261 let f: &F = &*(f as *const F);
262 f(&from_glib_borrow(this))
263 }
264 }
265 unsafe {
266 let f: Box_<F> = Box_::new(f);
267 connect_raw(
268 self.as_ptr() as *mut _,
269 c"on-abort".as_ptr(),
270 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
271 on_abort_trampoline::<F> as *const (),
272 )),
273 Box_::into_raw(f),
274 )
275 }
276 }
277
278 #[doc(alias = "on-error")]
279 pub fn connect_on_error<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
280 unsafe extern "C" fn on_error_trampoline<F: Fn(&SourceBuffer) + Send + Sync + 'static>(
281 this: *mut ffi::GstSourceBuffer,
282 f: glib::ffi::gpointer,
283 ) {
284 unsafe {
285 let f: &F = &*(f as *const F);
286 f(&from_glib_borrow(this))
287 }
288 }
289 unsafe {
290 let f: Box_<F> = Box_::new(f);
291 connect_raw(
292 self.as_ptr() as *mut _,
293 c"on-error".as_ptr(),
294 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
295 on_error_trampoline::<F> as *const (),
296 )),
297 Box_::into_raw(f),
298 )
299 }
300 }
301
302 #[doc(alias = "on-update")]
303 pub fn connect_on_update<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
304 unsafe extern "C" fn on_update_trampoline<F: Fn(&SourceBuffer) + Send + Sync + 'static>(
305 this: *mut ffi::GstSourceBuffer,
306 f: glib::ffi::gpointer,
307 ) {
308 unsafe {
309 let f: &F = &*(f as *const F);
310 f(&from_glib_borrow(this))
311 }
312 }
313 unsafe {
314 let f: Box_<F> = Box_::new(f);
315 connect_raw(
316 self.as_ptr() as *mut _,
317 c"on-update".as_ptr(),
318 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
319 on_update_trampoline::<F> as *const (),
320 )),
321 Box_::into_raw(f),
322 )
323 }
324 }
325
326 #[doc(alias = "on-update-end")]
327 pub fn connect_on_update_end<F: Fn(&Self) + Send + Sync + 'static>(
328 &self,
329 f: F,
330 ) -> SignalHandlerId {
331 unsafe extern "C" fn on_update_end_trampoline<
332 F: Fn(&SourceBuffer) + Send + Sync + 'static,
333 >(
334 this: *mut ffi::GstSourceBuffer,
335 f: glib::ffi::gpointer,
336 ) {
337 unsafe {
338 let f: &F = &*(f as *const F);
339 f(&from_glib_borrow(this))
340 }
341 }
342 unsafe {
343 let f: Box_<F> = Box_::new(f);
344 connect_raw(
345 self.as_ptr() as *mut _,
346 c"on-update-end".as_ptr(),
347 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
348 on_update_end_trampoline::<F> as *const (),
349 )),
350 Box_::into_raw(f),
351 )
352 }
353 }
354
355 #[doc(alias = "on-update-start")]
356 pub fn connect_on_update_start<F: Fn(&Self) + Send + Sync + 'static>(
357 &self,
358 f: F,
359 ) -> SignalHandlerId {
360 unsafe extern "C" fn on_update_start_trampoline<
361 F: Fn(&SourceBuffer) + Send + Sync + 'static,
362 >(
363 this: *mut ffi::GstSourceBuffer,
364 f: glib::ffi::gpointer,
365 ) {
366 unsafe {
367 let f: &F = &*(f as *const F);
368 f(&from_glib_borrow(this))
369 }
370 }
371 unsafe {
372 let f: Box_<F> = Box_::new(f);
373 connect_raw(
374 self.as_ptr() as *mut _,
375 c"on-update-start".as_ptr(),
376 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
377 on_update_start_trampoline::<F> as *const (),
378 )),
379 Box_::into_raw(f),
380 )
381 }
382 }
383
384 #[doc(alias = "append-mode")]
385 pub fn connect_append_mode_notify<F: Fn(&Self) + Send + Sync + 'static>(
386 &self,
387 f: F,
388 ) -> SignalHandlerId {
389 unsafe extern "C" fn notify_append_mode_trampoline<
390 F: Fn(&SourceBuffer) + Send + Sync + 'static,
391 >(
392 this: *mut ffi::GstSourceBuffer,
393 _param_spec: glib::ffi::gpointer,
394 f: glib::ffi::gpointer,
395 ) {
396 unsafe {
397 let f: &F = &*(f as *const F);
398 f(&from_glib_borrow(this))
399 }
400 }
401 unsafe {
402 let f: Box_<F> = Box_::new(f);
403 connect_raw(
404 self.as_ptr() as *mut _,
405 c"notify::append-mode".as_ptr(),
406 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
407 notify_append_mode_trampoline::<F> as *const (),
408 )),
409 Box_::into_raw(f),
410 )
411 }
412 }
413
414 #[doc(alias = "append-window-end")]
415 pub fn connect_append_window_end_notify<F: Fn(&Self) + Send + Sync + 'static>(
416 &self,
417 f: F,
418 ) -> SignalHandlerId {
419 unsafe extern "C" fn notify_append_window_end_trampoline<
420 F: Fn(&SourceBuffer) + Send + Sync + 'static,
421 >(
422 this: *mut ffi::GstSourceBuffer,
423 _param_spec: glib::ffi::gpointer,
424 f: glib::ffi::gpointer,
425 ) {
426 unsafe {
427 let f: &F = &*(f as *const F);
428 f(&from_glib_borrow(this))
429 }
430 }
431 unsafe {
432 let f: Box_<F> = Box_::new(f);
433 connect_raw(
434 self.as_ptr() as *mut _,
435 c"notify::append-window-end".as_ptr(),
436 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
437 notify_append_window_end_trampoline::<F> as *const (),
438 )),
439 Box_::into_raw(f),
440 )
441 }
442 }
443
444 #[doc(alias = "append-window-start")]
445 pub fn connect_append_window_start_notify<F: Fn(&Self) + Send + Sync + 'static>(
446 &self,
447 f: F,
448 ) -> SignalHandlerId {
449 unsafe extern "C" fn notify_append_window_start_trampoline<
450 F: Fn(&SourceBuffer) + Send + Sync + 'static,
451 >(
452 this: *mut ffi::GstSourceBuffer,
453 _param_spec: glib::ffi::gpointer,
454 f: glib::ffi::gpointer,
455 ) {
456 unsafe {
457 let f: &F = &*(f as *const F);
458 f(&from_glib_borrow(this))
459 }
460 }
461 unsafe {
462 let f: Box_<F> = Box_::new(f);
463 connect_raw(
464 self.as_ptr() as *mut _,
465 c"notify::append-window-start".as_ptr(),
466 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
467 notify_append_window_start_trampoline::<F> as *const (),
468 )),
469 Box_::into_raw(f),
470 )
471 }
472 }
473
474 #[doc(alias = "buffered")]
475 pub fn connect_buffered_notify<F: Fn(&Self) + Send + Sync + 'static>(
476 &self,
477 f: F,
478 ) -> SignalHandlerId {
479 unsafe extern "C" fn notify_buffered_trampoline<
480 F: Fn(&SourceBuffer) + Send + Sync + 'static,
481 >(
482 this: *mut ffi::GstSourceBuffer,
483 _param_spec: glib::ffi::gpointer,
484 f: glib::ffi::gpointer,
485 ) {
486 unsafe {
487 let f: &F = &*(f as *const F);
488 f(&from_glib_borrow(this))
489 }
490 }
491 unsafe {
492 let f: Box_<F> = Box_::new(f);
493 connect_raw(
494 self.as_ptr() as *mut _,
495 c"notify::buffered".as_ptr(),
496 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
497 notify_buffered_trampoline::<F> as *const (),
498 )),
499 Box_::into_raw(f),
500 )
501 }
502 }
503
504 #[doc(alias = "content-type")]
505 pub fn connect_content_type_notify<F: Fn(&Self) + Send + Sync + 'static>(
506 &self,
507 f: F,
508 ) -> SignalHandlerId {
509 unsafe extern "C" fn notify_content_type_trampoline<
510 F: Fn(&SourceBuffer) + Send + Sync + 'static,
511 >(
512 this: *mut ffi::GstSourceBuffer,
513 _param_spec: glib::ffi::gpointer,
514 f: glib::ffi::gpointer,
515 ) {
516 unsafe {
517 let f: &F = &*(f as *const F);
518 f(&from_glib_borrow(this))
519 }
520 }
521 unsafe {
522 let f: Box_<F> = Box_::new(f);
523 connect_raw(
524 self.as_ptr() as *mut _,
525 c"notify::content-type".as_ptr(),
526 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
527 notify_content_type_trampoline::<F> as *const (),
528 )),
529 Box_::into_raw(f),
530 )
531 }
532 }
533
534 #[doc(alias = "timestamp-offset")]
535 pub fn connect_timestamp_offset_notify<F: Fn(&Self) + Send + Sync + 'static>(
536 &self,
537 f: F,
538 ) -> SignalHandlerId {
539 unsafe extern "C" fn notify_timestamp_offset_trampoline<
540 F: Fn(&SourceBuffer) + Send + Sync + 'static,
541 >(
542 this: *mut ffi::GstSourceBuffer,
543 _param_spec: glib::ffi::gpointer,
544 f: glib::ffi::gpointer,
545 ) {
546 unsafe {
547 let f: &F = &*(f as *const F);
548 f(&from_glib_borrow(this))
549 }
550 }
551 unsafe {
552 let f: Box_<F> = Box_::new(f);
553 connect_raw(
554 self.as_ptr() as *mut _,
555 c"notify::timestamp-offset".as_ptr(),
556 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
557 notify_timestamp_offset_trampoline::<F> as *const (),
558 )),
559 Box_::into_raw(f),
560 )
561 }
562 }
563
564 #[doc(alias = "updating")]
565 pub fn connect_updating_notify<F: Fn(&Self) + Send + Sync + 'static>(
566 &self,
567 f: F,
568 ) -> SignalHandlerId {
569 unsafe extern "C" fn notify_updating_trampoline<
570 F: Fn(&SourceBuffer) + Send + Sync + 'static,
571 >(
572 this: *mut ffi::GstSourceBuffer,
573 _param_spec: glib::ffi::gpointer,
574 f: glib::ffi::gpointer,
575 ) {
576 unsafe {
577 let f: &F = &*(f as *const F);
578 f(&from_glib_borrow(this))
579 }
580 }
581 unsafe {
582 let f: Box_<F> = Box_::new(f);
583 connect_raw(
584 self.as_ptr() as *mut _,
585 c"notify::updating".as_ptr(),
586 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
587 notify_updating_trampoline::<F> as *const (),
588 )),
589 Box_::into_raw(f),
590 )
591 }
592 }
593}
594
595unsafe impl Send for SourceBuffer {}
596unsafe impl Sync for SourceBuffer {}