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
163
164
165
166
167
168
169
use Bus;
use Device;
use DeviceProviderFactory;
use Object;
use Plugin;
use ffi;
use glib;
use glib::object::Downcast;
use glib::object::IsA;
use glib::signal::SignalHandlerId;
use glib::signal::connect;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use libc;
use std::boxed::Box as Box_;
use std::mem;
use std::mem::transmute;
use std::ptr;
glib_wrapper! {
pub struct DeviceProvider(Object<ffi::GstDeviceProvider, ffi::GstDeviceProviderClass>): Object;
match fn {
get_type => || ffi::gst_device_provider_get_type(),
}
}
impl DeviceProvider {
pub fn register<'a, P: Into<Option<&'a Plugin>>>(plugin: P, name: &str, rank: u32, type_: glib::types::Type) -> bool {
assert_initialized_main_thread!();
let plugin = plugin.into();
let plugin = plugin.to_glib_none();
unsafe {
from_glib(ffi::gst_device_provider_register(plugin.0, name.to_glib_none().0, rank, type_.to_glib()))
}
}
}
unsafe impl Send for DeviceProvider {}
unsafe impl Sync for DeviceProvider {}
pub trait DeviceProviderExt {
fn can_monitor(&self) -> bool;
fn device_add(&self, device: &Device);
fn device_remove(&self, device: &Device);
fn get_bus(&self) -> Bus;
fn get_devices(&self) -> Vec<Device>;
fn get_factory(&self) -> Option<DeviceProviderFactory>;
fn get_hidden_providers(&self) -> Vec<String>;
fn hide_provider(&self, name: &str);
fn start(&self) -> Result<(), glib::error::BoolError>;
fn stop(&self);
fn unhide_provider(&self, name: &str);
fn connect_provider_hidden<F: Fn(&Self, &str) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_provider_unhidden<F: Fn(&Self, &str) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<DeviceProvider> + IsA<glib::object::Object>> DeviceProviderExt for O {
fn can_monitor(&self) -> bool {
unsafe {
from_glib(ffi::gst_device_provider_can_monitor(self.to_glib_none().0))
}
}
fn device_add(&self, device: &Device) {
unsafe {
ffi::gst_device_provider_device_add(self.to_glib_none().0, device.to_glib_none().0);
}
}
fn device_remove(&self, device: &Device) {
unsafe {
ffi::gst_device_provider_device_remove(self.to_glib_none().0, device.to_glib_none().0);
}
}
fn get_bus(&self) -> Bus {
unsafe {
from_glib_full(ffi::gst_device_provider_get_bus(self.to_glib_none().0))
}
}
fn get_devices(&self) -> Vec<Device> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::gst_device_provider_get_devices(self.to_glib_none().0))
}
}
fn get_factory(&self) -> Option<DeviceProviderFactory> {
unsafe {
from_glib_none(ffi::gst_device_provider_get_factory(self.to_glib_none().0))
}
}
fn get_hidden_providers(&self) -> Vec<String> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::gst_device_provider_get_hidden_providers(self.to_glib_none().0))
}
}
fn hide_provider(&self, name: &str) {
unsafe {
ffi::gst_device_provider_hide_provider(self.to_glib_none().0, name.to_glib_none().0);
}
}
fn start(&self) -> Result<(), glib::error::BoolError> {
unsafe {
glib::error::BoolError::from_glib(ffi::gst_device_provider_start(self.to_glib_none().0), "Failed to start")
}
}
fn stop(&self) {
unsafe {
ffi::gst_device_provider_stop(self.to_glib_none().0);
}
}
fn unhide_provider(&self, name: &str) {
unsafe {
ffi::gst_device_provider_unhide_provider(self.to_glib_none().0, name.to_glib_none().0);
}
}
fn connect_provider_hidden<F: Fn(&Self, &str) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&Self, &str) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "provider-hidden",
transmute(provider_hidden_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
}
}
fn connect_provider_unhidden<F: Fn(&Self, &str) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&Self, &str) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "provider-unhidden",
transmute(provider_unhidden_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
}
}
}
unsafe extern "C" fn provider_hidden_trampoline<P>(this: *mut ffi::GstDeviceProvider, object: *mut libc::c_char, f: glib_ffi::gpointer)
where P: IsA<DeviceProvider> {
let f: &&(Fn(&P, &str) + Send + Sync + 'static) = transmute(f);
f(&DeviceProvider::from_glib_borrow(this).downcast_unchecked(), &String::from_glib_none(object))
}
unsafe extern "C" fn provider_unhidden_trampoline<P>(this: *mut ffi::GstDeviceProvider, object: *mut libc::c_char, f: glib_ffi::gpointer)
where P: IsA<DeviceProvider> {
let f: &&(Fn(&P, &str) + Send + Sync + 'static) = transmute(f);
f(&DeviceProvider::from_glib_borrow(this).downcast_unchecked(), &String::from_glib_none(object))
}