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