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
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 let f: &F = &*(f as *const F);
278 f(
279 Layer::from_glib_borrow(this).unsafe_cast_ref(),
280 &from_glib_borrow(clip),
281 )
282 }
283 unsafe {
284 let f: Box_<F> = Box_::new(f);
285 connect_raw(
286 self.as_ptr() as *mut _,
287 c"clip-added".as_ptr() as *const _,
288 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
289 clip_added_trampoline::<Self, F> as *const (),
290 )),
291 Box_::into_raw(f),
292 )
293 }
294 }
295
296 #[doc(alias = "clip-removed")]
297 fn connect_clip_removed<F: Fn(&Self, &Clip) + 'static>(&self, f: F) -> SignalHandlerId {
298 unsafe extern "C" fn clip_removed_trampoline<P: IsA<Layer>, F: Fn(&P, &Clip) + 'static>(
299 this: *mut ffi::GESLayer,
300 clip: *mut ffi::GESClip,
301 f: glib::ffi::gpointer,
302 ) {
303 let f: &F = &*(f as *const F);
304 f(
305 Layer::from_glib_borrow(this).unsafe_cast_ref(),
306 &from_glib_borrow(clip),
307 )
308 }
309 unsafe {
310 let f: Box_<F> = Box_::new(f);
311 connect_raw(
312 self.as_ptr() as *mut _,
313 c"clip-removed".as_ptr() as *const _,
314 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
315 clip_removed_trampoline::<Self, F> as *const (),
316 )),
317 Box_::into_raw(f),
318 )
319 }
320 }
321
322 #[doc(alias = "auto-transition")]
323 fn connect_auto_transition_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
324 unsafe extern "C" fn notify_auto_transition_trampoline<
325 P: IsA<Layer>,
326 F: Fn(&P) + 'static,
327 >(
328 this: *mut ffi::GESLayer,
329 _param_spec: glib::ffi::gpointer,
330 f: glib::ffi::gpointer,
331 ) {
332 let f: &F = &*(f as *const F);
333 f(Layer::from_glib_borrow(this).unsafe_cast_ref())
334 }
335 unsafe {
336 let f: Box_<F> = Box_::new(f);
337 connect_raw(
338 self.as_ptr() as *mut _,
339 c"notify::auto-transition".as_ptr() as *const _,
340 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
341 notify_auto_transition_trampoline::<Self, F> as *const (),
342 )),
343 Box_::into_raw(f),
344 )
345 }
346 }
347
348 #[cfg_attr(feature = "v1_16", deprecated = "Since 1.16")]
349 #[doc(alias = "priority")]
350 fn connect_priority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
351 unsafe extern "C" fn notify_priority_trampoline<P: IsA<Layer>, F: Fn(&P) + 'static>(
352 this: *mut ffi::GESLayer,
353 _param_spec: glib::ffi::gpointer,
354 f: glib::ffi::gpointer,
355 ) {
356 let f: &F = &*(f as *const F);
357 f(Layer::from_glib_borrow(this).unsafe_cast_ref())
358 }
359 unsafe {
360 let f: Box_<F> = Box_::new(f);
361 connect_raw(
362 self.as_ptr() as *mut _,
363 c"notify::priority".as_ptr() as *const _,
364 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
365 notify_priority_trampoline::<Self, F> as *const (),
366 )),
367 Box_::into_raw(f),
368 )
369 }
370 }
371}
372
373impl<O: IsA<Layer>> LayerExt for O {}