mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-29 23:11:01 +00:00
commit
a02fe56871
6 changed files with 61 additions and 170 deletions
16
Cargo.toml
16
Cargo.toml
|
@ -9,13 +9,11 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
glib = "0.10"
|
||||
gobject-sys = "0.10"
|
||||
gstreamer = { version = "0.16", features = ["v1_12"] }
|
||||
gstreamer-base = "0.16"
|
||||
gstreamer-audio = "0.16"
|
||||
gstreamer-video = { version = "0.16", features = ["v1_12"] }
|
||||
lazy_static = "1.1.0"
|
||||
byte-slice-cast = "0.3.0"
|
||||
gst = { package = "gstreamer", version = "0.16", features = ["v1_12"] }
|
||||
gst-base = { package = "gstreamer-base", version = "0.16" }
|
||||
gst-audio = { package = "gstreamer-audio", version = "0.16" }
|
||||
gst-video = { package = "gstreamer-video", version = "0.16", features = ["v1_12"] }
|
||||
byte-slice-cast = "1"
|
||||
once_cell = "1.0"
|
||||
|
||||
[build-dependencies]
|
||||
|
@ -23,8 +21,8 @@ gst-plugin-version-helper = "0.2"
|
|||
|
||||
[features]
|
||||
default = ["interlaced-fields", "reference-timestamps"]
|
||||
interlaced-fields = ["gstreamer/v1_16", "gstreamer-video/v1_16"]
|
||||
reference-timestamps = ["gstreamer/v1_14"]
|
||||
interlaced-fields = ["gst/v1_16", "gst-video/v1_16"]
|
||||
reference-timestamps = ["gst/v1_14"]
|
||||
|
||||
[lib]
|
||||
name = "gstndi"
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use glib;
|
||||
use glib::subclass;
|
||||
use gst;
|
||||
use gst::prelude::*;
|
||||
use gst::subclass::prelude::*;
|
||||
use gst::{gst_error, gst_log, gst_trace};
|
||||
|
||||
use once_cell::sync::OnceCell;
|
||||
|
||||
|
@ -27,7 +26,7 @@ impl ObjectSubclass for DeviceProvider {
|
|||
type Instance = subclass::simple::InstanceStruct<Self>;
|
||||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
||||
glib_object_subclass!();
|
||||
glib::glib_object_subclass!();
|
||||
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
|
@ -54,7 +53,7 @@ impl ObjectSubclass for DeviceProvider {
|
|||
}
|
||||
|
||||
impl ObjectImpl for DeviceProvider {
|
||||
glib_object_impl!();
|
||||
glib::glib_object_impl!();
|
||||
}
|
||||
|
||||
impl DeviceProviderImpl for DeviceProvider {
|
||||
|
@ -213,7 +212,7 @@ impl ObjectSubclass for Device {
|
|||
type Instance = subclass::simple::InstanceStruct<Self>;
|
||||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
||||
glib_object_subclass!();
|
||||
glib::glib_object_subclass!();
|
||||
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
|
@ -228,7 +227,7 @@ impl ObjectSubclass for Device {
|
|||
}
|
||||
|
||||
impl ObjectImpl for Device {
|
||||
glib_object_impl!();
|
||||
glib::glib_object_impl!();
|
||||
}
|
||||
|
||||
impl DeviceImpl for Device {
|
||||
|
|
140
src/lib.rs
140
src/lib.rs
|
@ -1,15 +1,4 @@
|
|||
#[macro_use]
|
||||
extern crate glib;
|
||||
use glib::prelude::*;
|
||||
#[macro_use]
|
||||
extern crate gstreamer as gst;
|
||||
extern crate gstreamer_audio as gst_audio;
|
||||
extern crate gstreamer_base as gst_base;
|
||||
extern crate gstreamer_video as gst_video;
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
extern crate byte_slice_cast;
|
||||
|
||||
mod device_provider;
|
||||
pub mod ndi;
|
||||
|
@ -25,17 +14,23 @@ use crate::receiver::*;
|
|||
use std::collections::HashMap;
|
||||
use std::time;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, glib::GEnum)]
|
||||
#[repr(u32)]
|
||||
#[genum(type_name = "GstNdiTimestampMode")]
|
||||
pub enum TimestampMode {
|
||||
#[genum(name = "Receive Time", nick = "receive-time")]
|
||||
ReceiveTime = 0,
|
||||
#[genum(name = "NDI Timecode", nick = "timecode")]
|
||||
Timecode = 1,
|
||||
#[genum(name = "NDI Timestamp", nick = "timestamp")]
|
||||
Timestamp = 2,
|
||||
}
|
||||
|
||||
fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
|
||||
if !ndi::initialize() {
|
||||
return Err(glib_bool_error!("Cannot initialize NDI"));
|
||||
return Err(glib::glib_bool_error!("Cannot initialize NDI"));
|
||||
}
|
||||
|
||||
ndivideosrc::register(plugin)?;
|
||||
|
@ -44,115 +39,22 @@ fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref DEFAULT_RECEIVER_NDI_NAME: String = {
|
||||
format!(
|
||||
"GStreamer NDI Source {}-{}",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
env!("COMMIT_ID")
|
||||
)
|
||||
};
|
||||
}
|
||||
static DEFAULT_RECEIVER_NDI_NAME: Lazy<String> = Lazy::new(|| {
|
||||
format!(
|
||||
"GStreamer NDI Source {}-{}",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
env!("COMMIT_ID")
|
||||
)
|
||||
});
|
||||
|
||||
#[cfg(feature = "reference-timestamps")]
|
||||
lazy_static! {
|
||||
static ref TIMECODE_CAPS: gst::Caps = gst::Caps::new_simple("timestamp/x-ndi-timecode", &[]);
|
||||
static ref TIMESTAMP_CAPS: gst::Caps = gst::Caps::new_simple("timestamp/x-ndi-timestamp", &[]);
|
||||
}
|
||||
static TIMECODE_CAPS: Lazy<gst::Caps> =
|
||||
Lazy::new(|| gst::Caps::new_simple("timestamp/x-ndi-timecode", &[]));
|
||||
#[cfg(feature = "reference-timestamps")]
|
||||
static TIMESTAMP_CAPS: Lazy<gst::Caps> =
|
||||
Lazy::new(|| gst::Caps::new_simple("timestamp/x-ndi-timestamp", &[]));
|
||||
|
||||
impl glib::translate::ToGlib for TimestampMode {
|
||||
type GlibType = i32;
|
||||
|
||||
fn to_glib(&self) -> i32 {
|
||||
*self as i32
|
||||
}
|
||||
}
|
||||
|
||||
impl glib::translate::FromGlib<i32> for TimestampMode {
|
||||
fn from_glib(value: i32) -> Self {
|
||||
match value {
|
||||
0 => TimestampMode::ReceiveTime,
|
||||
1 => TimestampMode::Timecode,
|
||||
2 => TimestampMode::Timestamp,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StaticType for TimestampMode {
|
||||
fn static_type() -> glib::Type {
|
||||
timestamp_mode_get_type()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> glib::value::FromValueOptional<'a> for TimestampMode {
|
||||
unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> {
|
||||
Some(glib::value::FromValue::from_value(value))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> glib::value::FromValue<'a> for TimestampMode {
|
||||
unsafe fn from_value(value: &glib::Value) -> Self {
|
||||
use glib::translate::ToGlibPtr;
|
||||
|
||||
glib::translate::from_glib(gobject_sys::g_value_get_enum(value.to_glib_none().0))
|
||||
}
|
||||
}
|
||||
|
||||
impl glib::value::SetValue for TimestampMode {
|
||||
unsafe fn set_value(value: &mut glib::Value, this: &Self) {
|
||||
use glib::translate::{ToGlib, ToGlibPtrMut};
|
||||
|
||||
gobject_sys::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib())
|
||||
}
|
||||
}
|
||||
|
||||
fn timestamp_mode_get_type() -> glib::Type {
|
||||
use std::sync::Once;
|
||||
static ONCE: Once = Once::new();
|
||||
static mut TYPE: glib::Type = glib::Type::Invalid;
|
||||
|
||||
ONCE.call_once(|| {
|
||||
use std::ffi;
|
||||
use std::ptr;
|
||||
|
||||
static mut VALUES: [gobject_sys::GEnumValue; 4] = [
|
||||
gobject_sys::GEnumValue {
|
||||
value: TimestampMode::ReceiveTime as i32,
|
||||
value_name: b"Receive Time\0" as *const _ as *const _,
|
||||
value_nick: b"receive-time\0" as *const _ as *const _,
|
||||
},
|
||||
gobject_sys::GEnumValue {
|
||||
value: TimestampMode::Timecode as i32,
|
||||
value_name: b"NDI Timecode\0" as *const _ as *const _,
|
||||
value_nick: b"timecode\0" as *const _ as *const _,
|
||||
},
|
||||
gobject_sys::GEnumValue {
|
||||
value: TimestampMode::Timestamp as i32,
|
||||
value_name: b"NDI Timestamp\0" as *const _ as *const _,
|
||||
value_nick: b"timestamp\0" as *const _ as *const _,
|
||||
},
|
||||
gobject_sys::GEnumValue {
|
||||
value: 0,
|
||||
value_name: ptr::null(),
|
||||
value_nick: ptr::null(),
|
||||
},
|
||||
];
|
||||
|
||||
let name = ffi::CString::new("GstNdiTimestampMode").unwrap();
|
||||
unsafe {
|
||||
let type_ = gobject_sys::g_enum_register_static(name.as_ptr(), VALUES.as_ptr());
|
||||
TYPE = glib::translate::from_glib(type_);
|
||||
}
|
||||
});
|
||||
|
||||
unsafe {
|
||||
assert_ne!(TYPE, glib::Type::Invalid);
|
||||
TYPE
|
||||
}
|
||||
}
|
||||
|
||||
gst_plugin_define!(
|
||||
gst::gst_plugin_define!(
|
||||
ndi,
|
||||
env!("CARGO_PKG_DESCRIPTION"),
|
||||
plugin_init,
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
use glib;
|
||||
use glib::subclass;
|
||||
use gst;
|
||||
use gst::prelude::*;
|
||||
use gst::subclass::prelude::*;
|
||||
use gst_audio;
|
||||
use gst_base;
|
||||
use gst::{gst_debug, gst_element_error, gst_error, gst_error_msg};
|
||||
use gst_base::prelude::*;
|
||||
use gst_base::subclass::base_src::CreateSuccess;
|
||||
use gst_base::subclass::prelude::*;
|
||||
|
@ -149,7 +146,7 @@ impl ObjectSubclass for NdiAudioSrc {
|
|||
type Instance = gst::subclass::ElementInstanceStruct<Self>;
|
||||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
||||
glib_object_subclass!();
|
||||
glib::glib_object_subclass!();
|
||||
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
|
@ -199,7 +196,7 @@ impl ObjectSubclass for NdiAudioSrc {
|
|||
}
|
||||
|
||||
impl ObjectImpl for NdiAudioSrc {
|
||||
glib_object_impl!();
|
||||
glib::glib_object_impl!();
|
||||
|
||||
fn constructed(&self, obj: &glib::Object) {
|
||||
self.parent_constructed(obj);
|
||||
|
@ -412,8 +409,8 @@ impl BaseSrcImpl for NdiAudioSrc {
|
|||
let receiver = connect_ndi(
|
||||
self.cat,
|
||||
element,
|
||||
settings.ndi_name.as_ref().map(String::as_str),
|
||||
settings.url_address.as_ref().map(String::as_str),
|
||||
settings.ndi_name.as_deref(),
|
||||
settings.url_address.as_deref(),
|
||||
&settings.receiver_ndi_name,
|
||||
settings.connect_timeout,
|
||||
settings.bandwidth,
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
use glib;
|
||||
use glib::subclass;
|
||||
use gst;
|
||||
use gst::prelude::*;
|
||||
use gst::subclass::prelude::*;
|
||||
use gst_base;
|
||||
use gst::{gst_debug, gst_element_error, gst_error, gst_error_msg};
|
||||
use gst_base::prelude::*;
|
||||
use gst_base::subclass::base_src::CreateSuccess;
|
||||
use gst_base::subclass::prelude::*;
|
||||
use gst_video;
|
||||
|
||||
use std::sync::Mutex;
|
||||
use std::{i32, u32};
|
||||
|
@ -150,7 +147,7 @@ impl ObjectSubclass for NdiVideoSrc {
|
|||
type Instance = gst::subclass::ElementInstanceStruct<Self>;
|
||||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
||||
glib_object_subclass!();
|
||||
glib::glib_object_subclass!();
|
||||
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
|
@ -234,7 +231,7 @@ impl ObjectSubclass for NdiVideoSrc {
|
|||
}
|
||||
|
||||
impl ObjectImpl for NdiVideoSrc {
|
||||
glib_object_impl!();
|
||||
glib::glib_object_impl!();
|
||||
|
||||
fn constructed(&self, obj: &glib::Object) {
|
||||
self.parent_constructed(obj);
|
||||
|
@ -447,8 +444,8 @@ impl BaseSrcImpl for NdiVideoSrc {
|
|||
let receiver = connect_ndi(
|
||||
self.cat,
|
||||
element,
|
||||
settings.ndi_name.as_ref().map(String::as_str),
|
||||
settings.url_address.as_ref().map(String::as_str),
|
||||
settings.ndi_name.as_deref(),
|
||||
settings.url_address.as_deref(),
|
||||
&settings.receiver_ndi_name,
|
||||
settings.connect_timeout,
|
||||
settings.bandwidth,
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
use glib;
|
||||
use glib::prelude::*;
|
||||
use gst;
|
||||
use gst::prelude::*;
|
||||
use gst_video;
|
||||
use gst::{gst_debug, gst_element_error, gst_error, gst_log, gst_warning};
|
||||
use gst_video::prelude::*;
|
||||
|
||||
use byte_slice_cast::AsMutSliceOf;
|
||||
|
@ -13,6 +11,8 @@ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
|||
use std::sync::{Arc, Condvar, Mutex, Weak};
|
||||
use std::thread;
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use super::*;
|
||||
|
||||
pub struct ReceiverInfo {
|
||||
|
@ -25,12 +25,10 @@ pub struct ReceiverInfo {
|
|||
observations: Observations,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref HASHMAP_RECEIVERS: Mutex<HashMap<usize, ReceiverInfo>> = {
|
||||
let m = HashMap::new();
|
||||
Mutex::new(m)
|
||||
};
|
||||
}
|
||||
static HASHMAP_RECEIVERS: Lazy<Mutex<HashMap<usize, ReceiverInfo>>> = Lazy::new(|| {
|
||||
let m = HashMap::new();
|
||||
Mutex::new(m)
|
||||
});
|
||||
|
||||
static ID_RECEIVER: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
|
@ -544,14 +542,14 @@ where
|
|||
// then that one has to match and the other one does not matter
|
||||
if (ndi_name.is_some()
|
||||
&& url_address.is_some()
|
||||
&& receiver.ndi_name.as_ref().map(String::as_str) == ndi_name
|
||||
&& receiver.url_address.as_ref().map(String::as_str) == url_address)
|
||||
&& receiver.ndi_name.as_deref() == ndi_name
|
||||
&& receiver.url_address.as_deref() == url_address)
|
||||
|| (ndi_name.is_some()
|
||||
&& url_address.is_none()
|
||||
&& receiver.ndi_name.as_ref().map(String::as_str) == ndi_name)
|
||||
&& receiver.ndi_name.as_deref() == ndi_name)
|
||||
|| (ndi_name.is_none()
|
||||
&& url_address.is_some()
|
||||
&& receiver.url_address.as_ref().map(String::as_str) == url_address)
|
||||
&& receiver.url_address.as_deref() == url_address)
|
||||
{
|
||||
if (receiver.video.is_some() || !T::IS_VIDEO)
|
||||
&& (receiver.audio.is_some() || T::IS_VIDEO)
|
||||
|
@ -950,7 +948,7 @@ impl Receiver<VideoReceiver> {
|
|||
|
||||
let info = self.create_video_info(element, &video_frame)?;
|
||||
|
||||
let buffer = self.create_video_buffer(element, pts, duration, &info, &video_frame)?;
|
||||
let buffer = self.create_video_buffer(element, pts, duration, &info, &video_frame);
|
||||
|
||||
gst_log!(self.0.cat, obj: element, "Produced buffer {:?}", buffer);
|
||||
|
||||
|
@ -1103,7 +1101,7 @@ impl Receiver<VideoReceiver> {
|
|||
duration: gst::ClockTime,
|
||||
info: &gst_video::VideoInfo,
|
||||
video_frame: &VideoFrame,
|
||||
) -> Result<gst::Buffer, gst::FlowError> {
|
||||
) -> gst::Buffer {
|
||||
let mut buffer = gst::Buffer::with_size(info.size()).unwrap();
|
||||
{
|
||||
let buffer = buffer.get_mut().unwrap();
|
||||
|
@ -1174,7 +1172,7 @@ impl Receiver<VideoReceiver> {
|
|||
info: &gst_video::VideoInfo,
|
||||
buffer: gst::Buffer,
|
||||
video_frame: &VideoFrame,
|
||||
) -> Result<gst::Buffer, gst::FlowError> {
|
||||
) -> gst::Buffer {
|
||||
let mut vframe = gst_video::VideoFrame::from_buffer_writable(buffer, info).unwrap();
|
||||
|
||||
match info.format() {
|
||||
|
@ -1289,7 +1287,7 @@ impl Receiver<VideoReceiver> {
|
|||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
Ok(vframe.into_buffer())
|
||||
vframe.into_buffer()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1378,7 +1376,7 @@ impl Receiver<AudioReceiver> {
|
|||
|
||||
let info = self.create_audio_info(element, &audio_frame)?;
|
||||
|
||||
let buffer = self.create_audio_buffer(element, pts, duration, &info, &audio_frame)?;
|
||||
let buffer = self.create_audio_buffer(element, pts, duration, &info, &audio_frame);
|
||||
|
||||
gst_log!(self.0.cat, obj: element, "Produced buffer {:?}", buffer);
|
||||
|
||||
|
@ -1434,7 +1432,7 @@ impl Receiver<AudioReceiver> {
|
|||
duration: gst::ClockTime,
|
||||
info: &gst_audio::AudioInfo,
|
||||
audio_frame: &AudioFrame,
|
||||
) -> Result<gst::Buffer, gst::FlowError> {
|
||||
) -> gst::Buffer {
|
||||
// We multiply by 2 because is the size in bytes of an i16 variable
|
||||
let buff_size = (audio_frame.no_samples() as u32 * info.bpf()) as usize;
|
||||
let mut buffer = gst::Buffer::with_size(buff_size).unwrap();
|
||||
|
@ -1471,6 +1469,6 @@ impl Receiver<AudioReceiver> {
|
|||
);
|
||||
}
|
||||
|
||||
Ok(buffer)
|
||||
buffer
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue