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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
// 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 Error;
use RTSPAuth;
use RTSPClient;
use RTSPMountPoints;
use RTSPSessionPool;
use RTSPThreadPool;
use ffi;
use gio;
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 std::boxed::Box as Box_;
use std::mem;
use std::mem::transmute;
use std::ptr;

glib_wrapper! {
    /// This object listens on a port, creates and manages the clients connected to
    /// it.
    ///
    /// # Implements
    ///
    /// [`RTSPServerExt`](trait.RTSPServerExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html)
    pub struct RTSPServer(Object<ffi::GstRTSPServer, ffi::GstRTSPServerClass>);

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

impl RTSPServer {
    /// Create a new `RTSPServer` instance.
    ///
    /// # Returns
    ///
    /// a new `RTSPServer`
    pub fn new() -> RTSPServer {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gst_rtsp_server_new())
        }
    }

    /// A default `GSocketSourceFunc` that creates a new `RTSPClient` to accept and handle a
    /// new connection on `socket` or `server`.
    /// ## `socket`
    /// a `gio::Socket`
    /// ## `condition`
    /// the condition on `source`
    /// ## `server`
    /// a `RTSPServer`
    ///
    /// # Returns
    ///
    /// TRUE if the source could be connected, FALSE if an error occurred.
    pub fn io_func<P: IsA<RTSPServer>>(socket: &gio::Socket, condition: glib::IOCondition, server: &P) -> bool {
        skip_assert_initialized!();
        unsafe {
            from_glib(ffi::gst_rtsp_server_io_func(socket.to_glib_none().0, condition.to_glib(), server.to_glib_none().0))
        }
    }
}

impl Default for RTSPServer {
    fn default() -> Self {
        Self::new()
    }
}

unsafe impl Send for RTSPServer {}
unsafe impl Sync for RTSPServer {}

/// Trait containing all `RTSPServer` methods.
///
/// # Implementors
///
/// [`RTSPServer`](struct.RTSPServer.html)
pub trait RTSPServerExt {
    //fn client_filter<'a, P: Into<Option<&'a /*Unimplemented*/RTSPServerClientFilterFunc>>, Q: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, func: P, user_data: Q) -> Vec<RTSPClient>;

    /// Create a `gio::Socket` for `self`. The socket will listen on the
    /// configured service.
    /// ## `cancellable`
    /// a `gio::Cancellable`
    ///
    /// # Returns
    ///
    /// the `gio::Socket` for `self` or `None` when an error
    /// occurred.
    fn create_socket<'a, P: Into<Option<&'a gio::Cancellable>>>(&self, cancellable: P) -> Result<gio::Socket, Error>;

    /// Create a `glib::Source` for `self`. The new source will have a default
    /// `GSocketSourceFunc` of `RTSPServer::io_func`.
    ///
    /// `cancellable` if not `None` can be used to cancel the source, which will cause
    /// the source to trigger, reporting the current condition (which is likely 0
    /// unless cancellation happened at the same time as a condition change). You can
    /// check for this in the callback using `gio::CancellableExt::is_cancelled`.
    ///
    /// This takes a reference on `self` until `source` is destroyed.
    /// ## `cancellable`
    /// a `gio::Cancellable` or `None`.
    ///
    /// # Returns
    ///
    /// the `glib::Source` for `self` or `None` when an error
    /// occurred. Free with g_source_unref ()
    fn create_source<'a, P: Into<Option<&'a gio::Cancellable>>>(&self, cancellable: P) -> Result<glib::Source, Error>;

    /// Get the address on which the server will accept connections.
    ///
    /// # Returns
    ///
    /// the server address. `g_free` after usage.
    fn get_address(&self) -> Option<String>;

    /// Get the `RTSPAuth` used as the authentication manager of `self`.
    ///
    /// # Returns
    ///
    /// the `RTSPAuth` of `self`. `gobject::ObjectExt::unref` after
    /// usage.
    fn get_auth(&self) -> Option<RTSPAuth>;

    /// The maximum amount of queued requests for the server.
    ///
    /// # Returns
    ///
    /// the server backlog.
    fn get_backlog(&self) -> i32;

    /// Get the port number where the server was bound to.
    ///
    /// # Returns
    ///
    /// the port number
    fn get_bound_port(&self) -> i32;

    /// Get the `RTSPMountPoints` used as the mount points of `self`.
    ///
    /// # Returns
    ///
    /// the `RTSPMountPoints` of `self`. `gobject::ObjectExt::unref` after
    /// usage.
    fn get_mount_points(&self) -> Option<RTSPMountPoints>;

