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