gstreamer_editing_services/auto/
layer.rs1#![allow(deprecated)]
6
7#[cfg(feature = "v1_18")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
9use crate::Track;
10use crate::{Asset, Clip, Extractable, MetaContainer, Timeline, TrackType, ffi};
11use glib::{
12 object::ObjectType as _,
13 prelude::*,
14 signal::{SignalHandlerId, connect_raw},
15 translate::*,
16};
17use std::boxed::Box as Box_;
18
19glib::wrapper! {
20 #[doc(alias = "GESLayer")]
21 pub struct Layer(Object<ffi::GESLayer, ffi::GESLayerClass>) @implements Extractable, MetaContainer;
22
23 match fn {
24 type_ => || ffi::ges_layer_get_type(),
25 }
26}
27
28impl Layer {
29 pub const NONE: Option<&'static Layer> = None;
30
31 #[doc(alias = "ges_layer_new")]
32 pub fn new() -> Layer {
33 assert_initialized_main_thread!();
34 unsafe { from_glib_none(ffi::ges_layer_new()) }
35 }
36}
37
38impl Default for Layer {
39 fn default() -> Self {
40 Self::new()
41 }
42}
43
44pub trait LayerExt: IsA<Layer> + 'static {
45 #[doc(alias = "ges_layer_add_asset")]
46 fn add_asset(
47 &self,
48 asset: &impl IsA<Asset>,
49 start: impl Into<Option<gst::ClockTime>>,
50 inpoint: impl Into<Option<gst::ClockTime>>,
51 duration: impl Into<Option<gst::ClockTime>>,
52 track_types: TrackType,
53 ) -> Result<Clip, glib::BoolError> {
54 unsafe {
55 Option::<_>::from_glib_none(ffi::ges_layer_add_asset(
56 self.as_ref().to_glib_none().0,
57 asset.as_ref().to_glib_none().0,
58 start.into().into_glib(),
59 inpoint.into().into_glib(),
60 duration.into().into_glib(),
61 track_types.into_glib(),
62 ))
63 .ok_or_else(|| glib::bool_error!("Failed to add asset"))
64 }
65 }
66
67 #[cfg(feature = "v1_18")]
68 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
69 #[doc(alias = "ges_layer_add_asset_full")]
70 fn add_asset_full(
71 &self,
72 asset: &impl IsA<Asset>,
73 start: impl Into<Option<gst::ClockTime>>,
74 inpoint: impl Into<Option<gst::ClockTime>>,
75 duration: impl Into<Option<gst::ClockTime>>,
76 track_types: TrackType,
77 ) -> Result<Clip, glib::Error> {
78 unsafe {
79 let mut error = std::ptr::null_mut();
80 let ret = ffi::ges_layer_add_asset_full(
81 self.as_ref().to_glib_none().0,
82 asset.as_ref().to_glib_none().0,
83 start.into().into_glib(),
84 inpoint.into().into_glib(),
85 duration.into().into_glib(),
86 track_types.into_glib(),
87 &mut error,
88 );
89 if error.is_null() {
90 Ok(from_glib_none(ret))
91 } else {
92 Err(from_glib_full(error))
93 }
94 }
95 }
96
97 #[doc(alias = "ges_layer_add_clip")]
98 fn add_clip(&self, clip: &impl IsA<Clip>) -> Result<(), glib::error::BoolError> {
99 unsafe {
100 glib::result_from_gboolean!(
101 ffi::ges_layer_add_clip(
102 self.as_ref().to_glib_none().0,
103 clip.as_ref().to_glib_none().0
104 ),
105 "Failed to add clip"
106 )
107 }
108 }
109
110 #[cfg(feature = "v1_18")]
111 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
112 #[doc(alias = "ges_layer_add_clip_full")]
113 fn add_clip_full(&self, clip: &impl IsA<Clip>) -> Result<(), glib::Error> {
114 unsafe {
115 let mut error = std::ptr::null_mut();
116 let is_ok = ffi::ges_layer_add_clip_full(
117 self.as_ref().to_glib_none().0,
118 clip.as_ref().to_glib_none().0,
119 &mut error,
120 );
121 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
122 if error.is_null() {
123 Ok(())
124 } else {
125 Err(from_glib_full(error))
126 }
127 }
128 }
129
130 #[cfg(feature = "v1_18")]
131 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
132 #[doc(alias = "ges_layer_get_active_for_track")]
133 #[doc(alias = "get_active_for_track")]
134 fn is_active_for_track(&self, track: &impl IsA<Track>) -> bool {
135 unsafe {
136 from_glib(ffi::ges_layer_get_active_for_track(
137 self.as_ref().to_glib_none().0,
138 track.as_ref().to_glib_none().0,
139 ))
140 }
141 }
142
143 #[doc(alias = "ges_layer_get_auto_transition")]
144 #[doc(alias = "get_auto_transition")]
145 #[doc(alias = "auto-transition")]
146 fn is_auto_transition(&self) -> bool {
147 unsafe {
148 from_glib(ffi::ges_layer_get_auto_transition(
149 self.as_ref().to_glib_none().0,
150 ))
151 }
152 }
153
154 #[doc(alias = "ges_layer_get_clips")]
155 #[doc(alias = "get_clips")]
156 fn clips(&self) -> Vec<Clip> {
157 unsafe {
158 FromGlibPtrContainer::from_glib_full(ffi::ges_layer_get_clips(
159 self.as_ref().to_glib_none().0,
160 ))
161 }
162 }
163
164 #[doc(alias = "ges_layer_get_clips_in_interval")]
165 #[doc(alias = "get_clips_in_interval")]
166 fn clips_in_interval(
167 &self,
168 start: impl Into<Option<gst::ClockTime>>,
169 end: impl Into<Option<gst::ClockTime>>,
170 ) -> Vec<Clip> {
171 unsafe {
172 FromGlibPtrContainer::from_glib_full(ffi::ges_layer_get_clips_in_interval(
173 self.as_ref().to_glib_none().0,
174 start.into().into_glib(),
175 end.into().into_glib(),
176 ))
177 }
178 }
179
180 #[doc(alias = "ges_layer_get_duration")]
181 #[doc(alias = "get_duration")]
182 fn duration(&self) -> gst::ClockTime {
183 unsafe {
184 try_from_glib(ffi::ges_layer_get_duration(self.as_ref().to_glib_none().0))
185 .expect("mandatory glib value is None")
186 }
187 }
188
189 #[doc(alias = "ges_layer_get_priority")]
190 #[doc(alias = "get_priority")]
191 fn priority(&self) -> u32 {
192 unsafe { ffi::ges_layer_get_priority(self.as_ref().to_glib_none().0) }
193 }
194
195 #[cfg_attr(feature = "v1_30", deprecated = "Since 1.30")]
196 #[allow(deprecated)]
197 #[doc(alias = "ges_layer_get_timeline")]
198 #[doc(alias = "get_timeline")]
199 fn timeline(&self) -> Option<Timeline> {
200 unsafe { from_glib_none(ffi::ges_layer_get_timeline(self.as_ref().to_glib_none().0)) }
201 }
202
203 #[cfg(feature = "v1_30")]
204 #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
205 #[doc(alias = "ges_layer_get_timeline_full")]
206 #[doc(alias = "get_timeline_full")]
207 fn timeline_full(&self) -> Option<Timeline> {
208 unsafe {
209 from_glib_full(ffi::ges_layer_get_timeline_full(
210 self.as_ref().to_glib_none().0,
211 ))
212 }
213 }
214
215 #[doc(alias = "ges_layer_is_empty")]
216 fn is_empty(&self) -> bool {
217 unsafe { from_glib(ffi::ges_layer_is_empty(self.as_ref().to_glib_none().0)) }
218 }
219
220 #[doc(alias = "ges_layer_remove_clip")]
221 fn remove_clip(&self, clip: &impl IsA<Clip>) -> Result<(), glib::error::BoolError> {
222 unsafe {
223 glib::result_from_gboolean!(
224 ffi::ges_layer_remove_clip(
225 self.as_ref().to_glib_none().0,
226 clip.as_ref().to_glib_none().0
227 ),
228 "Failed to remove clip"
229 )
230 }
231 }
232
233 #[cfg(feature = "v1_18")]
234 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
235 #[doc(alias = "ges_layer_set_active_for_tracks")]
236 fn set_active_for_tracks(&self, active: bool, tracks: &[Track]) -> bool {
237 unsafe {
238 from_glib(ffi::ges_layer_set_active_for_tracks(
239 self.as_ref().to_glib_none().0,
240 active.into_glib(),
241 tracks.to_glib_none().0,
242 ))
243 }
244 }
245
246 #[doc(alias = "ges_layer_set_auto_transition")]
247 #[doc(alias = "auto-transition")]
248 fn set_auto_transition(&self, auto_transition: bool) {
249 unsafe {
250 ffi::ges_layer_set_auto_transition(
251 self.as_ref().to_glib_none().0,
252 auto_transition.into_glib(),
253 );
254 }
255 }
256
257 #[cfg_attr(feature = "v1_16", deprecated = "Since 1.16")]
258 #[allow(deprecated)]
259 #[doc(alias = "ges_layer_set_priority")]
260 #[doc(alias = "priority")]
261 fn set_priority(&self, priority: u32) {
262 unsafe {
263 ffi::ges_layer_set_priority(self.as_ref().to_glib_none().0, priority);
264 }
265 }
266
267 #[doc(alias = "ges_layer_set_timeline")]
268 fn set_timeline(&self, timeline: &impl IsA<Timeline>) {
269 unsafe {
270 ffi::ges_layer_set_timeline(
271 self.as_ref().to_glib_none().0,
272 timeline.as_ref().to_glib_none().0,
273 );
274 }
275 }
276
277 #[doc(alias = "clip-added")]
285 fn connect_clip_added<F: Fn(&Self, &Clip) + 'static>(&self, f: F) -> SignalHandlerId {
286 unsafe extern "C" fn clip_added_trampoline<P: IsA<Layer>, F: Fn(&P, &Clip) + 'static>(
287 this: *mut ffi::GESLayer,
288 clip: *mut ffi::GESClip,
289 f: glib::ffi::gpointer,
290 ) {
291 unsafe {
292 let f: &F = &*(f as *const F);
293 f(
294 Layer::from_glib_borrow(this).unsafe_cast_ref(),
295 &from_glib_borrow(clip),
296 )
297 }
298 }
299 unsafe {
300 let f: Box_<F> = Box_::new(f);
301 connect_raw(
302 self.as_ptr() as *mut _,
303 c"clip-added".as_ptr(),
304 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
305 clip_added_trampoline::<Self, F> as *const (),
306 )),
307 Box_::into_raw(f),
308 )
309 }
310 }
311
312 #[doc(alias = "clip-removed")]
313 fn connect_clip_removed<F: Fn(&Self, &Clip) + 'static>(&self, f: F) -> SignalHandlerId {
314 unsafe extern "C" fn clip_removed_trampoline<P: IsA<Layer>, F: Fn(&P, &Clip) + 'static>(
315 this: *mut ffi::GESLayer,
316 clip: *mut ffi::GESClip,
317 f: glib::ffi::gpointer,
318 ) {
319 unsafe {
320 let f: &F = &*(f as *const F);
321 f(
322 Layer::from_glib_borrow(this).unsafe_cast_ref(),
323 &from_glib_borrow(clip),
324 )
325 }
326 }
327 unsafe {
328 let f: Box_<F> = Box_::new(f);
329 connect_raw(
330 self.as_ptr() as *mut _,
331 c"clip-removed".as_ptr(),
332 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
333 clip_removed_trampoline::<Self, F> as *const (),
334 )),
335 Box_::into_raw(f),
336 )
337 }
338 }
339
340 #[doc(alias = "auto-transition")]
341 fn connect_auto_transition_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
342 unsafe extern "C" fn notify_auto_transition_trampoline<
343 P: IsA<Layer>,
344 F: Fn(&P) + 'static,
345 >(
346 this: *mut ffi::GESLayer,
347 _param_spec: glib::ffi::gpointer,
348 f: glib::ffi::gpointer,
349 ) {
350 unsafe {
351 let f: &F = &*(f as *const F);
352 f(Layer::from_glib_borrow(this).unsafe_cast_ref())
353 }
354 }
355 unsafe {
356 let f: Box_<F> = Box_::new(f);
357 connect_raw(
358 self.as_ptr() as *mut _,
359 c"notify::auto-transition".as_ptr(),
360 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
361 notify_auto_transition_trampoline::<Self, F> as *const (),
362 )),
363 Box_::into_raw(f),
364 )
365 }
366 }
367
368 #[cfg_attr(feature = "v1_16", deprecated = "Since 1.16")]
369 #[doc(alias = "priority")]
370 fn connect_priority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
371 unsafe extern "C" fn notify_priority_trampoline<P: IsA<Layer>, F: Fn(&P) + 'static>(
372 this: *mut ffi::GESLayer,
373 _param_spec: glib::ffi::gpointer,
374 f: glib::ffi::gpointer,
375 ) {
376 unsafe {
377 let f: &F = &*(f as *const F);
378 f(Layer::from_glib_borrow(this).unsafe_cast_ref())
379 }
380 }
381 unsafe {
382 let f: Box_<F> = Box_::new(f);
383 connect_raw(
384 self.as_ptr() as *mut _,
385 c"notify::priority".as_ptr(),
386 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
387 notify_priority_trampoline::<Self, F> as *const (),
388 )),
389 Box_::into_raw(f),
390 )
391 }
392 }
393}
394
395impl<O: IsA<Layer>> LayerExt for O {}