gstreamer_editing_services/
composition_meta.rs
1use std::fmt;
4
5use crate::ffi;
6use glib::translate::from_glib;
7use gst::prelude::*;
8
9#[repr(transparent)]
13#[doc(alias = "GESFrameCompositionMeta")]
14pub struct FrameCompositionMeta(ffi::GESFrameCompositionMeta);
15
16unsafe impl Send for FrameCompositionMeta {}
17
18unsafe impl Sync for FrameCompositionMeta {}
19
20impl FrameCompositionMeta {
21 #[inline]
22 pub fn alpha(&self) -> f64 {
23 self.0.alpha
24 }
25
26 #[inline]
27 pub fn set_alpha(&mut self, alpha: f64) {
28 self.0.alpha = alpha;
29 }
30
31 #[inline]
32 pub fn position(&self) -> (f64, f64) {
33 (self.0.posx, self.0.posy)
34 }
35
36 #[inline]
37 pub fn set_position(&mut self, posx: f64, posy: f64) {
38 self.0.posx = posx;
39 self.0.posy = posy;
40 }
41
42 #[inline]
43 pub fn pos_x(&self) -> f64 {
44 self.0.posx
45 }
46
47 #[inline]
48 pub fn set_pos_x(&mut self, pos_x: f64) {
49 self.0.posx = pos_x;
50 }
51
52 #[inline]
53 pub fn pos_y(&self) -> f64 {
54 self.0.posy
55 }
56
57 #[inline]
58 pub fn set_pos_y(&mut self, pos_y: f64) {
59 self.0.posy = pos_y;
60 }
61
62 #[inline]
63 pub fn size(&self) -> (f64, f64) {
64 (self.0.width, self.0.height)
65 }
66
67 pub fn set_size(&mut self, width: f64, height: f64) {
68 self.0.width = width;
69 self.0.height = height;
70 }
71
72 #[inline]
73 pub fn width(&self) -> f64 {
74 self.0.width
75 }
76
77 #[inline]
78 pub fn set_width(&mut self, width: f64) {
79 self.0.width = width;
80 }
81
82 #[inline]
83 pub fn height(&self) -> f64 {
84 self.0.height
85 }
86
87 #[inline]
88 pub fn set_height(&mut self, height: f64) {
89 self.0.height = height;
90 }
91
92 #[inline]
93 pub fn zorder(&self) -> u32 {
94 self.0.zorder
95 }
96
97 #[inline]
98 pub fn set_zorder(&mut self, zorder: u32) {
99 self.0.zorder = zorder;
100 }
101
102 #[inline]
103 pub fn operator(&self) -> i32 {
104 self.0.operator
105 }
106
107 #[inline]
108 pub fn set_operator(&mut self, operator: i32) {
109 self.0.operator = operator;
110 }
111}
112
113unsafe impl MetaAPI for FrameCompositionMeta {
114 type GstType = ffi::GESFrameCompositionMeta;
115
116 #[doc(alias = "ges_frame_composition_meta_api_get_type")]
117 #[inline]
118 fn meta_api() -> glib::Type {
119 unsafe { from_glib(ffi::ges_frame_composition_meta_api_get_type()) }
120 }
121}
122
123impl fmt::Debug for FrameCompositionMeta {
124 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
125 f.debug_struct("FrameCompositionMeta")
126 .field("pos-x", &self.pos_x())
127 .field("pos-y", &self.pos_y())
128 .field("width", &self.width())
129 .field("height", &self.height())
130 .field("zorder", &self.zorder())
131 .field("alpha", &self.alpha())
132 .field("operator", &self.operator())
133 .finish()
134 }
135}
136
137#[cfg(test)]
138mod tests {
139 use super::*;
140
141 fn add_composition_meta(
142 buffer: &mut gst::BufferRef,
143 position: (f64, f64),
144 size: (f64, f64),
145 alpha: f64,
146 zorder: u32,
147 operator: i32,
148 ) -> Result<gst::MetaRefMut<FrameCompositionMeta, gst::meta::Standalone>, glib::BoolError> {
149 assert_initialized_main_thread!();
150
151 unsafe {
152 let meta = ffi::ges_buffer_add_frame_composition_meta(buffer.as_mut_ptr());
153
154 if meta.is_null() {
155 return Err(glib::bool_error!("Failed to add frame composition meta"));
156 }
157
158 let mut result = FrameCompositionMeta::from_mut_ptr(buffer, meta);
159 result.0.posx = position.0;
160 result.0.posy = position.1;
161 result.0.width = size.0;
162 result.0.height = size.1;
163 result.0.alpha = alpha;
164 result.0.zorder = zorder;
165 result.0.operator = operator;
166 Ok(result)
167 }
168 }
169
170 #[test]
171 fn test_add_get_meta() {
172 gst::init().unwrap();
173 crate::init().unwrap();
174
175 let mut buffer = gst::Buffer::with_size(320 * 240 * 4).unwrap();
176 {
177 let _meta = add_composition_meta(
178 buffer.get_mut().unwrap(),
179 (42., 42.),
180 (20., 22.),
181 0.42,
182 2,
183 42,
184 )
185 .unwrap();
186 }
187
188 {
189 let meta = buffer.meta::<FrameCompositionMeta>().unwrap();
190 assert_eq!(meta.position(), (42., 42.));
191 assert_eq!(meta.size(), (20., 22.));
192 assert_eq!(meta.alpha(), 0.42);
193 assert_eq!(meta.zorder(), 2);
194 assert_eq!(meta.operator(), 42);
195 }
196 }
197}