1use std::path::PathBuf;
4use std::time::Duration;
5
6use clap::builder::BoolishValueParser;
7use clap::{ArgAction, Args, ValueEnum};
8use moqros::ros::QosProfile;
9
10use crate::url::{insecurity, redact_url};
11
12#[derive(Debug, Clone, Args)]
14pub struct RelayArgs {
15 #[arg(long, env = "MOQROS_URL", default_value = "http://localhost:4443/anon")]
17 pub url: moqros::Url,
18
19 #[arg(long, env = "MOQROS_INSECURE", action = ArgAction::Set, value_parser = BoolishValueParser::new(),
21 num_args = 0..=1, require_equals = true, default_value_t = false, default_missing_value = "true")]
22 pub insecure: bool,
23
24 #[arg(long, env = "MOQROS_TLS_CERT", requires = "tls_key")]
26 pub tls_cert: Option<PathBuf>,
27
28 #[arg(long, env = "MOQROS_TLS_KEY", requires = "tls_cert")]
30 pub tls_key: Option<PathBuf>,
31}
32
33impl RelayArgs {
34 pub fn config(&self) -> moqros::ClientConfig {
35 moqros::ClientConfig {
36 url: self.url.clone(),
37 insecure: self.insecure,
38 tls_cert: self.tls_cert.clone(),
39 tls_key: self.tls_key.clone(),
40 }
41 }
42
43 pub fn redacted_url(&self) -> moqros::Url {
45 redact_url(&self.url)
46 }
47
48 pub fn warn_if_insecure(&self) {
50 if let Some(reason) = insecurity(&self.url, self.insecure) {
51 tracing::warn!("{reason}; anyone on the network path can read or alter the stream");
52 }
53 }
54}
55
56#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
58pub enum Format {
59 Video,
61 Json,
63 Cdr,
65}
66
67impl Format {
68 pub fn data(self) -> Option<moqros::DataFormat> {
70 match self {
71 Self::Video => None,
72 Self::Json => Some(moqros::DataFormat::Json),
73 Self::Cdr => Some(moqros::DataFormat::Cdr),
74 }
75 }
76}
77
78#[derive(Debug, Clone, Args)]
80pub struct QosArgs {
81 #[arg(long, action = ArgAction::Set, value_parser = BoolishValueParser::new(),
83 num_args = 0..=1, require_equals = true, default_value_t = false, default_missing_value = "true")]
84 pub reliable: bool,
85}
86
87impl QosArgs {
88 pub fn profile(&self) -> QosProfile {
89 if self.reliable {
90 QosProfile::default().keep_last(5)
91 } else {
92 QosProfile::sensor_data()
93 }
94 }
95}
96
97#[derive(Debug, Clone, Args)]
99pub struct EncoderArgs {
100 #[arg(long, default_value_t = moqros::Codec::default())]
103 pub codec: moqros::Codec,
104
105 #[arg(long, default_value_t = moqros::Hardware::default())]
109 pub hw: moqros::Hardware,
110
111 #[arg(long, default_value_t = 2_000_000)]
113 pub bitrate: u32,
114
115 #[arg(long, default_value_t = 30.0)]
117 pub fps: f32,
118
119 #[arg(long, default_value_t = 2000)]
121 pub keyframe_interval_ms: u64,
122}
123
124impl EncoderArgs {
125 pub fn settings(&self) -> moqros::EncoderSettings {
126 moqros::EncoderSettings {
127 codec: self.codec,
128 bitrate: self.bitrate,
129 max_fps: self.fps,
130 keyframe_interval: Duration::from_millis(self.keyframe_interval_ms),
131 hardware: self.hw,
132 ..Default::default()
133 }
134 }
135}