2018-03-06 09:38:27 +00:00
|
|
|
// Copyright (C) 2018 Sebastian Dröge <sebastian@centricular.com>
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the
|
|
|
|
// Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
|
|
|
|
// Boston, MA 02110-1335, USA.
|
|
|
|
|
2019-12-02 09:30:07 +00:00
|
|
|
//! A collection of GStreamer plugins which leverage the `threadshare` [`runtime`].
|
|
|
|
//!
|
|
|
|
//! [`runtime`]: runtime/index.html
|
|
|
|
|
|
|
|
// Needed for `select!` in `Socket::next`
|
|
|
|
// see https://docs.rs/futures/0.3.1/futures/macro.select.html
|
|
|
|
#![recursion_limit = "1024"]
|
2018-03-06 09:38:27 +00:00
|
|
|
#![crate_type = "cdylib"]
|
|
|
|
|
2019-11-30 18:51:31 +00:00
|
|
|
pub use tokio;
|
2019-12-02 09:30:07 +00:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
pub mod runtime;
|
2018-03-19 14:47:56 +00:00
|
|
|
|
2019-12-02 09:30:07 +00:00
|
|
|
pub mod socket;
|
2018-07-06 07:32:24 +00:00
|
|
|
mod tcpclientsrc;
|
2019-12-23 15:23:38 +00:00
|
|
|
mod udpsink;
|
2018-03-06 09:38:27 +00:00
|
|
|
mod udpsrc;
|
|
|
|
|
2018-04-03 16:14:00 +00:00
|
|
|
mod appsrc;
|
2019-12-02 09:30:07 +00:00
|
|
|
pub mod dataqueue;
|
2019-08-05 13:19:06 +00:00
|
|
|
mod jitterbuffer;
|
2018-03-27 17:06:25 +00:00
|
|
|
mod proxy;
|
2018-04-03 16:14:00 +00:00
|
|
|
mod queue;
|
2018-03-19 14:47:56 +00:00
|
|
|
|
2019-12-21 09:45:43 +00:00
|
|
|
use glib::translate::*;
|
2019-11-24 20:12:40 +00:00
|
|
|
use glib_sys as glib_ffi;
|
|
|
|
|
|
|
|
use gst;
|
|
|
|
use gst::gst_plugin_define;
|
2019-12-23 15:23:38 +00:00
|
|
|
use gst::prelude::*;
|
2019-11-24 20:12:40 +00:00
|
|
|
use gstreamer_sys as gst_ffi;
|
2019-08-05 13:19:06 +00:00
|
|
|
|
2018-11-05 11:43:11 +00:00
|
|
|
fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
|
|
|
|
udpsrc::register(plugin)?;
|
2019-12-23 15:23:38 +00:00
|
|
|
udpsink::register(plugin)?;
|
2018-11-05 11:43:11 +00:00
|
|
|
tcpclientsrc::register(plugin)?;
|
|
|
|
queue::register(plugin)?;
|
|
|
|
proxy::register(plugin)?;
|
|
|
|
appsrc::register(plugin)?;
|
2019-12-21 09:45:43 +00:00
|
|
|
jitterbuffer::jitterbuffer::register(plugin)?;
|
2018-11-05 11:43:11 +00:00
|
|
|
|
|
|
|
Ok(())
|
2018-03-06 09:38:27 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:03:04 +00:00
|
|
|
gst_plugin_define!(
|
2019-05-27 20:21:22 +00:00
|
|
|
threadshare,
|
2019-06-03 10:53:58 +00:00
|
|
|
env!("CARGO_PKG_DESCRIPTION"),
|
2018-03-06 09:38:27 +00:00
|
|
|
plugin_init,
|
2019-06-03 10:53:58 +00:00
|
|
|
concat!(env!("CARGO_PKG_VERSION"), "-", env!("COMMIT_ID")),
|
2018-12-06 11:03:04 +00:00
|
|
|
"LGPL",
|
2019-06-03 10:53:58 +00:00
|
|
|
env!("CARGO_PKG_NAME"),
|
|
|
|
env!("CARGO_PKG_NAME"),
|
|
|
|
env!("CARGO_PKG_REPOSITORY"),
|
|
|
|
env!("BUILD_REL_DATE")
|
2018-03-06 09:38:27 +00:00
|
|
|
);
|
2018-04-05 10:36:58 +00:00
|
|
|
|
|
|
|
pub fn set_element_flags<T: glib::IsA<gst::Object> + glib::IsA<gst::Element>>(
|
|
|
|
element: &T,
|
|
|
|
flags: gst::ElementFlags,
|
|
|
|
) {
|
|
|
|
unsafe {
|
2019-01-16 15:30:26 +00:00
|
|
|
let ptr: *mut gst_ffi::GstObject = element.as_ptr() as *mut _;
|
2018-04-05 10:36:58 +00:00
|
|
|
let _guard = MutexGuard::lock(&(*ptr).lock);
|
|
|
|
(*ptr).flags |= flags.to_glib();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct MutexGuard<'a>(&'a glib_ffi::GMutex);
|
|
|
|
|
|
|
|
impl<'a> MutexGuard<'a> {
|
|
|
|
pub fn lock(mutex: &'a glib_ffi::GMutex) -> Self {
|
|
|
|
unsafe {
|
|
|
|
glib_ffi::g_mutex_lock(mut_override(mutex));
|
|
|
|
}
|
|
|
|
MutexGuard(mutex)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Drop for MutexGuard<'a> {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe {
|
|
|
|
glib_ffi::g_mutex_unlock(mut_override(self.0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-23 15:23:38 +00:00
|
|
|
|
|
|
|
pub fn get_current_running_time(element: &gst::Element) -> gst::ClockTime {
|
|
|
|
if let Some(clock) = element.get_clock() {
|
|
|
|
if clock.get_time() > element.get_base_time() {
|
|
|
|
clock.get_time() - element.get_base_time()
|
|
|
|
} else {
|
|
|
|
0.into()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gst::CLOCK_TIME_NONE
|
|
|
|
}
|
|
|
|
}
|