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 #[doc(alias = "ges_layer_get_timeline")]
196 #[doc(alias = "get_timeline")]
197 fn timeline(&self) -> Option<Timeline> {
198 unsafe { from_glib_none(ffi::ges_layer_get_timeline(self.as_ref().to_glib_none().0)) }
199 }
200
201 #[doc(alias = "ges_layer_is_empty")]
202 fn is_empty(&self) -> bool {
203 unsafe { from_glib(ffi::ges_layer_is_empty(self.as_ref().to_glib_none().0)) }
204 }
205
206 #[doc(alias = "ges_layer_remove_clip")]
207 fn remove_clip(&self, clip: &impl IsA<Clip>) -> Result<(), glib::error::BoolError> {
208 unsafe {
209 glib::result_from_gboolean!(
210 ffi::ges_layer_remove_clip(
211 self.as_ref().to_glib_none().0,
212 clip.as_ref().to_glib_none().0
213 ),
214 "Failed to remove clip"
215 )
216 }
217 }
218
219 #[cfg(feature = "v1_18")]
220 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
221 #[doc(alias = "ges_layer_set_active_for_tracks")]
222 fn set_active_for_tracks(&self, active: bool, tracks: &[Track]) -> bool {
223 unsafe {
224 from_glib(ffi::ges_layer_set_active_for_tracks(
225 self.as_ref().to_glib_none().0,
226 active.into_glib(),
227 tracks.to_glib_none().0,
228 ))
229 }
230 }
231
232 #[doc(alias = "ges_layer_set_auto_transition")]
233 #[doc(alias = "auto-transition")]
234 fn set_auto_transition(&self, auto_transition: bool) {
235 unsafe {
236 ffi::ges_layer_set_auto_transition(
237 self.as_ref().to_glib_none().0,
238 auto_transition.into_glib(),
239 );
240 }
241 }
242
243 #[cfg_attr(feature = "v1_16", deprecated = "Since 1.16")]
244 #[allow(deprecated)]
245 #[doc(alias = "ges_layer_set_priority")]
246 #[doc(alias = "priority")]
247 fn set_priority(&self, priority: u32) {
248 unsafe {
249 ffi::ges_layer_set_priority(self.as_ref().to_glib_none().0, priority);
250 }
251 }
252
253 #[doc(alias = "ges_layer_set_timeline")]
254 fn set_timeline(&self, timeline: &impl IsA<Timeline>) {
255 unsafe {
256 ffi::ges_layer_set_timeline(
257 self.as_ref().to_glib_none().0,
258 timeline.as_ref().to_glib_none().0,
259 );
260 }
261 }
262
263 #[doc(alias = "clip-added")]
271 fn connect_clip_added<F: Fn(&Self, &Clip) + 'static>(&self, f: F) -> SignalHandlerId {
272 unsafe extern "C" fn clip_added_trampoline<P: IsA<Layer>, F: Fn(&P, &Clip) + 'static>(
273 this: *mut ffi::GESLayer,
274 clip: *mut ffi::GESClip,
275 f: glib::ffi::gpointer,
276 ) {
277 unsafe {
278 let f: &F = &*(f as *const F);
279 f(
280 Layer::from_glib_borrow(this).unsafe_cast_ref(),
281 &from_glib_borrow(clip),
282 )
283 }
284 }
285 unsafe {
286 let f: Box_<F> = Box_::new(f);
287 connect_raw(
288 self.as_ptr() as *mut _,
289 c"clip-added".as_ptr(),
290 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
291 clip_added_trampoline::<Self, F> as *const (),
292 )),
293 Box_::into_raw(f),
294 )
295 }
296 }
297
298 #[doc(alias = "clip-removed")]
299 fn connect_clip_removed<F: Fn(&Self, &Clip) + 'static>(&self, f: F) -> SignalHandlerId {
300 unsafe extern "C" fn clip_removed_trampoline<P: IsA<Layer>, F: Fn(&P, &Clip) + 'static>(
301 this: *mut ffi::GESLayer,
302 clip: *mut ffi::GESClip,
303 f: glib::ffi::gpointer,
304 ) {
305 unsafe {
306 let f: &F = &*(f as *const F);
307 f(
308 Layer::from_glib_borrow(this).unsafe_cast_ref(),
309 &from_glib_borrow(clip),
310 )
311 }
312 }
313 unsafe {
314 let f: Box_<F> = Box_::new(f);
315 connect_raw(
316 self.as_ptr() as *mut _,
317 c"clip-removed".as_ptr(),
318 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
319 clip_removed_trampoline::<Self, F> as *const (),
320 )),
321 Box_::into_raw(f),
322 )
323 }
324 }
325
326 #[doc(alias = "auto-transition")]
327 fn connect_auto_transition_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
328 unsafe extern "C" fn notify_auto_transition_trampoline<
329 P: IsA<Layer>,
330 F: Fn(&P) + 'static,
331 >(
332 this: *mut ffi::GESLayer,
333 _param_spec: glib::ffi::gpointer,
334 f: glib::ffi::gpointer,
335 ) {
336 unsafe {
337 let f: &F = &*(f as *const F);
338 f(Layer::from_glib_borrow(this).unsafe_cast_ref())
339 }
340 }
341 unsafe {
342 let f: Box_<F> = Box_::new(f);
343 connect_raw(
344 self.as_ptr() as *mut _,
345 c"notify::auto-transition".as_ptr(),
346 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
347 notify_auto_transition_trampoline::<Self, F> as *const (),
348 )),
349 Box_::into_raw(f),
350 )
351 }
352 }
353
354 #[cfg_attr(feature = "v1_16", deprecated = "Since 1.16")]
355 #[doc(alias = "priority")]
356 fn connect_priority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
357 unsafe extern "C" fn notify_priority_trampoline<P: IsA<Layer>, F: Fn(&P) + 'static>(
358 this: *mut ffi::GESLayer,
359 _param_spec: glib::ffi::gpointer,
360 f: glib::ffi::gpointer,
361 ) {
362 unsafe {
363 let f: &F = &*(f as *const F);
364 f(Layer::from_glib_borrow(this).unsafe_cast_ref())
365 }
366 }
367 unsafe {
368 let f: Box_<F> = Box_::new(f);
369 connect_raw(
370 self.as_ptr() as *mut _,
371 c"notify::priority".as_ptr(),
372 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
373 notify_priority_trampoline::<Self, F> as *const (),
374 )),
375 Box_::into_raw(f),
376 )
377 }
378 }
379}
380
381impl<O: IsA<Layer>> LayerExt for O {}