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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use RTSPMedia;
use RTSPSessionMedia;
use ffi;
use glib;
use glib::StaticType;
use glib::Value;
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 std::boxed::Box as Box_;
use std::mem;
use std::mem::transmute;
use std::ptr;

glib_wrapper! {
    /// Session information kept by the server for a specific client.
    /// One client session, identified with a session id, can handle multiple medias
    /// identified with the url of a media.
    ///
    /// # Implements
    ///
    /// [`RTSPSessionExt`](trait.RTSPSessionExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html)
    pub struct RTSPSession(Object<ffi::GstRTSPSession, ffi::GstRTSPSessionClass>);

    match fn {
        get_type => || ffi::gst_rtsp_session_get_type(),
    }
}

impl RTSPSession {
    /// Create a new `RTSPSession` instance with `sessionid`.
    /// ## `sessionid`
    /// a session id
    ///
    /// # Returns
    ///
    /// a new `RTSPSession`
    pub fn new(sessionid: &str) -> RTSPSession {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gst_rtsp_session_new(sessionid.to_glib_none().0))
        }
    }
}

unsafe impl Send for RTSPSession {}
unsafe impl Sync for RTSPSession {}

/// Trait containing all `RTSPSession` methods.
///
/// # Implementors
///
/// [`RTSPSession`](struct.RTSPSession.html)
pub trait RTSPSessionExt {
    /// Allow `self` to expire. This method must be called an equal
    /// amount of time as `RTSPSessionExt::prevent_expire`.
    fn allow_expire(&self);

    //fn filter<'a, P: Into<Option<&'a /*Unimplemented*/RTSPSessionFilterFunc>>, Q: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, func: P, user_data: Q) -> Vec<RTSPSessionMedia>;

    /// Get the string that can be placed in the Session header field.
    ///
    /// # Returns
    ///
    /// the Session header of `self`.
    /// `g_free` after usage.
    fn get_header(&self) -> Option<String>;

    /// Get the session media for `path`. `matched` will contain the number of matched
    /// characters of `path`.
    /// ## `path`
    /// the path for the media
    /// ## `matched`
    /// the amount of matched characters
    ///
    /// # Returns
    ///
    /// the configuration for `path` in `self`.
    fn get_media(&self, path: &str) -> (Option<RTSPSessionMedia>, i32);

    /// Get the sessionid of `self`.
    ///
    /// # Returns
    ///
    /// the sessionid of `self`.
    /// The value remains valid as long as `self` is alive.
    fn get_sessionid(&self) -> Option<String>;

    /// Get the timeout value of `self`.
    ///
    /// # Returns
    ///
    /// the timeout of `self` in seconds.
    fn get_timeout(&self) -> u32;

    //fn is_expired(&self, now: /*Ignored*/&mut glib::TimeVal) -> bool;

    /// Check if `self` timeout out.
    /// ## `now`
    /// the current monotonic time
    ///
    /// # Returns
    ///
    /// `true` if `self` timed out
    fn is_expired_usec(&self, now: i64) -> bool;

    /// Manage the media object `obj` in `self`. `path` will be used to retrieve this
    /// media from the session with `RTSPSessionExt::get_media`.
    ///
    /// Ownership is taken from `media`.
    /// ## `path`
    /// the path for the media
    /// ## `media`
    /// a `RTSPMedia`
    ///
    /// # Returns
    ///
    /// a new `RTSPSessionMedia` object.
    fn manage_media<P: IsA<RTSPMedia>>(&self, path: &str, media: &P) -> Option<RTSPSessionMedia>;

    //fn next_timeout(&self, now: /*Ignored*/&mut glib::TimeVal) -> i32;

    /// Get the amount of milliseconds till the session will expire.
    /// ## `now`
    /// the current monotonic time
    ///
    /// # Returns
    ///
    /// the amount of milliseconds since the session will time out.
    fn next_timeout_usec(&self, now: i64) -> i32;

    /// Prevent `self` from expiring.
    fn prevent_expire(&self);

    /// Release the managed `media` in `self`, freeing the memory allocated by it.
    /// ## `media`
    /// a `RTSPMedia`
    ///
    /// # Returns
    ///
    /// `true` if there are more media session left in `self`.
    fn release_media(&self, media: &RTSPSessionMedia) -> bool;

    /// Configure `self` for a timeout of `timeout` seconds. The session will be
    /// cleaned up when there is no activity for `timeout` seconds.
    /// ## `timeout`
    /// the new timeout
    fn set_timeout(&self, timeout: u32);

    /// Update the last_access time of the session to the current time.
    fn touch(&self);

    fn get_property_timeout_always_visible(&self) -> bool;

    fn set_property_timeout_always_visible(&self, timeout_always_visible: bool);

