use gst::glib;
use gst::prelude::*;
use gst::subclass::prelude::ObjectSubclassIsExt;
pub mod imp;
glib::wrapper! {
pub struct ZenohSrc(ObjectSubclass<imp::ZenohSrc>) @extends gst_base::PushSrc, gst_base::BaseSrc, gst::Element, gst::Object, @implements gst::URIHandler;
}
unsafe impl Send for ZenohSrc {}
unsafe impl Sync for ZenohSrc {}
impl Default for ZenohSrc {
fn default() -> Self {
gst::Object::builder().build().unwrap()
}
}
impl ZenohSrc {
pub fn new(key_expr: &str) -> Self {
gst::Object::builder()
.property("key-expr", key_expr)
.build()
.unwrap()
}
pub fn builder(key_expr: &str) -> ZenohSrcBuilder {
ZenohSrcBuilder::new(key_expr)
}
pub fn set_key_expr(&self, key_expr: &str) {
self.set_property("key-expr", key_expr);
}
pub fn set_config(&self, config_path: &str) {
self.set_property("config", config_path);
}
pub fn set_priority(&self, priority: u32) {
self.set_property("priority", priority);
}
pub fn set_congestion_control(&self, mode: &str) {
self.set_property("congestion-control", mode);
}
pub fn set_reliability(&self, mode: &str) {
self.set_property("reliability", mode);
}
pub fn set_receive_timeout_ms(&self, timeout: u64) {
self.set_property("receive-timeout-ms", timeout);
}
pub fn set_apply_buffer_meta(&self, apply: bool) {
self.set_property("apply-buffer-meta", apply);
}
pub fn set_session(&self, session: zenoh::Session) {
self.imp().set_external_session(session);
}
pub fn set_session_group(&self, group: &str) {
self.set_property("session-group", group);
}
pub fn key_expr(&self) -> String {
self.property("key-expr")
}
pub fn config(&self) -> Option<String> {
self.property("config")
}
pub fn priority(&self) -> u32 {
self.property("priority")
}
pub fn congestion_control(&self) -> String {
self.property("congestion-control")
}
pub fn reliability(&self) -> String {
self.property("reliability")
}
pub fn receive_timeout_ms(&self) -> u64 {
self.property("receive-timeout-ms")
}
pub fn apply_buffer_meta(&self) -> bool {
self.property("apply-buffer-meta")
}
pub fn session_group(&self) -> Option<String> {
self.property("session-group")
}
pub fn bytes_received(&self) -> u64 {
self.property("bytes-received")
}
pub fn messages_received(&self) -> u64 {
self.property("messages-received")
}
pub fn errors(&self) -> u64 {
self.property("errors")
}
}
impl TryFrom<gst::Element> for ZenohSrc {
type Error = gst::Element;
fn try_from(element: gst::Element) -> Result<Self, Self::Error> {
element.downcast()
}
}
pub struct ZenohSrcBuilder {
key_expr: String,
config: Option<String>,
priority: Option<u32>,
congestion_control: Option<String>,
reliability: Option<String>,
receive_timeout_ms: Option<u64>,
apply_buffer_meta: Option<bool>,
session: Option<zenoh::Session>,
session_group: Option<String>,
}
impl ZenohSrcBuilder {
pub fn new(key_expr: &str) -> Self {
Self {
key_expr: key_expr.to_string(),
config: None,
priority: None,
congestion_control: None,
reliability: None,
receive_timeout_ms: None,
apply_buffer_meta: None,
session: None,
session_group: None,
}
}
pub fn config(mut self, path: &str) -> Self {
self.config = Some(path.to_string());
self
}
pub fn priority(mut self, priority: u32) -> Self {
self.priority = Some(priority);
self
}
pub fn congestion_control(mut self, mode: &str) -> Self {
self.congestion_control = Some(mode.to_string());
self
}
pub fn reliability(mut self, mode: &str) -> Self {
self.reliability = Some(mode.to_string());
self
}
pub fn receive_timeout_ms(mut self, timeout: u64) -> Self {
self.receive_timeout_ms = Some(timeout);
self
}
pub fn apply_buffer_meta(mut self, apply: bool) -> Self {
self.apply_buffer_meta = Some(apply);
self
}
pub fn session(mut self, session: zenoh::Session) -> Self {
self.session = Some(session);
self
}
pub fn session_group(mut self, group: &str) -> Self {
self.session_group = Some(group.to_string());
self
}
pub fn build(self) -> ZenohSrc {
let mut builder = gst::Object::builder::<ZenohSrc>().property("key-expr", &self.key_expr);
if let Some(config) = self.config {
builder = builder.property("config", config);
}
if let Some(priority) = self.priority {
builder = builder.property("priority", priority);
}
if let Some(cc) = self.congestion_control {
builder = builder.property("congestion-control", cc);
}
if let Some(rel) = self.reliability {
builder = builder.property("reliability", rel);
}
if let Some(timeout) = self.receive_timeout_ms {
builder = builder.property("receive-timeout-ms", timeout);
}
if let Some(apply) = self.apply_buffer_meta {
builder = builder.property("apply-buffer-meta", apply);
}
if let Some(ref sg) = self.session_group {
builder = builder.property("session-group", sg);
}
let src: ZenohSrc = builder.build().unwrap();
if let Some(session) = self.session {
src.set_session(session);
}
src
}
}
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
gst::Element::register(
Some(plugin),
"zenohsrc",
gst::Rank::NONE + 100, ZenohSrc::static_type(),
)
}