1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use ClockTime;
use Object;
use ffi;
use glib;
use glib::StaticType;
use glib::Value;
use glib::object::Downcast;
use glib::object::IsA;
use glib::signal::SignalHandlerId;
use glib::signal::connect;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::boxed::Box as Box_;
use std::mem;
use std::mem::transmute;
use std::ptr;

glib_wrapper! {
    pub struct Clock(Object<ffi::GstClock, ffi::GstClockClass>): Object;

    match fn {
        get_type => || ffi::gst_clock_get_type(),
    }
}

impl Clock {
    //pub fn id_compare_func<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>, Q: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(id1: P, id2: Q) -> i32 {
    //    unsafe { TODO: call ffi::gst_clock_id_compare_func() }
    //}

    //pub fn id_get_time(id: /*Unimplemented*/ClockID) -> ClockTime {
    //    unsafe { TODO: call ffi::gst_clock_id_get_time() }
    //}

    //pub fn id_ref(id: /*Unimplemented*/ClockID) -> /*Unimplemented*/Option<ClockID> {
    //    unsafe { TODO: call ffi::gst_clock_id_ref() }
    //}

    //pub fn id_unref(id: /*Unimplemented*/ClockID) {
    //    unsafe { TODO: call ffi::gst_clock_id_unref() }
    //}

    //pub fn id_unschedule(id: /*Unimplemented*/ClockID) {
    //    unsafe { TODO: call ffi::gst_clock_id_unschedule() }
    //}

    //pub fn id_wait(id: /*Unimplemented*/ClockID) -> (ClockReturn, ClockTimeDiff) {
    //    unsafe { TODO: call ffi::gst_clock_id_wait() }
    //}

    //pub fn id_wait_async(id: /*Unimplemented*/ClockID, func: /*Unknown conversion*//*Unimplemented*/ClockCallback, destroy_data: /*Unknown conversion*//*Unimplemented*/DestroyNotify) -> ClockReturn {
    //    unsafe { TODO: call ffi::gst_clock_id_wait_async() }
    //}
}

unsafe impl Send for Clock {}
unsafe impl Sync for Clock {}

pub trait ClockExt {
    fn add_observation(&self, slave: ClockTime, master: ClockTime) -> Option<f64>;

    fn add_observation_unapplied(&self, slave: ClockTime, master: ClockTime) -> Option<(f64, ClockTime, ClockTime, ClockTime, ClockTime)>;

    fn adjust_unlocked(&self, internal: ClockTime) -> ClockTime;

    fn get_calibration(&self) -> (ClockTime, ClockTime, ClockTime, ClockTime);

    fn get_internal_time(&self) -> ClockTime;

    fn get_master(&self) -> Option<Clock>;

    fn get_resolution(&self) -> ClockTime;

    fn get_time(&self) -> ClockTime;

    fn get_timeout(&self) -> ClockTime;

    fn is_synced(&self) -> bool;

    //fn new_periodic_id(&self, start_time: ClockTime, interval: ClockTime) -> /*Unimplemented*/Option<ClockID>;

    //fn new_single_shot_id(&self, time: ClockTime) -> /*Unimplemented*/Option<ClockID>;

    //fn periodic_id_reinit(&self, id: /*Unimplemented*/ClockID, start_time: ClockTime, interval: ClockTime) -> bool;

    fn set_calibration(&self, internal: ClockTime, external: ClockTime, rate_num: ClockTime, rate_denom: ClockTime);

    fn set_master<'a, P: IsA<Clock> + 'a, Q: Into<Option<&'a P>>>(&self, master: Q) -> Result<(), glib::error::BoolError>;

    fn set_resolution(&self, resolution: ClockTime) -> ClockTime;

    fn set_synced(&self, synced: bool);

    fn set_timeout(&self, timeout: ClockTime);

    //fn single_shot_id_reinit(&self, id: /*Unimplemented*/ClockID, time: ClockTime) -> bool;

    fn unadjust_unlocked(&self, external: ClockTime) -> ClockTime;

    fn wait_for_sync(&self, timeout: ClockTime) -> Result<(), glib::error::BoolError>;

    fn get_property_window_size(&self) -> i32;

    fn set_property_window_size(&self, window_size: i32);

