Skip to content

Commit

Permalink
src: stream: rtsp_server: Use VideoEncodeType for encoding instead of…
Browse files Browse the repository at this point in the history
… str
  • Loading branch information
joaoantoniocardoso committed Apr 20, 2023
1 parent 6b03aca commit fc6eb2f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/stream/rtsp/rtsp_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -107,25 +108,25 @@ impl RTSPServer {
}

#[instrument(level = "debug")]
fn create_rtsp_bin(proxysink: &gst::Element, encode: &str) -> Result<gst::Bin> {
fn create_rtsp_bin(proxysink: &gst::Element, encode: &VideoEncodeType) -> Result<gst::Bin> {
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",
" ! rtph264depay",
" ! 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",
" ! rtpvrawdepay",
" ! rtpvrawpay name=pay0 pt=96",
)
}
"JPEG" => {
VideoEncodeType::Mjpg => {
concat!(
"proxysrc name=ProxySrc",
" ! queue leaky=downstream flush-on-eos=true max-size-buffers=0",
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fc6eb2f

Please sign in to comment.