2018-11-18 14:10:58 +00:00
|
|
|
// Copyright (C) 2017-2018 Sebastian Dröge <sebastian@centricular.com>
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2019-03-19 07:58:20 +00:00
|
|
|
use glib_sys;
|
|
|
|
use gst_sys;
|
2018-11-18 14:10:58 +00:00
|
|
|
|
|
|
|
use glib;
|
|
|
|
use glib::prelude::*;
|
|
|
|
use glib::translate::*;
|
|
|
|
|
|
|
|
use glib::subclass::prelude::*;
|
|
|
|
|
|
|
|
use libc;
|
|
|
|
|
|
|
|
use URIHandler;
|
|
|
|
use URIType;
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
pub trait URIHandlerImpl: super::element::ElementImpl {
|
2018-11-18 14:10:58 +00:00
|
|
|
fn get_uri(&self, element: &URIHandler) -> Option<String>;
|
2019-05-25 17:10:36 +00:00
|
|
|
fn set_uri(&self, element: &URIHandler, uri: &str) -> Result<(), glib::Error>;
|
2018-12-03 19:24:17 +00:00
|
|
|
fn get_uri_type() -> URIType;
|
2018-11-18 14:10:58 +00:00
|
|
|
fn get_protocols() -> Vec<String>;
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe impl<T: URIHandlerImpl> IsImplementable<T> for URIHandler {
|
2018-12-18 23:15:23 +00:00
|
|
|
unsafe extern "C" fn interface_init(
|
2019-03-19 07:58:20 +00:00
|
|
|
iface: glib_sys::gpointer,
|
|
|
|
_iface_data: glib_sys::gpointer,
|
2018-12-18 23:15:23 +00:00
|
|
|
) {
|
2019-03-19 07:58:20 +00:00
|
|
|
let uri_handler_iface = &mut *(iface as *mut gst_sys::GstURIHandlerInterface);
|
2018-12-18 23:15:23 +00:00
|
|
|
|
|
|
|
// Store the protocols in the interface data for later use
|
|
|
|
let mut data = T::type_data();
|
|
|
|
let protocols = T::get_protocols();
|
|
|
|
let protocols: *mut *const libc::c_char = protocols.to_glib_full();
|
|
|
|
let data = data.as_mut();
|
|
|
|
if data.interface_data.is_null() {
|
|
|
|
data.interface_data = Box::into_raw(Box::new(Vec::new()));
|
|
|
|
}
|
2019-03-19 07:58:20 +00:00
|
|
|
(*(data.interface_data as *mut Vec<(glib_sys::GType, glib_sys::gpointer)>))
|
2018-12-18 23:15:23 +00:00
|
|
|
.push((URIHandler::static_type().to_glib(), protocols as *mut _));
|
|
|
|
|
|
|
|
uri_handler_iface.get_type = Some(uri_handler_get_type::<T>);
|
|
|
|
uri_handler_iface.get_protocols = Some(uri_handler_get_protocols::<T>);
|
|
|
|
uri_handler_iface.get_uri = Some(uri_handler_get_uri::<T>);
|
|
|
|
uri_handler_iface.set_uri = Some(uri_handler_set_uri::<T>);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn uri_handler_get_type<T: URIHandlerImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
_type_: glib_sys::GType,
|
2020-07-25 08:02:04 +00:00
|
|
|
) -> gst_sys::GstURIType {
|
2018-12-03 19:24:17 +00:00
|
|
|
<T as URIHandlerImpl>::get_uri_type().to_glib()
|
2018-11-18 14:10:58 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn uri_handler_get_protocols<T: URIHandlerImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
_type_: glib_sys::GType,
|
2020-07-25 08:02:04 +00:00
|
|
|
) -> *const *const libc::c_char {
|
2018-11-18 14:10:58 +00:00
|
|
|
let data = <T as ObjectSubclass>::type_data();
|
|
|
|
data.as_ref()
|
|
|
|
.get_interface_data(URIHandler::static_type().to_glib()) as *const _
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn uri_handler_get_uri<T: URIHandlerImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
uri_handler: *mut gst_sys::GstURIHandler,
|
2020-07-25 08:02:04 +00:00
|
|
|
) -> *mut libc::c_char {
|
2018-11-18 14:10:58 +00:00
|
|
|
let instance = &*(uri_handler as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
|
|
|
|
|
|
|
imp.get_uri(&from_glib_borrow(uri_handler)).to_glib_full()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn uri_handler_set_uri<T: URIHandlerImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
uri_handler: *mut gst_sys::GstURIHandler,
|
2018-11-18 14:10:58 +00:00
|
|
|
uri: *const libc::c_char,
|
2019-03-19 07:58:20 +00:00
|
|
|
err: *mut *mut glib_sys::GError,
|
2020-07-25 08:02:04 +00:00
|
|
|
) -> glib_sys::gboolean {
|
2018-11-18 14:10:58 +00:00
|
|
|
let instance = &*(uri_handler as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
|
|
|
|
2019-05-25 17:10:36 +00:00
|
|
|
match imp.set_uri(
|
|
|
|
&from_glib_borrow(uri_handler),
|
|
|
|
glib::GString::from_glib_borrow(uri).as_str(),
|
|
|
|
) {
|
2018-11-18 14:10:58 +00:00
|
|
|
Ok(()) => true.to_glib(),
|
|
|
|
Err(error) => {
|
|
|
|
*err = error.to_glib_full() as *mut _;
|
|
|
|
false.to_glib()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|