Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to CLAP from Argparse #61

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 119 additions & 6 deletions gstscream/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gstscream/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ libc = "0.2.68"
failure = "0.1"
gtypes = "0.2.0"
chrono = "0.4"
argparse = "0.2.2"
clap = { version = "4.5.11", features=["env","derive"] }

[lib]
name = "gstscream"
Expand Down
28 changes: 22 additions & 6 deletions gstscream/src/receiver.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#![allow(clippy::uninlined_format_args)]
extern crate failure;
use failure::Error;
use std::fmt::Display;

use std::env;
use clap::Parser;
use failure::Error;

extern crate gtypes;

Expand All @@ -12,16 +13,26 @@ use gst::prelude::*;

extern crate chrono;

#[derive(clap::Parser)]
#[command(version, about, long_about = None)]
struct Arguments {
#[arg(env)]
/// The gstreamer pipeline to use for the receiver application.
recvpipeline: String,
}

fn main() {
let args = Arguments::parse();
println!("{args}");
gst::init().expect("Failed to initialize");

let main_loop = glib::MainLoop::new(None, false);

start(&main_loop).expect("Failed to start");
start(&main_loop, args).expect("Failed to start");
}

pub fn start(main_loop: &glib::MainLoop) -> Result<(), Error> {
let pls: String = env::var("RECVPIPELINE").unwrap();
fn start(main_loop: &glib::MainLoop, args: Arguments) -> Result<(), Error> {
let pls: String = args.recvpipeline;
println!("RECVPIPELINE={}", pls);
let pipeline = gst::parse::launch(&pls).unwrap();

Expand All @@ -42,7 +53,6 @@ pub fn start(main_loop: &glib::MainLoop) -> Result<(), Error> {
.add_watch(move |_, msg| {
use gst::MessageView;

// println!("bus {:?}", msg.view());
let main_loop = &main_loop_clone;
match msg.view() {
MessageView::Eos(..) => {
Expand Down Expand Up @@ -71,3 +81,9 @@ pub fn start(main_loop: &glib::MainLoop) -> Result<(), Error> {

Ok(())
}

impl Display for Arguments {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Configuration:\n\t- Pipeline {}", self.recvpipeline)
}
}
19 changes: 1 addition & 18 deletions gstscream/src/screamrx/ScreamRx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,6 @@ impl Default for ScreamRx {
}
}

use std::io::Write;
struct WriteToGstInfo {
cat: gst::DebugCategory,
}
impl Write for WriteToGstInfo {
fn write(&mut self, buf: &[u8]) -> Result<usize, std::io::Error> {
let str_buf = String::from_utf8_lossy(buf);
gst::error!(self.cat, "{}", str_buf);
let len = str_buf.len();
Ok(len)
}
fn flush(&mut self) -> Result<(), std::io::Error> {
// nothing to do
Ok(())
}
}

impl ScreamRx {
pub fn ScreamReceiverPluginInit(&mut self, rtcp_srcpad: Option<Arc<Mutex<gst::Pad>>>) {
gst::info!(CAT, "Init");
Expand Down Expand Up @@ -189,7 +172,7 @@ impl ScreamRx {
* to the range [2ms,100ms]
*/
let mut rate: f64 = 0.02 * self.averageReceivedRate / (100.0 * 8.0); // RTCP overhead
rate = f64::min(500.0, f64::max(10.0, rate));
rate = rate.clamp(10., 500.);
/*
* More than one stream ?, increase the feedback rate as
* we currently don't bundle feedback packets
Expand Down
Loading