    /// Get the service on which the server will accept connections.
    ///
    /// # Returns
    ///
    /// the service. use `g_free` after usage.
    fn get_service(&self) -> Option<String>;

    /// Get the `RTSPSessionPool` used as the session pool of `self`.
    ///
    /// # Returns
    ///
    /// the `RTSPSessionPool` used for sessions. `gobject::ObjectExt::unref` after
    /// usage.
    fn get_session_pool(&self) -> Option<RTSPSessionPool>;

    /// Get the `RTSPThreadPool` used as the thread pool of `self`.
    ///
    /// # Returns
    ///
    /// the `RTSPThreadPool` of `self`. `gobject::ObjectExt::unref` after
    /// usage.
    fn get_thread_pool(&self) -> Option<RTSPThreadPool>;

    /// Configure `self` to accept connections on the given address.
    ///
    /// This function must be called before the server is bound.
    /// ## `address`
    /// the address
    fn set_address(&self, address: &str);

    /// configure `auth` to be used as the authentication manager of `self`.
    /// ## `auth`
    /// a `RTSPAuth`
    fn set_auth<'a, P: Into<Option<&'a RTSPAuth>>>(&self, auth: P);

    /// configure the maximum amount of requests that may be queued for the
    /// server.
    ///
    /// This function must be called before the server is bound.
    /// ## `backlog`
    /// the backlog
    fn set_backlog(&self, backlog: i32);

    /// configure `mounts` to be used as the mount points of `self`.
    /// ## `mounts`
    /// a `RTSPMountPoints`
    fn set_mount_points<'a, P: Into<Option<&'a RTSPMountPoints>>>(&self, mounts: P);

    /// Configure `self` to accept connections on the given service.
    /// `service` should be a string containing the service name (see services(5)) or
    /// a string containing a port number between 1 and 65535.
    ///
    /// When `service` is set to "0", the server will listen on a random free
    /// port. The actual used port can be retrieved with
    /// `RTSPServerExt::get_bound_port`.
    ///
    /// This function must be called before the server is bound.
    /// ## `service`
    /// the service
    fn set_service(&self, service: &str);

    /// configure `pool` to be used as the session pool of `self`.
    /// ## `pool`
    /// a `RTSPSessionPool`
    fn set_session_pool<'a, P: Into<Option<&'a RTSPSessionPool>>>(&self, pool: P);

    /// configure `pool` to be used as the thread pool of `self`.
    /// ## `pool`
    /// a `RTSPThreadPool`
    fn set_thread_pool<'a, P: Into<Option<&'a RTSPThreadPool>>>(&self, pool: P);

    /// Take an existing network socket and use it for an RTSP connection. This
    /// is used when transferring a socket from an HTTP server which should be used
    /// as an RTSP over HTTP tunnel. The `initial_buffer` contains any remaining data
    /// that the HTTP server read from the socket while parsing the HTTP header.
    /// ## `socket`
    /// a network socket
    /// ## `ip`
    /// the IP address of the remote client
    /// ## `port`
    /// the port used by the other end
    /// ## `initial_buffer`
    /// any initial data that was already read from the socket
    ///
    /// # Returns
    ///
    /// TRUE if all was ok, FALSE if an error occurred.
    fn transfer_connection<'a, P: Into<Option<&'a str>>>(&self, socket: &gio::Socket, ip: &str, port: i32, initial_buffer: P) -> bool;

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

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

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

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

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

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

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

impl<O: IsA<RTSPServer> + IsA<glib::object::Object>> RTSPServerExt for O {
    //fn client_filter<'a, P: Into<Option<&'a /*Unimplemented*/RTSPServerClientFilterFunc>>, Q: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, func: P, user_data: Q) -> Vec<RTSPClient> {
    //    unsafe { TODO: call ffi::gst_rtsp_server_client_filter() }
    //}

    fn create_socket<'a, P: Into<Option<&'a gio::Cancellable>>>(&self, cancellable: P) -> Result<gio::Socket, Error> {
        let cancellable = cancellable.into();
        let cancellable = cancellable.to_glib_none();
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::gst_rtsp_server_create_socket(self.to_glib_none().0, cancellable.0, &mut error);
            if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
        }
    }

