use std::sync::Arc;
use nv_core::error::MediaError;
use crate::ingress::{HealthSink, IngressOptions, MediaIngress, MediaIngressFactory};
use crate::source::MediaSource;
pub struct GstMediaIngressFactory {
health_sink: Option<Arc<dyn HealthSink>>,
}
pub type DefaultMediaFactory = GstMediaIngressFactory;
impl GstMediaIngressFactory {
#[must_use]
pub fn new() -> Self {
Self { health_sink: None }
}
#[must_use]
pub fn with_health_sink(health_sink: Arc<dyn HealthSink>) -> Self {
Self {
health_sink: Some(health_sink),
}
}
}
impl Default for GstMediaIngressFactory {
fn default() -> Self {
Self::new()
}
}
impl MediaIngressFactory for GstMediaIngressFactory {
fn create(&self, options: IngressOptions) -> Result<Box<dyn MediaIngress>, MediaError> {
let mut source = MediaSource::new(
options.feed_id,
options.spec,
options.reconnect,
options.decode_preference,
);
if let Some(ref hs) = self.health_sink {
source.set_health_sink(Arc::clone(hs));
}
if let Some(ptz) = options.ptz_provider {
source.set_ptz_provider(ptz);
}
if let Some(hook) = options.post_decode_hook {
source.set_post_decode_hook(hook);
}
source.event_queue_capacity = options.event_queue_capacity;
source.device_residency = options.device_residency;
Ok(Box::new(source))
}
}