    fn get_property_window_threshold(&self) -> i32;

    fn set_property_window_threshold(&self, window_threshold: i32);

    fn connect_synced<F: Fn(&Self, bool) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_timeout_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_window_size_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_window_threshold_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Clock> + IsA<glib::object::Object>> ClockExt for O {
    fn add_observation(&self, slave: ClockTime, master: ClockTime) -> Option<f64> {
        unsafe {
            let mut r_squared = mem::uninitialized();
            let ret = from_glib(ffi::gst_clock_add_observation(self.to_glib_none().0, slave.to_glib(), master.to_glib(), &mut r_squared));
            if ret { Some(r_squared) } else { None }
        }
    }

    fn add_observation_unapplied(&self, slave: ClockTime, master: ClockTime) -> Option<(f64, ClockTime, ClockTime, ClockTime, ClockTime)> {
        unsafe {
            let mut r_squared = mem::uninitialized();
            let mut internal = mem::uninitialized();
            let mut external = mem::uninitialized();
            let mut rate_num = mem::uninitialized();
            let mut rate_denom = mem::uninitialized();
            let ret = from_glib(ffi::gst_clock_add_observation_unapplied(self.to_glib_none().0, slave.to_glib(), master.to_glib(), &mut r_squared, &mut internal, &mut external, &mut rate_num, &mut rate_denom));
            if ret { Some((r_squared, from_glib(internal), from_glib(external), from_glib(rate_num), from_glib(rate_denom))) } else { None }
        }
    }

    fn adjust_unlocked(&self, internal: ClockTime) -> ClockTime {
        unsafe {
            from_glib(ffi::gst_clock_adjust_unlocked(self.to_glib_none().0, internal.to_glib()))
        }
    }

    fn get_calibration(&self) -> (ClockTime, ClockTime, ClockTime, ClockTime) {
        unsafe {
            let mut internal = mem::uninitialized();
            let mut external = mem::uninitialized();
            let mut rate_num = mem::uninitialized();
            let mut rate_denom = mem::uninitialized();
            ffi::gst_clock_get_calibration(self.to_glib_none().0, &mut internal, &mut external, &mut rate_num, &mut rate_denom);
            (from_glib(internal), from_glib(external), from_glib(rate_num), from_glib(rate_denom))
        }
    }

    fn get_internal_time(&self) -> ClockTime {
        unsafe {
            from_glib(ffi::gst_clock_get_internal_time(self.to_glib_none().0))
        }
    }

    fn get_master(&self) -> Option<Clock> {
        unsafe {
            from_glib_full(ffi::gst_clock_get_master(self.to_glib_none().0))
        }
    }

    fn get_resolution(&self) -> ClockTime {
        unsafe {
            from_glib(ffi::gst_clock_get_resolution(self.to_glib_none().0))
        }
    }

    fn get_time(&self) -> ClockTime {
        unsafe {
            from_glib(ffi::gst_clock_get_time(self.to_glib_none().0))
        }
    }

    fn get_timeout(&self) -> ClockTime {
        unsafe {
            from_glib(ffi::gst_clock_get_timeout(self.to_glib_none().0))
        }
    }

    fn is_synced(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_clock_is_synced(self.to_glib_none().0))
        }
    }

    //fn new_periodic_id(&self, start_time: ClockTime, interval: ClockTime) -> /*Unimplemented*/Option<ClockID> {
    //    unsafe { TODO: call ffi::gst_clock_new_periodic_id() }
    //}

    //fn new_single_shot_id(&self, time: ClockTime) -> /*Unimplemented*/Option<ClockID> {
    //    unsafe { TODO: call ffi::gst_clock_new_single_shot_id() }
    //}

    //fn periodic_id_reinit(&self, id: /*Unimplemented*/ClockID, start_time: ClockTime, interval: ClockTime) -> bool {
    //    unsafe { TODO: call ffi::gst_clock_periodic_id_reinit() }
    //}

    fn set_calibration(&self, internal: ClockTime, external: ClockTime, rate_num: ClockTime, rate_denom: ClockTime) {
        unsafe {
            ffi::gst_clock_set_calibration(self.to_glib_none().0, internal.to_glib(), external.to_glib(), rate_num.to_glib(), rate_denom.to_glib());
        }
    }

    fn set_master<'a, P: IsA<Clock> + 'a, Q: Into<Option<&'a P>>>(&self, master: Q) -> Result<(), glib::error::BoolError> {
        let master = master.into();
        let master = master.to_glib_none();
        unsafe {
            glib::error::BoolError::from_glib(ffi::gst_clock_set_master(self.to_glib_none().0, master.0), "Failed to set master clock")
        }
    }

    fn set_resolution(&self, resolution: ClockTime) -> ClockTime {
        unsafe {
            from_glib(ffi::gst_clock_set_resolution(self.to_glib_none().0, resolution.to_glib()))
        }
    }

    fn set_synced(&self, synced: bool) {
        unsafe {
            ffi::gst_clock_set_synced(self.to_glib_none().0, synced.to_glib());
        }
    }

    fn set_timeout(&self, timeout: ClockTime) {
        unsafe {
            ffi::gst_clock_set_timeout(self.to_glib_none().0, timeout.to_glib());
        }
    }

    //fn single_shot_id_reinit(&self, id: /*Unimplemented*/ClockID, time: ClockTime) -> bool {
    //    unsafe { TODO: call ffi::gst_clock_single_shot_id_reinit() }
    //}

    fn unadjust_unlocked(&self, external: ClockTime) -> ClockTime {
        unsafe {
            from_glib(ffi::gst_clock_unadjust_unlocked(self.to_glib_none().0, external.to_glib()))
        }
    }

    fn wait_for_sync(&self, timeout: ClockTime) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::error::BoolError::from_glib(ffi::gst_clock_wait_for_sync(self.to_glib_none().0, timeout.to_glib()), "Timed out waiting for sync")
        }
    }

    fn get_property_window_size(&self) -> i32 {
        unsafe {
            let mut value = Value::from_type(<i32 as StaticType>::static_type());
            gobject_ffi::g_object_get_property(self.to_glib_none().0, "window-size".to_glib_none().0, value.to_glib_none_mut().0);
            value.get().unwrap()
        }
    }

    fn set_property_window_size(&self, window_size: i32) {
        unsafe {
            gobject_ffi::g_object_set_property(self.to_glib_none().0, "window-size".to_glib_none().0, Value::from(&window_size).to_glib_none().0);
        }
    }

    fn get_property_window_threshold(&self) -> i32 {
        unsafe {
            let mut value = Value::from_type(<i32 as StaticType>::static_type());
            gobject_ffi::g_object_get_property(self.to_glib_none().0, "window-threshold".to_glib_none().0, value.to_glib_none_mut().0);
            value.get().unwrap()
        }
    }

    fn set_property_window_threshold(&self, window_threshold: i32) {
        unsafe {
            gobject_ffi::g_object_set_property(self.to_glib_none().0, "window-threshold".to_glib_none().0, Value::from(&window_threshold).to_glib_none().0);
        }
    }

    fn connect_synced<F: Fn(&Self, bool) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self, bool) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "synced",
                transmute(synced_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_property_timeout_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "notify::timeout",
                transmute(notify_timeout_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_property_window_size_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "notify::window-size",
                transmute(notify_window_size_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_property_window_threshold_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "notify::window-threshold",
                transmute(notify_window_threshold_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }
}

unsafe extern "C" fn synced_trampoline<P>(this: *mut ffi::GstClock, synced: glib_ffi::gboolean, f: glib_ffi::gpointer)
where P: IsA<Clock> {
    let f: &&(Fn(&P, bool) + Send + Sync + 'static) = transmute(f);
    f(&Clock::from_glib_borrow(this).downcast_unchecked(), from_glib(synced))
}

unsafe extern "C" fn notify_timeout_trampoline<P>(this: *mut ffi::GstClock, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Clock> {
    let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
    f(&Clock::from_glib_borrow(this).downcast_unchecked())
}

unsafe extern "C" fn notify_window_size_trampoline<P>(this: *mut ffi::GstClock, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Clock> {
    let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
    f(&Clock::from_glib_borrow(this).downcast_unchecked())
}

unsafe extern "C" fn notify_window_threshold_trampoline<P>(this: *mut ffi::GstClock, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Clock> {
    let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
    f(&Clock::from_glib_borrow(this).downcast_unchecked())
}