    fn connect_property_sessionid_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_timeout_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_timeout_always_visible_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<RTSPSession> + IsA<glib::object::Object>> RTSPSessionExt for O {
    fn allow_expire(&self) {
        unsafe {
            ffi::gst_rtsp_session_allow_expire(self.to_glib_none().0);
        }
    }

    //fn filter<'a, P: Into<Option<&'a /*Unimplemented*/RTSPSessionFilterFunc>>, Q: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, func: P, user_data: Q) -> Vec<RTSPSessionMedia> {
    //    unsafe { TODO: call ffi::gst_rtsp_session_filter() }
    //}

    fn get_header(&self) -> Option<String> {
        unsafe {
            from_glib_full(ffi::gst_rtsp_session_get_header(self.to_glib_none().0))
        }
    }

    fn get_media(&self, path: &str) -> (Option<RTSPSessionMedia>, i32) {
        unsafe {
            let mut matched = mem::uninitialized();
            let ret = from_glib_none(ffi::gst_rtsp_session_get_media(self.to_glib_none().0, path.to_glib_none().0, &mut matched));
            (ret, matched)
        }
    }

    fn get_sessionid(&self) -> Option<String> {
        unsafe {
            from_glib_none(ffi::gst_rtsp_session_get_sessionid(self.to_glib_none().0))
        }
    }

    fn get_timeout(&self) -> u32 {
        unsafe {
            ffi::gst_rtsp_session_get_timeout(self.to_glib_none().0)
        }
    }

    //fn is_expired(&self, now: /*Ignored*/&mut glib::TimeVal) -> bool {
    //    unsafe { TODO: call ffi::gst_rtsp_session_is_expired() }
    //}

    fn is_expired_usec(&self, now: i64) -> bool {
        unsafe {
            from_glib(ffi::gst_rtsp_session_is_expired_usec(self.to_glib_none().0, now))
        }
    }

    fn manage_media<P: IsA<RTSPMedia>>(&self, path: &str, media: &P) -> Option<RTSPSessionMedia> {
        unsafe {
            from_glib_none(ffi::gst_rtsp_session_manage_media(self.to_glib_none().0, path.to_glib_none().0, media.to_glib_full()))
        }
    }

    //fn next_timeout(&self, now: /*Ignored*/&mut glib::TimeVal) -> i32 {
    //    unsafe { TODO: call ffi::gst_rtsp_session_next_timeout() }
    //}

    fn next_timeout_usec(&self, now: i64) -> i32 {
        unsafe {
            ffi::gst_rtsp_session_next_timeout_usec(self.to_glib_none().0, now)
        }
    }

    fn prevent_expire(&self) {
        unsafe {
            ffi::gst_rtsp_session_prevent_expire(self.to_glib_none().0);
        }
    }

    fn release_media(&self, media: &RTSPSessionMedia) -> bool {
        unsafe {
            from_glib(ffi::gst_rtsp_session_release_media(self.to_glib_none().0, media.to_glib_none().0))
        }
    }

    fn set_timeout(&self, timeout: u32) {
        unsafe {
            ffi::gst_rtsp_session_set_timeout(self.to_glib_none().0, timeout);
        }
    }

    fn touch(&self) {
        unsafe {
            ffi::gst_rtsp_session_touch(self.to_glib_none().0);
        }
    }

    fn get_property_timeout_always_visible(&self) -> bool {
        unsafe {
            let mut value = Value::from_type(<bool as StaticType>::static_type());
            gobject_ffi::g_object_get_property(self.to_glib_none().0, "timeout-always-visible".to_glib_none().0, value.to_glib_none_mut().0);
            value.get().unwrap()
        }
    }

    fn set_property_timeout_always_visible(&self, timeout_always_visible: bool) {
        unsafe {
            gobject_ffi::g_object_set_property(self.to_glib_none().0, "timeout-always-visible".to_glib_none().0, Value::from(&timeout_always_visible).to_glib_none().0);
        }
    }

    fn connect_property_sessionid_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "notify::sessionid",
                transmute(notify_sessionid_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_property_timeout_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "notify::timeout",
                transmute(notify_timeout_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_property_timeout_always_visible_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "notify::timeout-always-visible",
                transmute(notify_timeout_always_visible_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }
}

unsafe extern "C" fn notify_sessionid_trampoline<P>(this: *mut ffi::GstRTSPSession, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<RTSPSession> {
    let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
    f(&RTSPSession::from_glib_borrow(this).downcast_unchecked())
}

unsafe extern "C" fn notify_timeout_trampoline<P>(this: *mut ffi::GstRTSPSession, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<RTSPSession> {
    let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
    f(&RTSPSession::from_glib_borrow(this).downcast_unchecked())
}

unsafe extern "C" fn notify_timeout_always_visible_trampoline<P>(this: *mut ffi::GstRTSPSession, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<RTSPSession> {
    let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
    f(&RTSPSession::from_glib_borrow(this).downcast_unchecked())
}