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
// 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_sys;
use gst;
use std::boxed::Box as Box_;
use std::mem::transmute;
use Asset;
use Clip;
use Extractable;
use Timeline;
use TrackType;

glib_wrapper! {
    /// Responsible for the ordering of the various contained Clip(s). A
    /// timeline layer has a "priority" property, which is used to manage the
    /// priorities of individual Clips. Two layers should not have the
    /// same priority within a given timeline.
    ///
    /// # Implements
    ///
    /// [`LayerExt`](trait.LayerExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html), [`ExtractableExt`](trait.ExtractableExt.html)
    pub struct Layer(Object<ges_sys::GESLayer, ges_sys::GESLayerClass, LayerClass>) @implements Extractable;

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

impl Layer {
    /// Creates a new `Layer`.
    ///
    /// # Returns
    ///
    /// A new `Layer`
    pub fn new() -> Layer {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ges_sys::ges_layer_new()) }
    }
}

impl Default for Layer {
    fn default() -> Self {
        Self::new()
    }
}

pub const NONE_LAYER: Option<&Layer> = None;

/// Trait containing all `Layer` methods.
///
/// # Implementors
///
/// [`Layer`](struct.Layer.html)
pub trait LayerExt: 'static {
    /// Creates Clip from asset, adds it to layer and
    /// returns a reference to it.
    /// ## `asset`
    /// The asset to add to
    /// ## `start`
    /// The start value to set on the new `Clip`,
    /// if `start` == GST_CLOCK_TIME_NONE, it will be set to
    /// the current duration of `self`
    /// ## `inpoint`
    /// The inpoint value to set on the new `Clip`
    /// ## `duration`
    /// The duration value to set on the new `Clip`
    /// ## `track_types`
    /// The `TrackType` to set on the the new `Clip`
    ///
    /// # Returns
    ///
    /// Created `Clip`
    fn add_asset<P: IsA<Asset>>(
        &self,
        asset: &P,
        start: gst::ClockTime,
        inpoint: gst::ClockTime,
        duration: gst::ClockTime,
        track_types: TrackType,
    ) -> Result<Clip, glib::BoolError>;

    /// Adds the given clip to the layer. Sets the clip's parent, and thus
    /// takes ownership of the clip.
    ///
    /// An clip can only be added to one layer.
    ///
    /// Calling this method will construct and properly set all the media related
    /// elements on `clip`. If you need to know when those objects (actually `TrackElement`)
    /// are constructed, you should connect to the container::child-added signal which
    /// is emited right after those elements are ready to be used.
    /// ## `clip`
    /// the `Clip` to add.
    ///
    /// # Returns
    ///
    /// `true` if the clip was properly added to the layer, or `false`
    /// if the `self` refuses to add the clip.
    fn add_clip<P: IsA<Clip>>(&self, clip: &P) -> Result<(), glib::error::BoolError>;

    /// Gets whether transitions are automatically added when objects
    /// overlap or not.
    ///
    /// # Returns
    ///
    /// `true` if transitions are automatically added, else `false`.
    fn get_auto_transition(&self) -> bool;

    /// Get the clips this layer contains.
    ///
    /// # Returns
    ///
    /// a `glib::List` of
    /// clips. The user is responsible for
    /// unreffing the contained objects and freeing the list.
    fn get_clips(&self) -> Vec<Clip>;

    /// Gets the clips which appear between `start` and `end` on `self`.
    /// ## `start`
    /// start of the interval
    /// ## `end`
    /// end of the interval
    ///
    /// # Returns
    ///
    /// a `glib::List` of clips intersecting [`start`, `end`) interval on `self`.
    fn get_clips_in_interval(&self, start: gst::ClockTime, end: gst::ClockTime) -> Vec<Clip>;

    /// Lets you retrieve the duration of the layer, which means
    /// the end time of the last clip inside it
    ///
    /// # Returns
    ///
    /// The duration of a layer
    fn get_duration(&self) -> gst::ClockTime;

    /// Get the priority of `self` within the timeline.
    ///
    /// # Returns
    ///
    /// The priority of the `self` within the timeline.
    fn get_priority(&self) -> u32;

    /// Get the `Timeline` in which `Layer` currently is.
    ///
    /// # Returns
    ///
    /// the `Timeline` in which `Layer`
    /// currently is or `None` if not in any timeline yet.
    fn get_timeline(&self) -> Option<Timeline>;

    /// Convenience method to check if `self` is empty (doesn't contain any clip),
    /// or not.
    ///
    /// # Returns
    ///
    /// `true` if `self` is empty, `false` if it already contains at least
    /// one `Clip`
    fn is_empty(&self) -> bool;

    /// Removes the given `clip` from the `self` and unparents it.
    /// Unparenting it means the reference owned by `self` on the `clip` will be
    /// removed. If you wish to use the `clip` after this function, make sure you
    /// call `gst::ObjectExt::ref` before removing it from the `self`.
    /// ## `clip`
    /// the `Clip` to remove
    ///
    /// # Returns
    ///
    /// `true` if the clip could be removed, `false` if the layer does
    /// not want to remove the clip.
    fn remove_clip<P: IsA<Clip>>(&self, clip: &P) -> Result<(), glib::error::BoolError>;

    /// Sets the layer to the given `auto_transition`. See the documentation of the
    /// property auto_transition for more information.
    /// ## `auto_transition`
    /// whether the auto_transition is active
    fn set_auto_transition(&self, auto_transition: bool);

    /// Sets the layer to the given `priority`. See the documentation of the
    /// priority property for more information.
    ///
    /// # Deprecated since 1.16
    ///
    /// use `TimelineExt::move_layer` instead. This deprecation means
    /// that you will not need to handle layer priorities at all yourself, GES
    /// will make sure there is never 'gaps' between layer priorities.
    /// ## `priority`
    /// the priority to set
    #[cfg_attr(feature = "v1_16", deprecated)]
    fn set_priority(&self, priority: u32);

    fn set_timeline<P: IsA<Timeline>>(&self, timeline: &P);

    /// Will be emitted after the clip was added to the layer.
    /// ## `clip`
    /// the `Clip` that was added.
    fn connect_clip_added<F: Fn(&Self, &Clip) + 'static>(&self, f: F) -> SignalHandlerId;

    /// Will be emitted after the clip was removed from the layer.
    /// ## `clip`
    /// the `Clip` that was removed
    fn connect_clip_removed<F: Fn(&Self, &Clip) + 'static>(&self, f: F) -> SignalHandlerId;

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

    #[cfg_attr(feature = "v1_16", deprecated)]
    fn connect_property_priority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Layer>> LayerExt for O {
    fn add_asset<P: IsA<Asset>>(
        &self,
        asset: &P,
        start: gst::ClockTime,
        inpoint: gst::ClockTime,
        duration: gst::ClockTime,
        track_types: TrackType,
    ) -> Result<Clip, glib::BoolError> {
        unsafe {
            Option::<_>::from_glib_none(ges_sys::ges_layer_add_asset(
                self.as_ref().to_glib_none().0,
                asset.as_ref().to_glib_none().0,
                start.to_glib(),
                inpoint.to_glib(),
                duration.to_glib(),
                track_types.to_glib(),
            ))
            .ok_or_else(|| glib_bool_error!("Failed to add asset"))
        }
    }

    fn add_clip<P: IsA<Clip>>(&self, clip: &P) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib_result_from_gboolean!(
                ges_sys::ges_layer_add_clip(
                    self.as_ref().to_glib_none().0,
                    clip.as_ref().to_glib_none().0
                ),
                "Failed to add clip"
            )
        }
    }

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

    fn get_clips(&self) -> Vec<Clip> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ges_sys::ges_layer_get_clips(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_clips_in_interval(&self, start: gst::ClockTime, end: gst::ClockTime) -> Vec<Clip> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ges_sys::ges_layer_get_clips_in_interval(
                self.as_ref().to_glib_none().0,
                start.to_glib(),
                end.to_glib(),
            ))
        }
    }

    fn get_duration(&self) -> gst::ClockTime {
        unsafe {
            from_glib(ges_sys::ges_layer_get_duration(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_priority(&self) -> u32 {
        unsafe { ges_sys::ges_layer_get_priority(self.as_ref().to_glib_none().0) }
    }

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

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

    fn remove_clip<P: IsA<Clip>>(&self, clip: &P) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib_result_from_gboolean!(
                ges_sys::ges_layer_remove_clip(
                    self.as_ref().to_glib_none().0,
                    clip.as_ref().to_glib_none().0
                ),
                "Failed to remove clip"
            )
        }
    }

    fn set_auto_transition(&self, auto_transition: bool) {
        unsafe {
            ges_sys::ges_layer_set_auto_transition(
                self.as_ref().to_glib_none().0,
                auto_transition.to_glib(),
            );
        }
    }

    fn set_priority(&self, priority: u32) {
        unsafe {
            ges_sys::ges_layer_set_priority(self.as_ref().to_glib_none().0, priority);
        }
    }

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

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

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

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

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