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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
// 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 ges_sys;
use glib;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
use glib::Value;
use glib_sys;
use gobject_sys;
use gst;
use std::boxed::Box as Box_;
use std::mem::transmute;
use Timeline;
use TrackElement;
use TrackType;

glib_wrapper! {
    /// Corresponds to one output format (i.e. audio OR video).
    ///
    /// Contains the compatible TrackElement(s).
    ///
    /// # Implements
    ///
    /// [`GESTrackExt`](trait.GESTrackExt.html), [`gst::ElementExt`](../gst/trait.ElementExt.html), [`gst::ObjectExt`](../gst/trait.ObjectExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html)
    pub struct Track(Object<ges_sys::GESTrack, ges_sys::GESTrackClass, TrackClass>) @extends gst::Element, gst::Object;

    match fn {
        get_type => || ges_sys::ges_track_get_type(),
    }
}

impl Track {
    /// Creates a new `Track` with the given `type_` and `caps`.
    ///
    /// The newly created track will steal a reference to the caps. If you wish to
    /// use those caps elsewhere, you will have to take an extra reference.
    /// ## `type_`
    /// The type of track
    /// ## `caps`
    /// The caps to restrict the output of the track to.
    ///
    /// # Returns
    ///
    /// A new `Track`.
    pub fn new(type_: TrackType, caps: &gst::Caps) -> Track {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ges_sys::ges_track_new(type_.to_glib(), caps.to_glib_full())) }
    }
}

pub const NONE_TRACK: Option<&Track> = None;

/// Trait containing all `Track` methods.
///
/// # Implementors
///
/// [`Track`](struct.Track.html)
pub trait GESTrackExt: 'static {
    /// Adds the given object to the track. Sets the object's controlling track,
    /// and thus takes ownership of the `object`.
    ///
    /// An object can only be added to one track.
    /// ## `object`
    /// the `TrackElement` to add
    ///
    /// # Returns
    ///
    /// `true` if the object was properly added. `false` if the track does not
    /// want to accept the object.
    fn add_element<P: IsA<TrackElement>>(&self, object: &P) -> Result<(), glib::error::BoolError>;

    /// Commits all the pending changes of the TrackElement contained in the
    /// track.
    ///
    /// When timing changes happen in a timeline, the changes are not
    /// directly done inside NLE. This method needs to be called so any changes
    /// on a clip contained in the timeline actually happen at the media
    /// processing level.
    ///
    /// # Returns
    ///
    /// `true` if something as been commited `false` if nothing needed
    /// to be commited
    fn commit(&self) -> bool;

    /// Get the `gst::Caps` this track is configured to output.
    ///
    /// # Returns
    ///
    /// The `gst::Caps` this track is configured to output.
    fn get_caps(&self) -> Option<gst::Caps>;

    /// Gets the `TrackElement` contained in `self`
    ///
    /// # Returns
    ///
    /// the list of
    /// `TrackElement` present in the Track sorted by priority and start.
    fn get_elements(&self) -> Vec<TrackElement>;

    /// Gets if the underlying `NleComposition` contains an expandable mixer.
    ///
    /// # Returns
    ///
    /// `True` if there is a mixer, `False` otherwise.
    fn get_mixing(&self) -> bool;

    /// Get the `Timeline` this track belongs to. Can be `None`.
    ///
    /// # Returns
    ///
    /// The `Timeline` this track belongs to. Can be `None`.
    fn get_timeline(&self) -> Option<Timeline>;

    /// Removes the object from the track and unparents it.
    /// Unparenting it means the reference owned by `self` on the `object` will be
    /// removed. If you wish to use the `object` after this function, make sure you
    /// call `gst::ObjectExt::ref` before removing it from the `self`.
    /// ## `object`
    /// the `TrackElement` to remove
    ///
    /// # Returns
    ///
    /// `true` if the object was removed, else `false` if the track
    /// could not remove the object (like if it didn't belong to the track).
    fn remove_element<P: IsA<TrackElement>>(
        &self,
        object: &P,
    ) -> Result<(), glib::error::BoolError>;

    //fn set_create_element_for_gap_func<P: Fn(&Track) -> gst::Element + 'static>(&self, func: P);

    /// Sets if the `Track` should be mixing.
    /// ## `mixing`
    /// TRUE if the track should be mixing, FALSE otherwise.
    fn set_mixing(&self, mixing: bool);

    /// Sets the given `caps` as the caps the track has to output.
    /// ## `caps`
    /// the `gst::Caps` to set
    fn set_restriction_caps(&self, caps: &gst::Caps);

    /// Sets `timeline` as the timeline controlling `self`.
    /// ## `timeline`
    /// a `Timeline`
    fn set_timeline<P: IsA<Timeline>>(&self, timeline: &P);

    /// Updates the restriction caps by modifying all the fields present in `caps`
    /// in the original restriction caps. If for example the current restriction caps
    /// are video/x-raw, format=I420, width=360 and `caps` is video/x-raw, format=RGB,
    /// the restriction caps will be updated to video/x-raw, format=RGB, width=360.
    ///
    /// Modification happens for each structure in the new caps, and
    /// one can add new fields or structures through that function.
    /// ## `caps`
    /// the `gst::Caps` to update with
    fn update_restriction_caps(&self, caps: &gst::Caps);

    /// Current duration of the track
    ///
    /// Default value: O
    fn get_property_duration(&self) -> u64;

    /// Caps used to filter/choose the output stream.
    ///
    /// Default value: `GST_CAPS_ANY`.
    fn get_property_restriction_caps(&self) -> Option<gst::Caps>;

    /// Type of stream the track outputs. This is used when creating the `Track`
    /// to specify in generic terms what type of content will be outputted.
    ///
    /// It also serves as a 'fast' way to check what type of data will be outputted
    /// from the `Track` without having to actually check the `Track`'s caps
    /// property.
    fn get_property_track_type(&self) -> TrackType;

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

    /// Will be emitted after a track element was added to the track.
    /// ## `effect`
    /// the `TrackElement` that was added.
    fn connect_track_element_added<F: Fn(&Self, &TrackElement) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId;

    /// Will be emitted after a track element was removed from the track.
    /// ## `effect`
    /// the `TrackElement` that was removed.
    fn connect_track_element_removed<F: Fn(&Self, &TrackElement) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId;

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

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

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

