discoverer.rs 4.58 KB
Newer Older
1 2
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
3 4 5 6 7 8 9
// DO NOT EDIT

use DiscovererInfo;
use Error;
use ffi;
use glib;
use glib::signal::SignalHandlerId;
10
use glib::signal::connect_raw;
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
use glib::translate::*;
use glib_ffi;
use gst;
use gst_ffi;
use std::boxed::Box as Box_;
use std::mem::transmute;
use std::ptr;

glib_wrapper! {
    pub struct Discoverer(Object<ffi::GstDiscoverer, ffi::GstDiscovererClass>);

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

impl Discoverer {
    pub fn new(timeout: gst::ClockTime) -> Result<Discoverer, Error> {
        assert_initialized_main_thread!();
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::gst_discoverer_new(timeout.to_glib(), &mut error);
            if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
        }
    }

    pub fn discover_uri(&self, uri: &str) -> Result<DiscovererInfo, Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::gst_discoverer_discover_uri(self.to_glib_none().0, uri.to_glib_none().0, &mut error);
            if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
        }
    }

    pub fn discover_uri_async(&self, uri: &str) -> Result<(), glib::error::BoolError> {
        unsafe {
François Laignel's avatar
François Laignel committed
47
            glib_result_from_gboolean!(ffi::gst_discoverer_discover_uri_async(self.to_glib_none().0, uri.to_glib_none().0), "Failed to add URI to list of discovers")
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
        }
    }

    pub fn start(&self) {
        unsafe {
            ffi::gst_discoverer_start(self.to_glib_none().0);
        }
    }

    pub fn stop(&self) {
        unsafe {
            ffi::gst_discoverer_stop(self.to_glib_none().0);
        }
    }

    pub fn connect_discovered<F: Fn(&Discoverer, &DiscovererInfo, &Option<Error>) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Discoverer, &DiscovererInfo, &Option<Error>) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
66
            connect_raw(self.to_glib_none().0, b"discovered\0".as_ptr() as *const _,
67 68 69 70 71 72 73
                transmute(discovered_trampoline as usize), Box_::into_raw(f) as *mut _)
        }
    }

    pub fn connect_finished<F: Fn(&Discoverer) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Discoverer) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
74
            connect_raw(self.to_glib_none().0, b"finished\0".as_ptr() as *const _,
75 76 77 78 79 80 81
                transmute(finished_trampoline as usize), Box_::into_raw(f) as *mut _)
        }
    }

    pub fn connect_source_setup<F: Fn(&Discoverer, &gst::Element) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Discoverer, &gst::Element) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
82
            connect_raw(self.to_glib_none().0, b"source-setup\0".as_ptr() as *const _,
83 84 85 86 87 88 89
                transmute(source_setup_trampoline as usize), Box_::into_raw(f) as *mut _)
        }
    }

    pub fn connect_starting<F: Fn(&Discoverer) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Discoverer) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
90
            connect_raw(self.to_glib_none().0, b"starting\0".as_ptr() as *const _,
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
                transmute(starting_trampoline as usize), Box_::into_raw(f) as *mut _)
        }
    }
}

unsafe impl Send for Discoverer {}
unsafe impl Sync for Discoverer {}

unsafe extern "C" fn discovered_trampoline(this: *mut ffi::GstDiscoverer, info: *mut ffi::GstDiscovererInfo, error: *mut glib_ffi::GError, f: glib_ffi::gpointer) {
    let f: &&(Fn(&Discoverer, &DiscovererInfo, &Option<Error>) + Send + Sync + 'static) = transmute(f);
    f(&from_glib_borrow(this), &from_glib_borrow(info), &from_glib_borrow(error))
}

unsafe extern "C" fn finished_trampoline(this: *mut ffi::GstDiscoverer, f: glib_ffi::gpointer) {
    let f: &&(Fn(&Discoverer) + Send + Sync + 'static) = transmute(f);
    f(&from_glib_borrow(this))
}

unsafe extern "C" fn source_setup_trampoline(this: *mut ffi::GstDiscoverer, source: *mut gst_ffi::GstElement, f: glib_ffi::gpointer) {
    let f: &&(Fn(&Discoverer, &gst::Element) + Send + Sync + 'static) = transmute(f);
    f(&from_glib_borrow(this), &from_glib_borrow(source))
}

unsafe extern "C" fn starting_trampoline(this: *mut ffi::GstDiscoverer, f: glib_ffi::gpointer) {
    let f: &&(Fn(&Discoverer) + Send + Sync + 'static) = transmute(f);
    f(&from_glib_borrow(this))
}