diff options
34 files changed, 203 insertions, 245 deletions
diff --git a/generic/file/Cargo.toml b/generic/file/Cargo.toml index 9493baf6c..60431ecc5 100644 --- a/generic/file/Cargo.toml +++ b/generic/file/Cargo.toml @@ -5,13 +5,14 @@ authors = ["Sebastian Dröge <sebastian@centricular.com>"] repository = "https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs" license = "MIT/Apache-2.0" description = "Rust File Plugin" +edition = "2018" [dependencies] url = "2" glib = { git = "https://github.com/gtk-rs/gtk-rs" } -gstreamer = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } -gstreamer-base = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } -lazy_static = "1.0" +gst = { package = "gstreamer", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } +gst-base = { package = "gstreamer-base", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } +once_cell = "1.0" [lib] name = "gstrsfile" diff --git a/generic/file/src/file_location.rs b/generic/file/src/file_location.rs index eca8e579f..22d4c4071 100644 --- a/generic/file/src/file_location.rs +++ b/generic/file/src/file_location.rs @@ -1,5 +1,3 @@ -use glib; -use gst; use url::Url; use std::convert::AsRef; diff --git a/generic/file/src/filesink/imp.rs b/generic/file/src/filesink/imp.rs index 4a53f5288..2521de95c 100644 --- a/generic/file/src/filesink/imp.rs +++ b/generic/file/src/filesink/imp.rs @@ -8,13 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use glib; use glib::subclass; use glib::subclass::prelude::*; -use gst; use gst::prelude::*; use gst::subclass::prelude::*; -use gst_base; +use gst::{gst_debug, gst_element_error, gst_error, gst_error_msg, gst_info, gst_trace}; use gst_base::subclass::prelude::*; use std::fs::File; @@ -66,13 +64,14 @@ pub struct FileSink { state: Mutex<State>, } -lazy_static! { - static ref CAT: gst::DebugCategory = gst::DebugCategory::new( +use once_cell::sync::Lazy; +static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "rsfilesink", gst::DebugColorFlags::empty(), Some("File Sink"), - ); -} + ) +}); impl FileSink { fn set_location( @@ -124,7 +123,7 @@ impl ObjectSubclass for FileSink { type Instance = gst::subclass::ElementInstanceStruct<Self>; type Class = subclass::simple::ClassStruct<Self>; - glib_object_subclass!(); + glib::glib_object_subclass!(); fn new() -> Self { Self { diff --git a/generic/file/src/filesink/mod.rs b/generic/file/src/filesink/mod.rs index 8ad677156..ac80bd849 100644 --- a/generic/file/src/filesink/mod.rs +++ b/generic/file/src/filesink/mod.rs @@ -12,7 +12,7 @@ use glib::prelude::*; mod imp; -glib_wrapper! { +glib::glib_wrapper! { pub struct FileSink(ObjectSubclass<imp::FileSink>) @extends gst_base::BaseSink, gst::Element, gst::Object, @implements gst::URIHandler; } diff --git a/generic/file/src/filesrc/imp.rs b/generic/file/src/filesrc/imp.rs index cc7969aa1..0eb0aa2e6 100644 --- a/generic/file/src/filesrc/imp.rs +++ b/generic/file/src/filesrc/imp.rs @@ -7,13 +7,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use glib; use glib::subclass; use glib::subclass::prelude::*; -use gst; use gst::prelude::*; use gst::subclass::prelude::*; -use gst_base; +use gst::{gst_debug, gst_element_error, gst_error, gst_error_msg, gst_info}; use gst_base::prelude::*; use gst_base::subclass::prelude::*; @@ -66,13 +64,14 @@ pub struct FileSrc { state: Mutex<State>, } -lazy_static! { - static ref CAT: gst::DebugCategory = gst::DebugCategory::new( +use once_cell::sync::Lazy; +static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "rsfilesrc", gst::DebugColorFlags::empty(), Some("File Source"), - ); -} + ) +}); impl FileSrc { fn set_location( @@ -138,7 +137,7 @@ impl ObjectSubclass for FileSrc { type Instance = gst::subclass::ElementInstanceStruct<Self>; type Class = subclass::simple::ClassStruct<Self>; - glib_object_subclass!(); + glib::glib_object_subclass!(); fn new() -> Self { Self { diff --git a/generic/file/src/filesrc/mod.rs b/generic/file/src/filesrc/mod.rs index 70ed45de7..5fc15a28f 100644 --- a/generic/file/src/filesrc/mod.rs +++ b/generic/file/src/filesrc/mod.rs @@ -11,7 +11,7 @@ use glib::prelude::*; mod imp; -glib_wrapper! { +glib::glib_wrapper! { pub struct FileSrc(ObjectSubclass<imp::FileSrc>) @extends gst_base::BaseSrc, gst::Element, gst::Object, @implements gst::URIHandler; } diff --git a/generic/file/src/lib.rs b/generic/file/src/lib.rs index 2acde3b9d..a3f3e20b2 100644 --- a/generic/file/src/lib.rs +++ b/generic/file/src/lib.rs @@ -6,15 +6,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[macro_use] -extern crate glib; -#[macro_use] -extern crate gstreamer as gst; -extern crate gstreamer_base as gst_base; -extern crate url; -#[macro_use] -extern crate lazy_static; - mod file_location; mod filesink; mod filesrc; @@ -25,7 +16,7 @@ fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { Ok(()) } -gst_plugin_define!( +gst::gst_plugin_define!( rsfile, env!("CARGO_PKG_DESCRIPTION"), plugin_init, diff --git a/generic/sodium/Cargo.toml b/generic/sodium/Cargo.toml index bb8119011..c1d2216b7 100644 --- a/generic/sodium/Cargo.toml +++ b/generic/sodium/Cargo.toml @@ -12,7 +12,7 @@ glib = { git = "https://github.com/gtk-rs/gtk-rs" } gst = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["v1_14"], package="gstreamer" } gst-base = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["v1_14"], package = "gstreamer-base" } sodiumoxide = "0.2.1" -lazy_static = "1.3.0" +once_cell = "1.3.0" hex = "0.4" smallvec = "1.0" diff --git a/generic/sodium/src/decrypter/imp.rs b/generic/sodium/src/decrypter/imp.rs index 779c92deb..f058ddfde 100644 --- a/generic/sodium/src/decrypter/imp.rs +++ b/generic/sodium/src/decrypter/imp.rs @@ -27,19 +27,19 @@ use glib::subclass; use glib::subclass::prelude::*; use gst::prelude::*; use gst::subclass::prelude::*; +use gst::{gst_debug, gst_element_error, gst_error, gst_error_msg, gst_log, gst_loggable_error}; use sodiumoxide::crypto::box_; use std::sync::Mutex; -lazy_static! { - static ref CAT: gst::DebugCategory = { - gst::DebugCategory::new( - "sodiumdecrypter", - gst::DebugColorFlags::empty(), - Some("Decrypter Element"), - ) - }; -} +use once_cell::sync::Lazy; +static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( + "sodiumdecrypter", + gst::DebugColorFlags::empty(), + Some("Decrypter Element"), + ) +}); static PROPERTIES: [subclass::Property; 2] = [ subclass::Property("receiver-key", |name| { @@ -565,7 +565,7 @@ impl ObjectSubclass for Decrypter { type Instance = gst::subclass::ElementInstanceStruct<Self>; type Class = subclass::simple::ClassStruct<Self>; - glib_object_subclass!(); + glib::glib_object_subclass!(); fn with_class(klass: &Self::Class) -> Self { let templ = klass.get_pad_template("sink").unwrap(); diff --git a/generic/sodium/src/decrypter/mod.rs b/generic/sodium/src/decrypter/mod.rs index 4bee6635c..1bf5dbe1e 100644 --- a/generic/sodium/src/decrypter/mod.rs +++ b/generic/sodium/src/decrypter/mod.rs @@ -26,7 +26,7 @@ use glib::prelude::*; mod imp; -glib_wrapper! { +glib::glib_wrapper! { pub struct Decrypter(ObjectSubclass<imp::Decrypter>) @extends gst::Element, gst::Object; } diff --git a/generic/sodium/src/encrypter/imp.rs b/generic/sodium/src/encrypter/imp.rs index d23fc15da..cc30a453d 100644 --- a/generic/sodium/src/encrypter/imp.rs +++ b/generic/sodium/src/encrypter/imp.rs @@ -27,6 +27,7 @@ use glib::subclass; use glib::subclass::prelude::*; use gst::prelude::*; use gst::subclass::prelude::*; +use gst::{gst_debug, gst_element_error, gst_error, gst_error_msg, gst_log}; use smallvec::SmallVec; use sodiumoxide::crypto::box_; @@ -34,15 +35,14 @@ type BufferVec = SmallVec<[gst::Buffer; 16]>; use std::sync::Mutex; -lazy_static! { - static ref CAT: gst::DebugCategory = { - gst::DebugCategory::new( - "sodiumencrypter", - gst::DebugColorFlags::empty(), - Some("Encrypter Element"), - ) - }; -} +use once_cell::sync::Lazy; +static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( + "sodiumencrypter", + gst::DebugColorFlags::empty(), + Some("Encrypter Element"), + ) +}); static PROPERTIES: [subclass::Property; 3] = [ subclass::Property("receiver-key", |name| { @@ -395,7 +395,7 @@ impl ObjectSubclass for Encrypter { type Instance = gst::subclass::ElementInstanceStruct<Self>; type Class = subclass::simple::ClassStruct<Self>; - glib_object_subclass!(); + glib::glib_object_subclass!(); fn with_class(klass: &Self::Class) -> Self { let templ = klass.get_pad_template("sink").unwrap(); diff --git a/generic/sodium/src/encrypter/mod.rs b/generic/sodium/src/encrypter/mod.rs index b71dd3f91..f9eb39ffe 100644 --- a/generic/sodium/src/encrypter/mod.rs +++ b/generic/sodium/src/encrypter/mod.rs @@ -26,7 +26,7 @@ use glib::prelude::*; mod imp; -glib_wrapper! { +glib::glib_wrapper! { pub struct Encrypter(ObjectSubclass<imp::Encrypter>) @extends gst::Element, gst::Object; } diff --git a/generic/sodium/src/lib.rs b/generic/sodium/src/lib.rs index 5e5470f89..bdccccd64 100644 --- a/generic/sodium/src/lib.rs +++ b/generic/sodium/src/lib.rs @@ -20,13 +20,6 @@ // // SPDX-License-Identifier: MIT -#[macro_use] -extern crate glib; -#[macro_use] -extern crate gst; -#[macro_use] -extern crate lazy_static; - const TYPEFIND_HEADER: &[u8; 12] = b"gst-sodium10"; // `core::slice::<impl [T]>::len` is not yet stable as a const fn // const TYPEFIND_HEADER_SIZE: usize = TYPEFIND_HEADER.len(); @@ -68,7 +61,7 @@ fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { Ok(()) } -gst_plugin_define!( +gst::gst_plugin_define!( sodium, env!("CARGO_PKG_DESCRIPTION"), plugin_init, diff --git a/generic/sodium/tests/decrypter.rs b/generic/sodium/tests/decrypter.rs index d9a34e4a1..cab580dd2 100644 --- a/generic/sodium/tests/decrypter.rs +++ b/generic/sodium/tests/decrypter.rs @@ -22,13 +22,6 @@ // // SPDX-License-Identifier: MIT -#[macro_use] -extern crate lazy_static; -#[macro_use] -extern crate pretty_assertions; - -extern crate gstsodium; - use glib::prelude::*; use gst::prelude::*; @@ -36,22 +29,23 @@ use std::sync::{Arc, Mutex}; use std::path::PathBuf; -lazy_static! { - static ref SENDER_PUBLIC: glib::Bytes = { - let public = [ - 66, 248, 199, 74, 216, 55, 228, 116, 52, 17, 147, 56, 65, 130, 134, 148, 157, 153, 235, - 171, 179, 147, 120, 71, 100, 243, 133, 120, 160, 14, 111, 65, - ]; - glib::Bytes::from_owned(public) - }; - static ref RECEIVER_PRIVATE: glib::Bytes = { - let secret = [ - 54, 221, 217, 54, 94, 235, 167, 2, 187, 249, 71, 31, 59, 27, 19, 166, 78, 236, 102, 48, - 29, 142, 41, 189, 22, 146, 218, 69, 147, 165, 240, 235, - ]; - glib::Bytes::from_owned(secret) - }; -} +use pretty_assertions::assert_eq; + +use once_cell::sync::Lazy; +static SENDER_PUBLIC: Lazy<glib::Bytes> = Lazy::new(|| { + let public = [ + 66, 248, 199, 74, 216, 55, 228, 116, 52, 17, 147, 56, 65, 130, 134, 148, 157, 153, 235, + 171, 179, 147, 120, 71, 100, 243, 133, 120, 160, 14, 111, 65, + ]; + glib::Bytes::from_owned(public) +}); +static RECEIVER_PRIVATE: Lazy<glib::Bytes> = Lazy::new(|| { + let secret = [ + 54, 221, 217, 54, 94, 235, 167, 2, 187, 249, 71, 31, 59, 27, 19, 166, 78, 236, 102, 48, 29, + 142, 41, 189, 22, 146, 218, 69, 147, 165, 240, 235, + ]; + glib::Bytes::from_owned(secret) +}); fn init() { use std::sync::Once; diff --git a/generic/sodium/tests/encrypter.rs b/generic/sodium/tests/encrypter.rs index beb1414a2..cbb653925 100644 --- a/generic/sodium/tests/encrypter.rs +++ b/generic/sodium/tests/encrypter.rs @@ -22,37 +22,35 @@ // // SPDX-License-Identifier: MIT -#[macro_use] -extern crate lazy_static; -extern crate gstsodium; - use glib::prelude::*; use gst::prelude::*; -lazy_static! { - static ref RECEIVER_PUBLIC: glib::Bytes = { - let public = [ - 28, 95, 33, 124, 28, 103, 80, 78, 7, 28, 234, 40, 226, 179, 253, 166, 169, 64, 78, 5, - 57, 92, 151, 179, 221, 89, 68, 70, 44, 225, 219, 19, - ]; - - glib::Bytes::from_owned(public) - }; - static ref SENDER_PRIVATE: glib::Bytes = { - let secret = [ - 154, 227, 90, 239, 206, 184, 202, 234, 176, 161, 14, 91, 218, 98, 142, 13, 145, 223, - 210, 222, 224, 240, 98, 51, 142, 165, 255, 1, 159, 100, 242, 162, - ]; - glib::Bytes::from_owned(secret) - }; - static ref NONCE: glib::Bytes = { - let nonce = [ - 144, 187, 179, 230, 15, 4, 241, 15, 37, 133, 22, 30, 50, 106, 70, 159, 243, 218, 173, - 22, 18, 36, 4, 45, - ]; - glib::Bytes::from_owned(nonce) - }; -} +use once_cell::sync::Lazy; + +use pretty_assertions::assert_eq; + +static RECEIVER_PUBLIC: Lazy<glib::Bytes> = Lazy::new(|| { + let public = [ + 28, 95, 33, 124, 28, 103, 80, 78, 7, 28, 234, 40, 226, 179, 253, 166, 169, 64, 78, 5, 57, + 92, 151, 179, 221, 89, 68, 70, 44, 225, 219, 19, + ]; + + glib::Bytes::from_owned(public) +}); +static SENDER_PRIVATE: Lazy<glib::Bytes> = Lazy::new(|| { + let secret = [ + 154, 227, 90, 239, 206, 184, 202, 234, 176, 161, 14, 91, 218, 98, 142, 13, 145, 223, 210, + 222, 224, 240, 98, 51, 142, 165, 255, 1, 159, 100, 242, 162, + ]; + glib::Bytes::from_owned(secret) +}); +static NONCE: Lazy<glib::Bytes> = Lazy::new(|| { + let nonce = [ + 144, 187, 179, 230, 15, 4, 241, 15, 37, 133, 22, 30, 50, 106, 70, 159, 243, 218, 173, 22, + 18, 36, 4, 45, + ]; + glib::Bytes::from_owned(nonce) +}); fn init() { use std::sync::Once; diff --git a/generic/threadshare/Cargo.toml b/generic/threadshare/Cargo.toml index 531225689..14ebe5102 100644 --- a/generic/threadshare/Cargo.toml +++ b/generic/threadshare/Cargo.toml @@ -9,22 +9,15 @@ edition = "2018" [dependencies] libc = "0.2" -glib-sys = { git = "https://github.com/gtk-rs/gtk-rs" } -gobject-sys = { git = "https://github.com/gtk-rs/gtk-rs" } -gio-sys = { git = "https://github.com/gtk-rs/gtk-rs" } glib = { git = "https://github.com/gtk-rs/gtk-rs" } gio = { git = "https://github.com/gtk-rs/gtk-rs" } gst = { package = "gstreamer", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features=["v1_10"] } -gst-app = { package = "gstreamer-app", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } -gst-check = { package = "gstreamer-check", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gst-net = { package = "gstreamer-net", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gst-rtp = { package = "gstreamer-rtp", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } -gstreamer-sys = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } pin-project = "1" once_cell = "1" tokio = { git = "https://github.com/fengalin/tokio", tag = "tokio-0.2.13-throttling", features = ["io-util", "macros", "rt-core", "sync", "stream", "time", "tcp", "udp", "rt-util"] } futures = { version = "0.3", features = ["thread-pool"] } -lazy_static = "1.0" rand = "0.7" socket2 = "0.3" @@ -34,6 +27,10 @@ winapi = { version = "0.3", features = ["winsock2", "processthreadsapi"] } [target.'cfg(unix)'.dependencies] socket2 = { version = "0.3", features = ["reuseport"] } +[dev-dependencies] +gst-check = { package = "gstreamer-check", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } +gst-app = { package = "gstreamer-app", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } + [lib] name = "gstthreadshare" crate-type = ["cdylib", "rlib", "staticlib"] diff --git a/generic/threadshare/src/appsrc/imp.rs b/generic/threadshare/src/appsrc/imp.rs index 9ab686dae..73c9276f5 100644 --- a/generic/threadshare/src/appsrc/imp.rs +++ b/generic/threadshare/src/appsrc/imp.rs @@ -30,7 +30,7 @@ use gst::prelude::*; use gst::subclass::prelude::*; use gst::{gst_debug, gst_element_error, gst_error, gst_error_msg, gst_log, gst_trace}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::convert::TryInto; use std::sync::Arc; @@ -119,13 +119,13 @@ static PROPERTIES: [subclass::Property; 5] = [ }), ]; -lazy_static! { - static ref CAT: gst::DebugCategory = gst::DebugCategory::new( +static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "ts-appsrc", gst::DebugColorFlags::empty(), Some("Thread-sharing app source"), - ); -} + ) +}); #[derive(Debug)] enum StreamItem { diff --git a/generic/threadshare/src/dataqueue.rs b/generic/threadshare/src/dataqueue.rs index 9d206061a..4f4fc6a0a 100644 --- a/generic/threadshare/src/dataqueue.rs +++ b/generic/threadshare/src/dataqueue.rs @@ -20,20 +20,20 @@ use futures::future::{self, abortable, AbortHandle}; use gst::gst_debug; use gst::prelude::*; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::collections::VecDeque; use std::sync::Arc; use std::sync::Mutex as StdMutex; use std::{u32, u64}; -lazy_static! { - static ref DATA_QUEUE_CAT: gst::DebugCategory = gst::DebugCategory::new( +static DATA_QUEUE_CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "ts-dataqueue", gst::DebugColorFlags::empty(), Some("Thread-sharing queue"), - ); -} + ) +}); #[derive(Debug)] pub enum DataQueueItem { diff --git a/generic/threadshare/src/inputselector/imp.rs b/generic/threadshare/src/inputselector/imp.rs index b7c6c8c33..fe861b84e 100644 --- a/generic/threadshare/src/inputselector/imp.rs +++ b/generic/threadshare/src/inputselector/imp.rs @@ -28,7 +28,7 @@ use gst::prelude::*; use gst::subclass::prelude::*; use gst::{gst_debug, gst_log, gst_trace}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::collections::HashMap; use std::sync::{Arc, Mutex}; @@ -407,13 +407,13 @@ pub struct InputSelector { pads: Mutex<Pads>, } -lazy_static! { - static ref CAT: gst::DebugCategory = gst::DebugCategory::new( +static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "ts-input-selector", gst::DebugColorFlags::empty(), Some("Thread-sharing input selector"), - ); -} + ) +}); impl InputSelector { fn unprepare(&self, element: &super::InputSelector) -> Result<(), ()> { diff --git a/generic/threadshare/src/jitterbuffer/ffi.rs b/generic/threadshare/src/jitterbuffer/ffi.rs index 46424fa14..cc1eb41d2 100644 --- a/generic/threadshare/src/jitterbuffer/ffi.rs +++ b/generic/threadshare/src/jitterbuffer/ffi.rs @@ -15,11 +15,9 @@ // Free Software Foundation, Inc., 51 Franklin Street, Suite 500, // Boston, MA 02110-1335, USA. -use glib_ffi::{gboolean, gpointer, GList, GType}; -use glib_sys as glib_ffi; +use glib::ffi::{gboolean, gpointer, GList, GType}; -use gst_ffi::GstClockTime; -use gstreamer_sys as gst_ffi; +use gst::ffi::GstClockTime; use libc::{c_int, c_uint, c_ulonglong, c_ushort, c_void}; #[repr(C)] @@ -70,7 +68,7 @@ extern "C" { pub fn rtp_jitter_buffer_get_clock_rate(jbuf: *mut RTPJitterBuffer) -> c_uint; pub fn rtp_jitter_buffer_reset_skew(jbuf: *mut RTPJitterBuffer); - pub fn rtp_jitter_buffer_flush(jbuf: *mut RTPJitterBuffer, free_func: glib_ffi::GFunc); + pub fn rtp_jitter_buffer_flush(jbuf: *mut RTPJitterBuffer, free_func: glib::ffi::GFunc); pub fn rtp_jitter_buffer_find_earliest( jbuf: *mut RTPJitterBuffer, pts: *mut GstClockTime, diff --git a/generic/threadshare/src/jitterbuffer/imp.rs b/generic/threadshare/src/jitterbuffer/imp.rs index b92aa66fe..e9dbdd6ec 100644 --- a/generic/threadshare/src/jitterbuffer/imp.rs +++ b/generic/threadshare/src/jitterbuffer/imp.rs @@ -29,7 +29,7 @@ use gst::subclass::prelude::*; use gst::{gst_debug, gst_element_error, gst_error, gst_error_msg, gst_info, gst_log, gst_trace}; use gst_rtp::RTPBuffer; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::cmp::{max, min, Ordering}; use std::collections::{BTreeSet, VecDeque}; @@ -1347,13 +1347,13 @@ pub struct JitterBuffer { settings: StdMutex<Settings>, } -lazy_static! { - static ref CAT: gst::DebugCategory = gst::DebugCategory::new( +static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "ts-jitterbuffer", gst::DebugColorFlags::empty(), Some("Thread-sharing jitterbuffer"), - ); -} + ) +}); impl JitterBuffer { fn clear_pt_map(&self, element: &super::JitterBuffer) { diff --git a/generic/threadshare/src/jitterbuffer/jitterbuffer.rs b/generic/threadshare/src/jitterbuffer/jitterbuffer.rs index 5984db98f..d240e3e24 100644 --- a/generic/threadshare/src/jitterbuffer/jitterbuffer.rs +++ b/generic/threadshare/src/jitterbuffer/jitterbuffer.rs @@ -19,9 +19,6 @@ use super::ffi; use std::ptr; -use glib_sys as glib_ffi; -use gstreamer_sys as gst_ffi; - use glib::glib_wrapper; use glib::prelude::*; use glib::translate::*; @@ -81,7 +78,7 @@ impl RTPJitterBufferItem { rtptime: u32, ) -> RTPJitterBufferItem { unsafe { - let ptr = ptr::NonNull::new(glib_sys::g_slice_alloc0(mem::size_of::< + let ptr = ptr::NonNull::new(glib::ffi::g_slice_alloc0(mem::size_of::< ffi::RTPJitterBufferItem, >()) as *mut ffi::RTPJitterBufferItem) .expect("Allocation failed"); @@ -107,8 +104,8 @@ impl RTPJitterBufferItem { pub fn into_buffer(mut self) -> gst::Buffer { unsafe { let item = self.0.take().expect("Invalid wrapper"); - let buf = item.as_ref().data as *mut gst_ffi::GstBuffer; - glib_sys::g_slice_free1( + let buf = item.as_ref().data as *mut gst::ffi::GstBuffer; + glib::ffi::g_slice_free1( mem::size_of::<ffi::RTPJitterBufferItem>(), item.as_ptr() as *mut _, ); @@ -119,7 +116,7 @@ impl RTPJitterBufferItem { pub fn get_dts(&self) -> gst::ClockTime { unsafe { let item = self.0.as_ref().expect("Invalid wrapper"); - if item.as_ref().dts == gst_ffi::GST_CLOCK_TIME_NONE { + if item.as_ref().dts == gst::ffi::GST_CLOCK_TIME_NONE { gst::CLOCK_TIME_NONE } else { gst::ClockTime(Some(item.as_ref().dts)) @@ -130,7 +127,7 @@ impl RTPJitterBufferItem { pub fn get_pts(&self) -> gst::ClockTime { unsafe { let item = self.0.as_ref().expect("Invalid wrapper"); - if item.as_ref().pts == gst_ffi::GST_CLOCK_TIME_NONE { + if item.as_ref().pts == gst::ffi::GST_CLOCK_TIME_NONE { gst::CLOCK_TIME_NONE } else { gst::ClockTime(Some(item.as_ref().pts)) @@ -163,10 +160,10 @@ impl Drop for RTPJitterBufferItem { unsafe { if let Some(ref item) = self.0 { if !item.as_ref().data.is_null() { - gst_ffi::gst_mini_object_unref(item.as_ref().data as *mut _); + gst::ffi::gst_mini_object_unref(item.as_ref().data as *mut _); } - glib_sys::g_slice_free1( + glib::ffi::g_slice_free1( mem::size_of::<ffi::RTPJitterBufferItem>(), item.as_ptr() as *mut _, ); @@ -274,7 +271,7 @@ impl RTPJitterBuffer { is_rtx.to_glib(), ); - if pts == gst_ffi::GST_CLOCK_TIME_NONE { + if pts == gst::ffi::GST_CLOCK_TIME_NONE { gst::CLOCK_TIME_NONE } else { pts.into() @@ -319,7 +316,7 @@ impl RTPJitterBuffer { Some(seqnum as u16) }; - if pts == gst_ffi::GST_CLOCK_TIME_NONE { + if pts == gst::ffi::GST_CLOCK_TIME_NONE { (gst::CLOCK_TIME_NONE, seqnum) } else { (pts.into(), seqnum) @@ -361,7 +358,7 @@ impl RTPJitterBuffer { } pub fn flush(&self) { - unsafe extern "C" fn free_item(item: glib_ffi::gpointer, _: glib_ffi::gpointer) { + unsafe extern "C" fn free_item(item: glib::ffi::gpointer, _: glib::ffi::gpointer) { let _ = RTPJitterBufferItem(Some(ptr::NonNull::new(item as *mut _).expect("NULL item"))); } diff --git a/generic/threadshare/src/lib.rs b/generic/threadshare/src/lib.rs index 1264cbf56..438d36c2e 100644 --- a/generic/threadshare/src/lib.rs +++ b/generic/threadshare/src/lib.rs @@ -41,10 +41,8 @@ mod proxy; mod queue; use glib::translate::*; -use glib_sys as glib_ffi; use gst::gst_plugin_define; -use gstreamer_sys as gst_ffi; fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { udpsrc::register(plugin)?; @@ -76,19 +74,19 @@ pub fn set_element_flags<T: glib::IsA<gst::Object> + glib::IsA<gst::Element>>( flags: gst::ElementFlags, ) { unsafe { - let ptr: *mut gst_ffi::GstObject = element.as_ptr() as *mut _; + let ptr: *mut gst::ffi::GstObject = element.as_ptr() as *mut _; let _guard = MutexGuard::lock(&(*ptr).lock); (*ptr).flags |= flags.to_glib(); } } #[must_use = "if unused the Mutex will immediately unlock"] -struct MutexGuard<'a>(&'a glib_ffi::GMutex); +struct MutexGuard<'a>(&'a glib::ffi::GMutex); impl<'a> MutexGuard<'a> { - pub fn lock(mutex: &'a glib_ffi::GMutex) -> Self { + pub fn lock(mutex: &'a glib::ffi::GMutex) -> Self { unsafe { - glib_ffi::g_mutex_lock(mut_override(mutex)); + glib::ffi::g_mutex_lock(mut_override(mutex)); } MutexGuard(mutex) } @@ -97,7 +95,7 @@ impl<'a> MutexGuard<'a> { impl<'a> Drop for MutexGuard<'a> { fn drop(&mut self) { unsafe { - glib_ffi::g_mutex_unlock(mut_override(self.0)); + glib::ffi::g_mutex_unlock(mut_override(self.0)); } } } diff --git a/generic/threadshare/src/proxy/imp.rs b/generic/threadshare/src/proxy/imp.rs index d4b22aca9..84062b6c3 100644 --- a/generic/threadshare/src/proxy/imp.rs +++ b/generic/threadshare/src/proxy/imp.rs @@ -28,7 +28,7 @@ use gst::prelude::*; use gst::subclass::prelude::*; use gst::{gst_debug, gst_element_error, gst_error, gst_error_msg, gst_log, gst_trace}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::collections::{HashMap, VecDeque}; use std::sync::Mutex as StdMutex; @@ -43,14 +43,12 @@ use crate::runtime::{ use crate::dataqueue::{DataQueue, DataQueueItem}; -lazy_static! { - static ref PROXY_CONTEXTS: StdMutex<HashMap<String, Weak<StdMutex<ProxyContextInner>>>> = - StdMutex::new(HashMap::new()); - static ref PROXY_SRC_PADS: StdMutex<HashMap<String, PadSrcWeak>> = - StdMutex::new(HashMap::new()); - static ref PROXY_SINK_PADS: StdMutex<HashMap<String, PadSinkWeak>> = - StdMutex::new(HashMap::new()); -} +static PROXY_CONTEXTS: Lazy<StdMutex<HashMap<String, Weak<StdMutex<ProxyContextInner>>>>> = + Lazy::new(|| StdMutex::new(HashMap::new())); +static PROXY_SRC_PADS: Lazy<StdMutex<HashMap<String, PadSrcWeak>>> = + Lazy::new(|| StdMutex::new(HashMap::new())); +static PROXY_SINK_PADS: Lazy<StdMutex<HashMap<String, PadSinkWeak>>> = + Lazy::new(|| StdMutex::new(HashMap::new())); const DEFAULT_PROXY_CONTEXT: &str = ""; @@ -412,13 +410,13 @@ pub struct ProxySink { settings: StdMutex<SettingsSink>, } -lazy_static! { - static ref SINK_CAT: gst::DebugCategory = gst::DebugCategory::new( +static SINK_CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "ts-proxysink", gst::DebugColorFlags::empty(), Some("Thread-sharing proxy sink"), - ); -} + ) +}); impl ProxySink { async fn schedule_pending_queue(&self, element: &super::ProxySink) { @@ -1051,13 +1049,13 @@ pub struct ProxySrc { settings: StdMutex<SettingsSrc>, } -lazy_static! { - static ref SRC_CAT: gst::DebugCategory = gst::DebugCategory::new( +static SRC_CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "ts-proxysrc", gst::DebugColorFlags::empty(), Some("Thread-sharing proxy source"), - ); -} + ) +}); impl ProxySrc { fn prepare(&self, element: &super::ProxySrc) -> Result<(), gst::ErrorMessage> { diff --git a/generic/threadshare/src/queue/imp.rs b/generic/threadshare/src/queue/imp.rs index fb9ee8f22..9d53b7a59 100644 --- a/generic/threadshare/src/queue/imp.rs +++ b/generic/threadshare/src/queue/imp.rs @@ -28,7 +28,7 @@ use gst::prelude::*; use gst::subclass::prelude::*; use gst::{gst_debug, gst_element_error, gst_error, gst_error_msg, gst_log, gst_trace}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::collections::VecDeque; use std::sync::Mutex as StdMutex; @@ -513,13 +513,13 @@ pub struct Queue { settings: StdMutex<Settings>, } -lazy_static! { - static ref CAT: gst::DebugCategory = gst::DebugCategory::new( +static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "ts-queue", gst::DebugColorFlags::empty(), Some("Thread-sharing queue"), - ); -} + ) +}); impl Queue { /* Try transfering all the items from the pending queue to the DataQueue, then diff --git a/generic/threadshare/src/runtime/executor.rs b/generic/threadshare/src/runtime/executor.rs index b8c2e01f6..fe3552904 100644 --- a/generic/threadshare/src/runtime/executor.rs +++ b/generic/threadshare/src/runtime/executor.rs @@ -40,7 +40,7 @@ use futures::prelude::*; use gst::{gst_debug, gst_log, gst_trace, gst_warning}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::cell::RefCell; use std::collections::{HashMap, VecDeque}; @@ -66,9 +66,8 @@ use super::RUNTIME_CAT; // // Also, we want to be able to `acquire` a `Context` outside of an `async` context. // These `Mutex`es must be `lock`ed for a short period. -lazy_static! { - static ref CONTEXTS: Mutex<HashMap<String, Weak<ContextInner>>> = Mutex::new(HashMap::new()); -} +static CONTEXTS: Lazy<Mutex<HashMap<String, Weak<ContextInner>>>> = + Lazy::new(|| Mutex::new(HashMap::new())); thread_local!(static CURRENT_THREAD_CONTEXT: RefCell<Option<ContextWeak>> = RefCell::new(None)); diff --git a/generic/threadshare/src/runtime/mod.rs b/generic/threadshare/src/runtime/mod.rs index 80f01d8d2..d22fe802c 100644 --- a/generic/threadshare/src/runtime/mod.rs +++ b/generic/threadshare/src/runtime/mod.rs @@ -59,12 +59,12 @@ pub mod prelude { pub mod time; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; -lazy_static! { - static ref RUNTIME_CAT: gst::DebugCategory = gst::DebugCategory::new( +static RUNTIME_CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "ts-runtime", gst::DebugColorFlags::empty(), Some("Thread-sharing Runtime"), - ); -} + ) +}); diff --git a/generic/threadshare/src/socket.rs b/generic/threadshare/src/socket.rs index dca8dc982..a2ada2999 100644 --- a/generic/threadshare/src/socket.rs +++ b/generic/threadshare/src/socket.rs @@ -21,13 +21,11 @@ use futures::future::BoxFuture; use gst::prelude::*; use gst::{gst_debug, gst_error, gst_error_msg, gst_log}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::io; use gio::prelude::*; -use gio_sys as gio_ffi; -use gobject_sys as gobject_ffi; use std::error; use std::fmt; @@ -38,13 +36,13 @@ use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; #[cfg(windows)] use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocket}; -lazy_static! { - static ref SOCKET_CAT: gst::DebugCategory = gst::DebugCategory::new( +static SOCKET_CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "ts-socket", gst::DebugColorFlags::empty(), Some("Thread-sharing Socket"), - ); -} + ) +}); pub trait SocketRead: Send + Unpin { const DO_TIMESTAMP: bool; @@ -193,7 +191,7 @@ impl<T: SocketRead> Drop for Socket<T> { // fd is safe though, as is receiving/sending from two different threads #[derive(Debug)] pub struct GioSocketWrapper { - socket: *mut gio_ffi::GSocket, + socket: *mut gio::ffi::GSocket, } unsafe impl Send for GioSocketWrapper {} @@ -240,14 +238,14 @@ impl GioSocketWrapper { #[cfg(unix)] pub fn get<T: FromRawFd>(&self) -> T { - unsafe { FromRawFd::from_raw_fd(libc::dup(gio_ffi::g_socket_get_fd(self.socket))) } + unsafe { FromRawFd::from_raw_fd(libc::dup(gio::ffi::g_socket_get_fd(self.socket))) } } #[cfg(windows)] pub fn get<T: FromRawSocket>(&self) -> T { unsafe { FromRawSocket::from_raw_socket( - dup_socket(gio_ffi::g_socket_get_fd(self.socket) as _) as _ + dup_socket(gio::ffi::g_socket_get_fd(self.socket) as _) as _ ) } } @@ -256,7 +254,7 @@ impl GioSocketWrapper { impl Clone for GioSocketWrapper { fn clone(&self) -> Self { Self { - socket: unsafe { gobject_ffi::g_object_ref(self.socket as *mut _) as *mut _ }, + socket: unsafe { glib::gobject_ffi::g_object_ref(self.socket as *mut _) as *mut _ }, } } } @@ -264,7 +262,7 @@ impl Clone for GioSocketWrapper { impl Drop for GioSocketWrapper { fn drop(&mut self) { unsafe { - gobject_ffi::g_object_unref(self.socket as *mut _); + glib::gobject_ffi::g_object_unref(self.socket as *mut _); } } } diff --git a/generic/threadshare/src/tcpclientsrc/imp.rs b/generic/threadshare/src/tcpclientsrc/imp.rs index 8a7136b3b..f3ef2fbfb 100644 --- a/generic/threadshare/src/tcpclientsrc/imp.rs +++ b/generic/threadshare/src/tcpclientsrc/imp.rs @@ -29,7 +29,7 @@ use gst::prelude::*; use gst::subclass::prelude::*; use gst::{gst_debug, gst_element_error, gst_error, gst_error_msg, gst_log, gst_trace}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::io; use std::net::{IpAddr, SocketAddr}; @@ -503,13 +503,13 @@ pub struct TcpClientSrc { settings: StdMutex<Settings>, } -lazy_static! { - static ref CAT: gst::DebugCategory = gst::DebugCategory::new( +static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "ts-tcpclientsrc", gst::DebugColorFlags::empty(), Some("Thread-sharing TCP Client source"), - ); -} + ) +}); impl TcpClientSrc { fn prepare(&self, element: &super::TcpClientSrc) -> Result<(), gst::ErrorMessage> { diff --git a/generic/threadshare/src/udpsink/imp.rs b/generic/threadshare/src/udpsink/imp.rs index 39c10a412..4472efeb2 100644 --- a/generic/threadshare/src/udpsink/imp.rs +++ b/generic/threadshare/src/udpsink/imp.rs @@ -33,7 +33,7 @@ use gst::{ gst_warning, }; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use crate::runtime::prelude::*; use crate::runtime::{self, Context, PadSink, PadSinkRef, Task}; @@ -112,13 +112,13 @@ impl Default for Settings { } } -lazy_static! { - static ref CAT: gst::DebugCategory = gst::DebugCategory::new( +static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "ts-udpsink", gst::DebugColorFlags::empty(), Some("Thread-sharing UDP sink"), - ); -} + ) +}); static PROPERTIES: [subclass::Property; 17] = [ subclass::Property("sync", |name| { diff --git a/generic/threadshare/src/udpsrc/imp.rs b/generic/threadshare/src/udpsrc/imp.rs index b536e2361..009ce43d6 100644 --- a/generic/threadshare/src/udpsrc/imp.rs +++ b/generic/threadshare/src/udpsrc/imp.rs @@ -29,7 +29,7 @@ use gst::subclass::prelude::*; use gst::{gst_debug, gst_element_error, gst_error, gst_error_msg, gst_log, gst_trace}; use gst_net::*; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::i32; use std::io; @@ -517,13 +517,13 @@ pub struct UdpSrc { settings: StdMutex<Settings>, } -lazy_static! { - static ref CAT: gst::DebugCategory = gst::DebugCategory::new( +static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "ts-udpsrc", gst::DebugColorFlags::empty(), Some("Thread-sharing UDP source"), - ); -} + ) +}); impl UdpSrc { fn prepare(&self, element: &super::UdpSrc) -> Result<(), gst::ErrorMessage> { diff --git a/generic/threadshare/tests/jitterbuffer.rs b/generic/threadshare/tests/jitterbuffer.rs index 58bb0a2c2..431dddf89 100644 --- a/generic/threadshare/tests/jitterbuffer.rs +++ b/generic/threadshare/tests/jitterbuffer.rs @@ -18,17 +18,17 @@ use gst::gst_debug; use gst::prelude::*; -use lazy_static::lazy_static; - use std::sync::mpsc; -lazy_static! { - static ref CAT: gst::DebugCategory = gst::DebugCategory::new( +use once_cell::sync::Lazy; + +static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "ts-test", gst::DebugColorFlags::empty(), Some("Thread-sharing test"), - ); -} + ) +}); fn init() { use std::sync::Once; diff --git a/generic/threadshare/tests/pad.rs b/generic/threadshare/tests/pad.rs index fa22175de..4fe33c555 100644 --- a/generic/threadshare/tests/pad.rs +++ b/generic/threadshare/tests/pad.rs @@ -29,7 +29,7 @@ use gst::subclass::prelude::*; use gst::EventView; use gst::{gst_debug, gst_error_msg, gst_info, gst_log}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::boxed::Box; use std::sync::atomic::{AtomicBool, Ordering}; @@ -86,13 +86,13 @@ mod imp_src { context: String, } - lazy_static! { - pub static ref SRC_CAT: gst::DebugCategory = gst::DebugCategory::new( + pub static SRC_CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "ts-element-src-test", gst::DebugColorFlags::empty(), Some("Thread-sharing Test Src Element"), - ); - } + ) + }); #[derive(Clone, Debug)] struct PadSrcTestHandler; @@ -623,13 +623,13 @@ mod imp_sink { } } - lazy_static! { - static ref SINK_CAT: gst::DebugCategory = gst::DebugCategory::new( + static SINK_CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "ts-element-sink-test", gst::DebugColorFlags::empty(), Some("Thread-sharing Test Sink Element"), - ); - } + ) + }); impl ObjectSubclass for ElementSinkTest { const NAME: &'static str = "TsElementSinkTest"; diff --git a/generic/threadshare/tests/pipeline.rs b/generic/threadshare/tests/pipeline.rs index 1e97b0869..3b85012d0 100644 --- a/generic/threadshare/tests/pipeline.rs +++ b/generic/threadshare/tests/pipeline.rs @@ -18,17 +18,17 @@ use gst::prelude::*; use gst::{gst_debug, gst_error}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::sync::mpsc; -lazy_static! { - static ref CAT: gst::DebugCategory = gst::DebugCategory::new( +static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| { + gst::DebugCategory::new( "ts-test", gst::DebugColorFlags::empty(), Some("Thread-sharing test"), - ); -} + ) +}); fn init() { use std::sync::Once; |