videocall_daemon/
cli_args.rs1use std::str::FromStr;
2
3use clap::{ArgGroup, Args, Parser, Subcommand};
4use thiserror::Error;
5use url::Url;
6use videocall_nokhwa::utils::FrameFormat;
7
8#[derive(Parser, Debug)]
14#[clap(name = "client")]
15pub struct Opt {
16 #[clap(subcommand)]
17 pub mode: Mode,
18}
19
20#[derive(Clone, Debug)]
21pub enum IndexKind {
22 String(String),
23 Index(u32),
24}
25
26#[derive(Error, Debug)]
27pub enum ParseIndexKindError {
28 #[error("Invalid index value: {0}")]
29 InvalidIndex(String),
30}
31
32impl FromStr for IndexKind {
33 type Err = ParseIndexKindError;
34
35 fn from_str(s: &str) -> Result<Self, Self::Err> {
36 if let Ok(index) = s.parse::<u32>() {
37 Ok(IndexKind::Index(index))
38 } else {
39 Ok(IndexKind::String(s.to_string()))
40 }
41 }
42}
43
44#[derive(Subcommand, Debug)]
45pub enum Mode {
46 Stream(Stream),
48
49 Info(Info),
51}
52
53#[derive(Args, Debug, Clone)]
54pub struct Stream {
55 #[clap(long = "url", default_value = "https://transport.rustlemania.com")]
57 pub url: Url,
58
59 #[clap(long = "user-id")]
60 pub user_id: String,
61
62 #[clap(long = "meeting-id")]
63 pub meeting_id: String,
64
65 #[clap(long = "video-device-index", short = 'v')]
78 pub video_device_index: Option<IndexKind>,
79
80 #[clap(long = "audio-device", short = 'a')]
81 pub audio_device: Option<String>,
82
83 #[clap(long = "resolution", short = 'r')]
85 #[clap(default_value = "1280x720")]
86 pub resolution: String,
87
88 #[clap(long = "fps")]
90 #[clap(default_value = "30")]
91 pub fps: u32,
92
93 #[clap(long = "bitrate-kbps")]
94 #[clap(default_value = "500")]
95 pub bitrate_kbps: u32,
96
97 #[arg(long, default_value_t = 5, value_parser = clap::value_parser!(u8).range(4..=15))]
109 pub vp9_cpu_used: u8,
110
111 #[arg(long, default_value_t = FrameFormat::NV12, value_parser = parse_frame_format)]
115 pub frame_format: FrameFormat,
116
117 #[clap(long = "debug-keylog")]
119 pub keylog: bool,
120
121 #[clap(long = "debug-send-test-pattern")]
123 pub send_test_pattern: bool,
124
125 #[clap(long = "debug-offline-streaming-test")]
127 pub local_streaming_test: bool,
128}
129
130fn parse_frame_format(s: &str) -> Result<FrameFormat, String> {
131 match s {
132 "NV12" => Ok(FrameFormat::NV12),
133 "YUYV" => Ok(FrameFormat::YUYV),
136 _ => Err("Invalid frame format, please use one of [NV12, BGRA, YUYV]".to_string()),
137 }
138}
139
140#[derive(Args, Debug)]
141#[clap(group = ArgGroup::new("info").required(true))]
142pub struct Info {
143 #[clap(long = "list-cameras", group = "info")]
145 pub list_cameras: bool,
146
147 #[clap(long = "list-formats", group = "info")]
149 pub list_formats: Option<IndexKind>, #[clap(long = "list-resolutions", group = "info")]
153 pub list_resolutions: Option<IndexKind>, }
155
156#[derive(Args, Debug, Clone)]
157pub struct TestCamera {
158 #[clap(long = "video-device-index")]
159 pub video_device_index: IndexKind,
160}