    fn create_source<'a, P: Into<Option<&'a gio::Cancellable>>>(&self, cancellable: P) -> Result<glib::Source, Error> {
        let cancellable = cancellable.into();
        let cancellable = cancellable.to_glib_none();
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::gst_rtsp_server_create_source(self.to_glib_none().0, cancellable.0, &mut error);
            if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
        }
    }

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

    fn get_auth(&self) -> Option<RTSPAuth> {
        unsafe {
            from_glib_full(ffi::gst_rtsp_server_get_auth(self.to_glib_none().0))
        }
    }

    fn get_backlog(&self) -> i32 {
        unsafe {
            ffi::gst_rtsp_server_get_backlog(self.to_glib_none().0)
        }
    }

    fn get_bound_port(&self) -> i32 {
        unsafe {
            ffi::gst_rtsp_server_get_bound_port(self.to_glib_none().0)
        }
    }

    fn get_mount_points(&self) -> Option<RTSPMountPoints> {
        unsafe {
            from_glib_full(ffi::gst_rtsp_server_get_mount_points(self.to_glib_none().0))
        }
    }

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

    fn get_session_pool(&self) -> Option<RTSPSessionPool> {
        unsafe {
            from_glib_full(ffi::gst_rtsp_server_get_session_pool(self.to_glib_none().0))
        }
    }

    fn get_thread_pool(&self) -> Option<RTSPThreadPool> {
        unsafe {
            from_glib_full(ffi::gst_rtsp_server_get_thread_pool(self.to_glib_none().0))
        }
    }

    fn set_address(&self, address: &str) {
        unsafe {
            ffi::gst_rtsp_server_set_address(self.to_glib_none().0, address.to_glib_none().0);
        }
    }

    fn set_auth<'a, P: Into<Option<&'a RTSPAuth>>>(&self, auth: P) {
        let auth = auth.into();
        let auth = auth.to_glib_none();
        unsafe {
            ffi::gst_rtsp_server_set_auth(self.to_glib_none().0, auth.0);
        }
    }

    fn set_backlog(&self, backlog: i32) {
        unsafe {
            ffi::gst_rtsp_server_set_backlog(self.to_glib_none().0, backlog);
        }
    }

    fn set_mount_points<'a, P: Into<Option<&'a RTSPMountPoints>>>(&self, mounts: P) {
        let mounts = mounts.into();
        let mounts = mounts.to_glib_none();
        unsafe {
            ffi::gst_rtsp_server_set_mount_points(self.to_glib_none().0, mounts.0);
        }
    }

    fn set_service(&self, service: &str) {
        unsafe {
            ffi::gst_rtsp_server_set_service(self.to_glib_none().0, service.to_glib_none().0);
        }
    }

    fn set_session_pool<'a, P: Into<Option<&'a RTSPSessionPool>>>(&self, pool: P) {
        let pool = pool.into();
        let pool = pool.to_glib_none();
        unsafe {
            ffi::gst_rtsp_server_set_session_pool(self.to_glib_none().0, pool.0);
        }
    }

    fn set_thread_pool<'a, P: Into<Option<&'a RTSPThreadPool>>>(&self, pool: P) {
        let pool = pool.into();
        let pool = pool.to_glib_none();
        unsafe {
            ffi::gst_rtsp_server_set_thread_pool(self.to_glib_none().0, pool.0);
        }
    }

    fn transfer_connection<'a, P: Into<Option<&'a str>>>(&self, socket: &gio::Socket, ip: &str, port: i32, initial_buffer: P) -> bool {
        let initial_buffer = initial_buffer.into();
        let initial_buffer = initial_buffer.to_glib_none();
        unsafe {
            from_glib(ffi::gst_rtsp_server_transfer_connection(self.to_glib_none().0, socket.to_glib_full(), ip.to_glib_none().0, port, initial_buffer.0))
        }
    }

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

    fn connect_property_address_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::address",
                transmute(notify_address_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_property_backlog_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::backlog",
                transmute(notify_backlog_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_property_bound_port_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::bound-port",
                transmute(notify_bound_port_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_property_mount_points_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::mount-points",
                transmute(notify_mount_points_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_property_service_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::service",
                transmute(notify_service_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_property_session_pool_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::session-pool",
                transmute(notify_session_pool_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }
}

unsafe extern "C" fn client_connected_trampoline<P>(this: *mut ffi::GstRTSPServer, object: *mut ffi::GstRTSPClient, f: glib_ffi::gpointer)
where P: IsA<RTSPServer> {
    let f: &&(Fn(&P, &RTSPClient) + Send + Sync + 'static) = transmute(f);
    f(&RTSPServer::from_glib_borrow(this).downcast_unchecked(), &from_glib_borrow(object))
}

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

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

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

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

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

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