1 // Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
2 //
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
8 
9 use glib;
10 use glib::translate::*;
11 use glib_sys;
12 use gobject_sys;
13 use gst_sys;
14 use std::fmt;
15 use std::marker::PhantomData;
16 use std::mem;
17 use std::ptr;
18 use Format;
19 use FormattedValue;
20 use GenericFormattedValue;
21 use SeekFlags;
22 use SeekType;
23 
24 pub type Segment = FormattedSegment<GenericFormattedValue>;
25 #[repr(C)]
26 pub struct FormattedSegment<T: FormattedValue>(gst_sys::GstSegment, PhantomData<T>);
27 
28 impl Segment {
reset_with_format(&mut self, format: Format)29     pub fn reset_with_format(&mut self, format: Format) {
30         unsafe {
31             gst_sys::gst_segment_init(self.to_glib_none_mut().0, format.to_glib());
32         }
33     }
34 
set_format(&mut self, format: Format)35     pub fn set_format(&mut self, format: Format) {
36         self.0.format = format.to_glib();
37     }
38 
downcast<T: FormattedValue>(self) -> Result<FormattedSegment<T>, Self>39     pub fn downcast<T: FormattedValue>(self) -> Result<FormattedSegment<T>, Self> {
40         if T::get_default_format() == Format::Undefined
41             || T::get_default_format() == self.get_format()
42         {
43             Ok(FormattedSegment(self.0, PhantomData))
44         } else {
45             Err(self)
46         }
47     }
48 
downcast_ref<T: FormattedValue>(&self) -> Option<&FormattedSegment<T>>49     pub fn downcast_ref<T: FormattedValue>(&self) -> Option<&FormattedSegment<T>> {
50         if T::get_default_format() == Format::Undefined
51             || T::get_default_format() == self.get_format()
52         {
53             Some(unsafe {
54                 &*(self as *const FormattedSegment<GenericFormattedValue>
55                     as *const FormattedSegment<T>)
56             })
57         } else {
58             None
59         }
60     }
61 
downcast_mut<T: FormattedValue>(&mut self) -> Option<&mut FormattedSegment<T>>62     pub fn downcast_mut<T: FormattedValue>(&mut self) -> Option<&mut FormattedSegment<T>> {
63         if T::get_default_format() == Format::Undefined
64             || T::get_default_format() == self.get_format()
65         {
66             Some(unsafe {
67                 &mut *(self as *mut FormattedSegment<GenericFormattedValue>
68                     as *mut FormattedSegment<T>)
69             })
70         } else {
71             None
72         }
73     }
74 }
75 
76 impl<T: FormattedValue> FormattedSegment<T> {
new() -> Self77     pub fn new() -> Self {
78         assert_initialized_main_thread!();
79         let segment = unsafe {
80             let mut segment = mem::MaybeUninit::zeroed();
81             gst_sys::gst_segment_init(segment.as_mut_ptr(), T::get_default_format().to_glib());
82             segment.assume_init()
83         };
84         FormattedSegment(segment, PhantomData)
85     }
86 
upcast(self) -> Segment87     pub fn upcast(self) -> Segment {
88         FormattedSegment(self.0, PhantomData)
89     }
90 
upcast_ref(&self) -> &Segment91     pub fn upcast_ref(&self) -> &Segment {
92         unsafe {
93             &*(self as *const FormattedSegment<T> as *const FormattedSegment<GenericFormattedValue>)
94         }
95     }
96 
reset(&mut self)97     pub fn reset(&mut self) {
98         unsafe {
99             gst_sys::gst_segment_init(&mut self.0, T::get_default_format().to_glib());
100         }
101     }
102 
clip<V: Into<T>>(&self, start: V, stop: V) -> Option<(T, T)>103     pub fn clip<V: Into<T>>(&self, start: V, stop: V) -> Option<(T, T)> {
104         let start = start.into();
105         let stop = stop.into();
106 
107         if T::get_default_format() == Format::Undefined {
108             assert_eq!(self.get_format(), start.get_format());
109             assert_eq!(self.get_format(), stop.get_format());
110         }
111 
112         unsafe {
113             let mut clip_start = mem::MaybeUninit::uninit();
114             let mut clip_stop = mem::MaybeUninit::uninit();
115             let ret = from_glib(gst_sys::gst_segment_clip(
116                 &self.0,
117                 start.get_format().to_glib(),
118                 start.to_raw_value() as u64,
119                 stop.to_raw_value() as u64,
120                 clip_start.as_mut_ptr(),
121                 clip_stop.as_mut_ptr(),
122             ));
123             if ret {
124                 Some((
125                     T::from_raw(self.get_format(), clip_start.assume_init() as i64),
126                     T::from_raw(self.get_format(), clip_stop.assume_init() as i64),
127                 ))
128             } else {
129                 None
130             }
131         }
132     }
133 
134     #[allow(clippy::too_many_arguments)]
do_seek<V: Into<T>>( &mut self, rate: f64, flags: SeekFlags, start_type: SeekType, start: V, stop_type: SeekType, stop: V, ) -> Option<bool>135     pub fn do_seek<V: Into<T>>(
136         &mut self,
137         rate: f64,
138         flags: SeekFlags,
139         start_type: SeekType,
140         start: V,
141         stop_type: SeekType,
142         stop: V,
143     ) -> Option<bool> {
144         skip_assert_initialized!();
145         let start = start.into();
146         let stop = stop.into();
147 
148         if T::get_default_format() == Format::Undefined {
149             assert_eq!(self.get_format(), start.get_format());
150             assert_eq!(self.get_format(), stop.get_format());
151         }
152 
153         unsafe {
154             let mut update = mem::MaybeUninit::uninit();
155             let ret = from_glib(gst_sys::gst_segment_do_seek(
156                 &mut self.0,
157                 rate,
158                 self.get_format().to_glib(),
159                 flags.to_glib(),
160                 start_type.to_glib(),
161                 start.to_raw_value() as u64,
162                 stop_type.to_glib(),
163                 stop.to_raw_value() as u64,
164                 update.as_mut_ptr(),
165             ));
166             if ret {
167                 Some(from_glib(update.assume_init()))
168             } else {
169                 None
170             }
171         }
172     }
173 
offset_running_time(&mut self, offset: i64) -> Result<(), glib::BoolError>174     pub fn offset_running_time(&mut self, offset: i64) -> Result<(), glib::BoolError> {
175         unsafe {
176             glib_result_from_gboolean!(
177                 gst_sys::gst_segment_offset_running_time(
178                     &mut self.0,
179                     self.get_format().to_glib(),
180                     offset,
181                 ),
182                 "Offset is not in the segment"
183             )
184         }
185     }
186 
position_from_running_time<V: Into<T>>(&self, running_time: V) -> T187     pub fn position_from_running_time<V: Into<T>>(&self, running_time: V) -> T {
188         let running_time = running_time.into();
189 
190         if T::get_default_format() == Format::Undefined {
191             assert_eq!(self.get_format(), running_time.get_format());
192         }
193 
194         unsafe {
195             T::from_raw(
196                 self.get_format(),
197                 gst_sys::gst_segment_position_from_running_time(
198                     &self.0,
199                     self.get_format().to_glib(),
200                     running_time.to_raw_value() as u64,
201                 ) as i64,
202             )
203         }
204     }
205 
position_from_running_time_full<V: Into<T>>(&self, running_time: V) -> (i32, T)206     pub fn position_from_running_time_full<V: Into<T>>(&self, running_time: V) -> (i32, T) {
207         let running_time = running_time.into();
208 
209         if T::get_default_format() == Format::Undefined {
210             assert_eq!(self.get_format(), running_time.get_format());
211         }
212 
213         unsafe {
214             let mut position = mem::MaybeUninit::uninit();
215             let ret = gst_sys::gst_segment_position_from_running_time_full(
216                 &self.0,
217                 self.get_format().to_glib(),
218                 running_time.to_raw_value() as u64,
219                 position.as_mut_ptr(),
220             );
221             (
222                 ret,
223                 T::from_raw(self.get_format(), position.assume_init() as i64),
224             )
225         }
226     }
227 
position_from_stream_time<V: Into<T>>(&self, stream_time: V) -> T228     pub fn position_from_stream_time<V: Into<T>>(&self, stream_time: V) -> T {
229         let stream_time = stream_time.into();
230 
231         if T::get_default_format() == Format::Undefined {
232             assert_eq!(self.get_format(), stream_time.get_format());
233         }
234 
235         unsafe {
236             T::from_raw(
237                 self.get_format(),
238                 gst_sys::gst_segment_position_from_stream_time(
239                     &self.0,
240                     self.get_format().to_glib(),
241                     stream_time.to_raw_value() as u64,
242                 ) as i64,
243             )
244         }
245     }
246 
position_from_stream_time_full<V: Into<T>>(&self, stream_time: V) -> (i32, T)247     pub fn position_from_stream_time_full<V: Into<T>>(&self, stream_time: V) -> (i32, T) {
248         let stream_time = stream_time.into();
249 
250         if T::get_default_format() == Format::Undefined {
251             assert_eq!(self.get_format(), stream_time.get_format());
252         }
253 
254         unsafe {
255             let mut position = mem::MaybeUninit::uninit();
256             let ret = gst_sys::gst_segment_position_from_stream_time_full(
257                 &self.0,
258                 self.get_format().to_glib(),
259                 stream_time.to_raw_value() as u64,
260                 position.as_mut_ptr(),
261             );
262             (
263                 ret,
264                 T::from_raw(self.get_format(), position.assume_init() as i64),
265             )
266         }
267     }
268 
set_running_time<V: Into<T>>(&mut self, running_time: V) -> Result<(), glib::BoolError>269     pub fn set_running_time<V: Into<T>>(&mut self, running_time: V) -> Result<(), glib::BoolError> {
270         let running_time = running_time.into();
271 
272         if T::get_default_format() == Format::Undefined {
273             assert_eq!(self.get_format(), running_time.get_format());
274         }
275 
276         unsafe {
277             glib_result_from_gboolean!(
278                 gst_sys::gst_segment_set_running_time(
279                     &mut self.0,
280                     self.get_format().to_glib(),
281                     running_time.to_raw_value() as u64,
282                 ),
283                 "Running time is not in the segment"
284             )
285         }
286     }
287 
to_running_time<V: Into<T>>(&self, position: V) -> T288     pub fn to_running_time<V: Into<T>>(&self, position: V) -> T {
289         let position = position.into();
290 
291         if T::get_default_format() == Format::Undefined {
292             assert_eq!(self.get_format(), position.get_format());
293         }
294 
295         unsafe {
296             T::from_raw(
297                 self.get_format(),
298                 gst_sys::gst_segment_to_running_time(
299                     &self.0,
300                     self.get_format().to_glib(),
301                     position.to_raw_value() as u64,
302                 ) as i64,
303             )
304         }
305     }
306 
to_running_time_full<V: Into<T>>(&self, position: V) -> (i32, T)307     pub fn to_running_time_full<V: Into<T>>(&self, position: V) -> (i32, T) {
308         let position = position.into();
309 
310         if T::get_default_format() == Format::Undefined {
311             assert_eq!(self.get_format(), position.get_format());
312         }
313 
314         unsafe {
315             let mut running_time = mem::MaybeUninit::uninit();
316             let ret = gst_sys::gst_segment_to_running_time_full(
317                 &self.0,
318                 self.get_format().to_glib(),
319                 position.to_raw_value() as u64,
320                 running_time.as_mut_ptr(),
321             );
322             (
323                 ret,
324                 T::from_raw(self.get_format(), running_time.assume_init() as i64),
325             )
326         }
327     }
328 
to_stream_time<V: Into<T>>(&self, position: V) -> T329     pub fn to_stream_time<V: Into<T>>(&self, position: V) -> T {
330         let position = position.into();
331 
332         if T::get_default_format() == Format::Undefined {
333             assert_eq!(self.get_format(), position.get_format());
334         }
335 
336         unsafe {
337             T::from_raw(
338                 self.get_format(),
339                 gst_sys::gst_segment_to_stream_time(
340                     &self.0,
341                     self.get_format().to_glib(),
342                     position.to_raw_value() as u64,
343                 ) as i64,
344             )
345         }
346     }
347 
to_stream_time_full<V: Into<T>>(&self, position: V) -> (i32, T)348     pub fn to_stream_time_full<V: Into<T>>(&self, position: V) -> (i32, T) {
349         let position = position.into();
350 
351         if T::get_default_format() == Format::Undefined {
352             assert_eq!(self.get_format(), position.get_format());
353         }
354 
355         unsafe {
356             let mut stream_time = mem::MaybeUninit::uninit();
357             let ret = gst_sys::gst_segment_to_stream_time_full(
358                 &self.0,
359                 self.get_format().to_glib(),
360                 position.to_raw_value() as u64,
361                 stream_time.as_mut_ptr(),
362             );
363             (
364                 ret,
365                 T::from_raw(self.get_format(), stream_time.assume_init() as i64),
366             )
367         }
368     }
369 
get_flags(&self) -> ::SegmentFlags370     pub fn get_flags(&self) -> ::SegmentFlags {
371         from_glib(self.0.flags)
372     }
373 
set_flags(&mut self, flags: ::SegmentFlags)374     pub fn set_flags(&mut self, flags: ::SegmentFlags) {
375         self.0.flags = flags.to_glib();
376     }
377 
get_rate(&self) -> f64378     pub fn get_rate(&self) -> f64 {
379         self.0.rate
380     }
381 
382     #[allow(clippy::float_cmp)]
set_rate(&mut self, rate: f64)383     pub fn set_rate(&mut self, rate: f64) {
384         assert_ne!(rate, 0.0);
385         self.0.rate = rate;
386     }
387 
get_applied_rate(&self) -> f64388     pub fn get_applied_rate(&self) -> f64 {
389         self.0.applied_rate
390     }
391 
392     #[allow(clippy::float_cmp)]
set_applied_rate(&mut self, applied_rate: f64)393     pub fn set_applied_rate(&mut self, applied_rate: f64) {
394         assert_ne!(applied_rate, 0.0);
395         self.0.applied_rate = applied_rate;
396     }
397 
get_format(&self) -> Format398     pub fn get_format(&self) -> Format {
399         from_glib(self.0.format)
400     }
401 
get_base(&self) -> T402     pub fn get_base(&self) -> T {
403         unsafe { T::from_raw(self.get_format(), self.0.base as i64) }
404     }
405 
set_base<V: Into<T>>(&mut self, base: V)406     pub fn set_base<V: Into<T>>(&mut self, base: V) {
407         let base = base.into();
408 
409         if T::get_default_format() == Format::Undefined {
410             assert_eq!(self.get_format(), base.get_format());
411         }
412 
413         self.0.base = unsafe { base.to_raw_value() } as u64;
414     }
415 
get_offset(&self) -> T416     pub fn get_offset(&self) -> T {
417         unsafe { T::from_raw(self.get_format(), self.0.offset as i64) }
418     }
419 
set_offset<V: Into<T>>(&mut self, offset: V)420     pub fn set_offset<V: Into<T>>(&mut self, offset: V) {
421         let offset = offset.into();
422 
423         if T::get_default_format() == Format::Undefined {
424             assert_eq!(self.get_format(), offset.get_format());
425         }
426 
427         self.0.offset = unsafe { offset.to_raw_value() } as u64;
428     }
429 
get_start(&self) -> T430     pub fn get_start(&self) -> T {
431         unsafe { T::from_raw(self.get_format(), self.0.start as i64) }
432     }
433 
set_start<V: Into<T>>(&mut self, start: V)434     pub fn set_start<V: Into<T>>(&mut self, start: V) {
435         let start = start.into();
436 
437         if T::get_default_format() == Format::Undefined {
438             assert_eq!(self.get_format(), start.get_format());
439         }
440 
441         self.0.start = unsafe { start.to_raw_value() } as u64;
442     }
443 
get_stop(&self) -> T444     pub fn get_stop(&self) -> T {
445         unsafe { T::from_raw(self.get_format(), self.0.stop as i64) }
446     }
447 
set_stop<V: Into<T>>(&mut self, stop: V)448     pub fn set_stop<V: Into<T>>(&mut self, stop: V) {
449         let stop = stop.into();
450 
451         if T::get_default_format() == Format::Undefined {
452             assert_eq!(self.get_format(), stop.get_format());
453         }
454 
455         self.0.stop = unsafe { stop.to_raw_value() } as u64;
456     }
457 
get_time(&self) -> T458     pub fn get_time(&self) -> T {
459         unsafe { T::from_raw(self.get_format(), self.0.time as i64) }
460     }
461 
set_time<V: Into<T>>(&mut self, time: V)462     pub fn set_time<V: Into<T>>(&mut self, time: V) {
463         let time = time.into();
464 
465         if T::get_default_format() == Format::Undefined {
466             assert_eq!(self.get_format(), time.get_format());
467         }
468 
469         self.0.time = unsafe { time.to_raw_value() } as u64;
470     }
471 
get_position(&self) -> T472     pub fn get_position(&self) -> T {
473         unsafe { T::from_raw(self.get_format(), self.0.position as i64) }
474     }
475 
set_position<V: Into<T>>(&mut self, position: V)476     pub fn set_position<V: Into<T>>(&mut self, position: V) {
477         let position = position.into();
478 
479         if T::get_default_format() == Format::Undefined {
480             assert_eq!(self.get_format(), position.get_format());
481         }
482 
483         self.0.position = unsafe { position.to_raw_value() } as u64;
484     }
485 
get_duration(&self) -> T486     pub fn get_duration(&self) -> T {
487         unsafe { T::from_raw(self.get_format(), self.0.duration as i64) }
488     }
489 
set_duration<V: Into<T>>(&mut self, duration: V)490     pub fn set_duration<V: Into<T>>(&mut self, duration: V) {
491         let duration = duration.into();
492 
493         if T::get_default_format() == Format::Undefined {
494             assert_eq!(self.get_format(), duration.get_format());
495         }
496 
497         self.0.duration = unsafe { duration.to_raw_value() } as u64;
498     }
499 }
500 
501 impl<T: FormattedValue> PartialEq for FormattedSegment<T> {
502     #[inline]
eq(&self, other: &Self) -> bool503     fn eq(&self, other: &Self) -> bool {
504         unsafe { from_glib(gst_sys::gst_segment_is_equal(&self.0, &other.0)) }
505     }
506 }
507 
508 impl<T: FormattedValue> Eq for FormattedSegment<T> {}
509 
510 unsafe impl<T: FormattedValue> Send for FormattedSegment<T> {}
511 unsafe impl<T: FormattedValue> Sync for FormattedSegment<T> {}
512 
513 impl<T: FormattedValue> Clone for FormattedSegment<T> {
clone(&self) -> Self514     fn clone(&self) -> Self {
515         unsafe { FormattedSegment(ptr::read(&self.0), PhantomData) }
516     }
517 }
518 
519 impl<T: FormattedValue> AsRef<Segment> for FormattedSegment<T> {
as_ref(&self) -> &Segment520     fn as_ref(&self) -> &Segment {
521         unsafe {
522             &*(self as *const FormattedSegment<T> as *const FormattedSegment<GenericFormattedValue>)
523         }
524     }
525 }
526 
527 impl<T: FormattedValue> fmt::Debug for FormattedSegment<T> {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result528     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
529         let segment = self.as_ref();
530         match segment.get_format() {
531             Format::Undefined => f
532                 .debug_struct("Segment")
533                 .field("format", &Format::Undefined)
534                 .finish(),
535             Format::Time => {
536                 let segment = segment.downcast_ref::<::ClockTime>().unwrap();
537                 f.debug_struct("Segment")
538                     .field("format", &Format::Time)
539                     .field("start", &segment.get_start().to_string())
540                     .field("offset", &segment.get_offset().to_string())
541                     .field("stop", &segment.get_stop().to_string())
542                     .field("rate", &segment.get_rate())
543                     .field("applied_rate", &segment.get_applied_rate())
544                     .field("flags", &segment.get_flags())
545                     .field("time", &segment.get_time().to_string())
546                     .field("base", &segment.get_base().to_string())
547                     .field("position", &segment.get_position().to_string())
548                     .field("duration", &segment.get_duration().to_string())
549                     .finish()
550             }
551             _ => f
552                 .debug_struct("Segment")
553                 .field("format", &segment.get_format())
554                 .field("start", &segment.get_start())
555                 .field("offset", &segment.get_offset())
556                 .field("stop", &segment.get_stop())
557                 .field("rate", &segment.get_rate())
558                 .field("applied_rate", &segment.get_applied_rate())
559                 .field("flags", &segment.get_flags())
560                 .field("time", &segment.get_time())
561                 .field("base", &segment.get_base())
562                 .field("position", &segment.get_position())
563                 .field("duration", &segment.get_duration())
564                 .finish(),
565         }
566     }
567 }
568 
569 impl<T: FormattedValue> Default for FormattedSegment<T> {
default() -> Self570     fn default() -> Self {
571         Self::new()
572     }
573 }
574 
575 impl<T: FormattedValue> glib::types::StaticType for FormattedSegment<T> {
static_type() -> glib::types::Type576     fn static_type() -> glib::types::Type {
577         unsafe { glib::translate::from_glib(gst_sys::gst_segment_get_type()) }
578     }
579 }
580 
581 #[doc(hidden)]
582 impl<'a> glib::value::FromValueOptional<'a> for Segment {
from_value_optional(value: &glib::Value) -> Option<Self>583     unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> {
584         Option::<Segment>::from_glib_none(
585             gobject_sys::g_value_get_boxed(value.to_glib_none().0) as *mut gst_sys::GstSegment
586         )
587     }
588 }
589 
590 #[doc(hidden)]
591 impl<T: FormattedValue> glib::value::SetValue for FormattedSegment<T> {
set_value(value: &mut glib::Value, this: &Self)592     unsafe fn set_value(value: &mut glib::Value, this: &Self) {
593         gobject_sys::g_value_set_boxed(
594             value.to_glib_none_mut().0,
595             glib::translate::ToGlibPtr::<*const gst_sys::GstSegment>::to_glib_none(this).0
596                 as glib_sys::gpointer,
597         )
598     }
599 }
600 
601 #[doc(hidden)]
602 impl<T: FormattedValue> glib::value::SetValueOptional for FormattedSegment<T> {
set_value_optional(value: &mut glib::Value, this: Option<&Self>)603     unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) {
604         gobject_sys::g_value_set_boxed(
605             value.to_glib_none_mut().0,
606             glib::translate::ToGlibPtr::<*const gst_sys::GstSegment>::to_glib_none(&this).0
607                 as glib_sys::gpointer,
608         )
609     }
610 }
611 
612 #[doc(hidden)]
613 impl<T: FormattedValue> glib::translate::GlibPtrDefault for FormattedSegment<T> {
614     type GlibType = *mut gst_sys::GstSegment;
615 }
616 
617 #[doc(hidden)]
618 impl<'a, T: FormattedValue> glib::translate::ToGlibPtr<'a, *const gst_sys::GstSegment>
619     for FormattedSegment<T>
620 {
621     type Storage = &'a FormattedSegment<T>;
622 
to_glib_none(&'a self) -> glib::translate::Stash<'a, *const gst_sys::GstSegment, Self>623     fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const gst_sys::GstSegment, Self> {
624         glib::translate::Stash(&self.0, self)
625     }
626 
to_glib_full(&self) -> *const gst_sys::GstSegment627     fn to_glib_full(&self) -> *const gst_sys::GstSegment {
628         unimplemented!()
629     }
630 }
631 
632 #[doc(hidden)]
633 impl<'a, T: FormattedValue> glib::translate::ToGlibPtrMut<'a, *mut gst_sys::GstSegment>
634     for FormattedSegment<T>
635 {
636     type Storage = &'a mut FormattedSegment<T>;
637 
638     #[inline]
to_glib_none_mut( &'a mut self, ) -> glib::translate::StashMut<'a, *mut gst_sys::GstSegment, Self>639     fn to_glib_none_mut(
640         &'a mut self,
641     ) -> glib::translate::StashMut<'a, *mut gst_sys::GstSegment, Self> {
642         glib::translate::StashMut(&mut self.0, self)
643     }
644 }
645 
646 #[doc(hidden)]
647 impl glib::translate::FromGlibPtrNone<*const gst_sys::GstSegment> for Segment {
648     #[inline]
from_glib_none(ptr: *const gst_sys::GstSegment) -> Self649     unsafe fn from_glib_none(ptr: *const gst_sys::GstSegment) -> Self {
650         FormattedSegment(ptr::read(ptr), PhantomData)
651     }
652 }
653 
654 #[doc(hidden)]
655 impl glib::translate::FromGlibPtrNone<*mut gst_sys::GstSegment> for Segment {
656     #[inline]
from_glib_none(ptr: *mut gst_sys::GstSegment) -> Self657     unsafe fn from_glib_none(ptr: *mut gst_sys::GstSegment) -> Self {
658         FormattedSegment(ptr::read(ptr), PhantomData)
659     }
660 }
661 
662 #[doc(hidden)]
663 impl glib::translate::FromGlibPtrBorrow<*mut gst_sys::GstSegment> for Segment {
664     #[inline]
from_glib_borrow(ptr: *mut gst_sys::GstSegment) -> Self665     unsafe fn from_glib_borrow(ptr: *mut gst_sys::GstSegment) -> Self {
666         FormattedSegment(ptr::read(ptr), PhantomData)
667     }
668 }
669 
670 #[doc(hidden)]
671 impl glib::translate::FromGlibPtrFull<*mut gst_sys::GstSegment> for Segment {
672     #[inline]
from_glib_full(ptr: *mut gst_sys::GstSegment) -> Self673     unsafe fn from_glib_full(ptr: *mut gst_sys::GstSegment) -> Self {
674         let segment = from_glib_none(ptr);
675         glib_sys::g_free(ptr as *mut _);
676         segment
677     }
678 }
679