From fc6eb2f16d955eacad32f87586a740355dd54733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ant=C3=B4nio=20Cardoso?= Date: Wed, 19 Apr 2023 22:48:07 -0300 Subject: [PATCH] src: stream: rtsp_server: Use VideoEncodeType for encoding instead of str --- src/stream/rtsp/rtsp_server.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/stream/rtsp/rtsp_server.rs b/src/stream/rtsp/rtsp_server.rs index b2f347a4..dc1d4569 100644 --- a/src/stream/rtsp/rtsp_server.rs +++ b/src/stream/rtsp/rtsp_server.rs @@ -8,6 +8,7 @@ use gst_rtsp_server::{prelude::*, RTSPTransportMode}; use tracing::*; use crate::stream::rtsp::rtsp_media_factory; +use crate::video::types::VideoEncodeType; #[allow(dead_code)] pub struct RTSPServer { @@ -107,9 +108,9 @@ impl RTSPServer { } #[instrument(level = "debug")] - fn create_rtsp_bin(proxysink: &gst::Element, encode: &str) -> Result { + fn create_rtsp_bin(proxysink: &gst::Element, encode: &VideoEncodeType) -> Result { let description = match encode { - "H264" => { + VideoEncodeType::H264 => { concat!( "proxysrc name=ProxySrc message-forward=true", " ! queue leaky=downstream flush-on-eos=true max-size-buffers=0", @@ -117,7 +118,7 @@ impl RTSPServer { " ! rtph264pay name=pay0 aggregate-mode=zero-latency config-interval=10 pt=96", ) } - "RAW" => { + VideoEncodeType::Yuyv => { concat!( "proxysrc name=ProxySrc", " ! queue leaky=downstream flush-on-eos=true max-size-buffers=0", @@ -125,7 +126,7 @@ impl RTSPServer { " ! rtpvrawpay name=pay0 pt=96", ) } - "JPEG" => { + VideoEncodeType::Mjpg => { concat!( "proxysrc name=ProxySrc", " ! queue leaky=downstream flush-on-eos=true max-size-buffers=0", @@ -155,11 +156,15 @@ impl RTSPServer { } #[instrument(level = "debug")] - pub fn add_pipeline(path: &str, proxysink: &gst::Element, encode: &str) -> Result<()> { + pub fn add_pipeline( + path: &str, + proxysink: &gst::Element, + encoding: &VideoEncodeType, + ) -> Result<()> { // Initialize the singleton before calling gst factory let mut rtsp_server = RTSP_SERVER.as_ref().lock().unwrap(); - let rtsp_bin = Self::create_rtsp_bin(proxysink, encode)?; + let rtsp_bin = Self::create_rtsp_bin(proxysink, encoding)?; let factory = rtsp_media_factory::Factory::new(rtsp_bin); factory.set_shared(true);