impl<O: IsA<Track>> GESTrackExt for O {
    fn add_element<P: IsA<TrackElement>>(&self, object: &P) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib_result_from_gboolean!(
                ges_sys::ges_track_add_element(
                    self.as_ref().to_glib_none().0,
                    object.as_ref().to_glib_none().0
                ),
                "Failed to add element"
            )
        }
    }

    fn commit(&self) -> bool {
        unsafe { from_glib(ges_sys::ges_track_commit(self.as_ref().to_glib_none().0)) }
    }

    fn get_caps(&self) -> Option<gst::Caps> {
        unsafe { from_glib_none(ges_sys::ges_track_get_caps(self.as_ref().to_glib_none().0)) }
    }

    fn get_elements(&self) -> Vec<TrackElement> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ges_sys::ges_track_get_elements(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_mixing(&self) -> bool {
        unsafe {
            from_glib(ges_sys::ges_track_get_mixing(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_timeline(&self) -> Option<Timeline> {
        unsafe {
            from_glib_none(ges_sys::ges_track_get_timeline(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn remove_element<P: IsA<TrackElement>>(
        &self,
        object: &P,
    ) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib_result_from_gboolean!(
                ges_sys::ges_track_remove_element(
                    self.as_ref().to_glib_none().0,
                    object.as_ref().to_glib_none().0
                ),
                "Failed to remove element"
            )
        }
    }

    //fn set_create_element_for_gap_func<P: Fn(&Track) -> gst::Element + 'static>(&self, func: P) {
    //    unsafe { TODO: call ges_sys:ges_track_set_create_element_for_gap_func() }
    //}

    fn set_mixing(&self, mixing: bool) {
        unsafe {
            ges_sys::ges_track_set_mixing(self.as_ref().to_glib_none().0, mixing.to_glib());
        }
    }

    fn set_restriction_caps(&self, caps: &gst::Caps) {
        unsafe {
            ges_sys::ges_track_set_restriction_caps(
                self.as_ref().to_glib_none().0,
                caps.to_glib_none().0,
            );
        }
    }

    fn set_timeline<P: IsA<Timeline>>(&self, timeline: &P) {
        unsafe {
            ges_sys::ges_track_set_timeline(
                self.as_ref().to_glib_none().0,
                timeline.as_ref().to_glib_none().0,
            );
        }
    }

    fn update_restriction_caps(&self, caps: &gst::Caps) {
        unsafe {
            ges_sys::ges_track_update_restriction_caps(
                self.as_ref().to_glib_none().0,
                caps.to_glib_none().0,
            );
        }
    }

    fn get_property_duration(&self) -> u64 {
        unsafe {
            let mut value = Value::from_type(<u64 as StaticType>::static_type());
            gobject_sys::g_object_get_property(
                self.to_glib_none().0 as *mut gobject_sys::GObject,
                b"duration\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `duration` getter")
                .unwrap()
        }
    }

    fn get_property_restriction_caps(&self) -> Option<gst::Caps> {
        unsafe {
            let mut value = Value::from_type(<gst::Caps as StaticType>::static_type());
            gobject_sys::g_object_get_property(
                self.to_glib_none().0 as *mut gobject_sys::GObject,
                b"restriction-caps\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `restriction-caps` getter")
        }
    }

    fn get_property_track_type(&self) -> TrackType {
        unsafe {
            let mut value = Value::from_type(<TrackType as StaticType>::static_type());
            gobject_sys::g_object_get_property(
                self.to_glib_none().0 as *mut gobject_sys::GObject,
                b"track-type\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `track-type` getter")
                .unwrap()
        }
    }

    fn connect_commited<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn commited_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut ges_sys::GESTrack,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Track>,
        {
            let f: &F = &*(f as *const F);
            f(&Track::from_glib_borrow(this).unsafe_cast())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"commited\0".as_ptr() as *const _,
                Some(transmute(commited_trampoline::<Self, F> as usize)),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_track_element_added<F: Fn(&Self, &TrackElement) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn track_element_added_trampoline<P, F: Fn(&P, &TrackElement) + 'static>(
            this: *mut ges_sys::GESTrack,
            effect: *mut ges_sys::GESTrackElement,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Track>,
        {
            let f: &F = &*(f as *const F);
            f(
                &Track::from_glib_borrow(this).unsafe_cast(),
                &from_glib_borrow(effect),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"track-element-added\0".as_ptr() as *const _,
                Some(transmute(
                    track_element_added_trampoline::<Self, F> as usize,
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_track_element_removed<F: Fn(&Self, &TrackElement) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn track_element_removed_trampoline<
            P,
            F: Fn(&P, &TrackElement) + 'static,
        >(
            this: *mut ges_sys::GESTrack,
            effect: *mut ges_sys::GESTrackElement,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Track>,
        {
            let f: &F = &*(f as *const F);
            f(
                &Track::from_glib_borrow(this).unsafe_cast(),
                &from_glib_borrow(effect),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"track-element-removed\0".as_ptr() as *const _,
                Some(transmute(
                    track_element_removed_trampoline::<Self, F> as usize,
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_duration_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_duration_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut ges_sys::GESTrack,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Track>,
        {
            let f: &F = &*(f as *const F);
            f(&Track::from_glib_borrow(this).unsafe_cast())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::duration\0".as_ptr() as *const _,
                Some(transmute(notify_duration_trampoline::<Self, F> as usize)),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_mixing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_mixing_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut ges_sys::GESTrack,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Track>,
        {
            let f: &F = &*(f as *const F);
            f(&Track::from_glib_borrow(this).unsafe_cast())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::mixing\0".as_ptr() as *const _,
                Some(transmute(notify_mixing_trampoline::<Self, F> as usize)),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_restriction_caps_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_restriction_caps_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut ges_sys::GESTrack,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Track>,
        {
            let f: &F = &*(f as *const F);
            f(&Track::from_glib_borrow(this).unsafe_cast())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::restriction-caps\0".as_ptr() as *const _,
                Some(transmute(
                    notify_restriction_caps_trampoline::<Self, F> as usize,
                )),
                Box_::into_raw(f),
            )
        }
    }
}