1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
use crate::GLBaseFilter;
use crate::GLMemory;
use crate::GLShader;
use glib::object::IsA;
use glib::translate::*;
glib::wrapper! {
pub struct GLFilter(Object<ffi::GstGLFilter, ffi::GstGLFilterClass>) @extends GLBaseFilter, gst_base::BaseTransform, gst::Element, gst::Object;
match fn {
type_ => || ffi::gst_gl_filter_get_type(),
}
}
unsafe impl Send for GLFilter {}
unsafe impl Sync for GLFilter {}
pub const NONE_GL_FILTER: Option<&GLFilter> = None;
pub trait GLFilterExt: 'static {
#[doc(alias = "gst_gl_filter_draw_fullscreen_quad")]
fn draw_fullscreen_quad(&self);
#[doc(alias = "gst_gl_filter_filter_texture")]
fn filter_texture(
&self,
input: &gst::Buffer,
output: &gst::Buffer,
) -> Result<(), glib::error::BoolError>;
#[doc(alias = "gst_gl_filter_render_to_target")]
fn render_to_target<P: FnMut(&GLFilter, &GLMemory) -> bool>(
&self,
input: &GLMemory,
output: &GLMemory,
func: P,
) -> Result<(), glib::error::BoolError>;
#[doc(alias = "gst_gl_filter_render_to_target_with_shader")]
fn render_to_target_with_shader(&self, input: &GLMemory, output: &GLMemory, shader: &GLShader);
}
impl<O: IsA<GLFilter>> GLFilterExt for O {
fn draw_fullscreen_quad(&self) {
unsafe {
ffi::gst_gl_filter_draw_fullscreen_quad(self.as_ref().to_glib_none().0);
}
}
fn filter_texture(
&self,
input: &gst::Buffer,
output: &gst::Buffer,
) -> Result<(), glib::error::BoolError> {
unsafe {
glib::result_from_gboolean!(
ffi::gst_gl_filter_filter_texture(
self.as_ref().to_glib_none().0,
input.to_glib_none().0,
output.to_glib_none().0
),
"Failed to transform texture"
)
}
}
fn render_to_target<P: FnMut(&GLFilter, &GLMemory) -> bool>(
&self,
input: &GLMemory,
output: &GLMemory,
func: P,
) -> Result<(), glib::error::BoolError> {
let func_data: P = func;
unsafe extern "C" fn func_func<P: FnMut(&GLFilter, &GLMemory) -> bool>(
filter: *mut ffi::GstGLFilter,
in_tex: *mut ffi::GstGLMemory,
user_data: glib::ffi::gpointer,
) -> glib::ffi::gboolean {
let filter = from_glib_borrow(filter);
let in_tex = from_glib_borrow(in_tex);
let callback: *mut P = user_data as *const _ as usize as *mut P;
let res = (*callback)(&filter, &in_tex);
res.into_glib()
}
let func = Some(func_func::<P> as _);
let super_callback0: &P = &func_data;
unsafe {
glib::result_from_gboolean!(
ffi::gst_gl_filter_render_to_target(
self.as_ref().to_glib_none().0,
mut_override(input.to_glib_none().0),
mut_override(output.to_glib_none().0),
func,
super_callback0 as *const _ as usize as *mut _
),
"`func` returned `false`"
)
}
}
fn render_to_target_with_shader(&self, input: &GLMemory, output: &GLMemory, shader: &GLShader) {
unsafe {
ffi::gst_gl_filter_render_to_target_with_shader(
self.as_ref().to_glib_none().0,
mut_override(input.to_glib_none().0),
mut_override(output.to_glib_none().0),
shader.to_glib_none().0,
);
}
}
}