add info cmd to example client, README update

This commit is contained in:
Yegor Bayev 2021-12-28 15:41:30 +03:00
parent 82be42af87
commit 091ee0f18e
3 changed files with 28 additions and 5 deletions

View File

@ -63,12 +63,24 @@ Help welcome!
Try the `mp4` example. It streams from an RTSP server to a `.mp4` file until
you hit ctrl-C.
```
```shell
$ cargo run --example client mp4 --url rtsp://ip.address.goes.here/ --username admin --password test out.mp4
...
^C
```
## Example client
```shell
$ cargo run --example client <CMD>
```
Where CMD:
* **info** - Get info about available streams and exit
* **mp4** - Write RTSP streams to mp4 file, exit with Ctrl+C
* **metadata** - Get realtime onvif metadata if available, exit with Ctrl+C
## Acknowledgements
This builds on the whole Rust ecosystem. A couple folks have been especially

View File

@ -28,8 +28,12 @@ struct Source {
#[derive(StructOpt)]
enum Cmd {
/// Write available audio and video streams to mp4 file
Mp4(mp4::Opts),
/// Get realtime metadata of onvif stream, use Ctrl+C to stop
Metadata(metadata::Opts),
/// Get info about available streams and exit
Info(metadata::Opts),
}
fn init_logging() -> mylog::Handle {
@ -78,6 +82,7 @@ async fn main_inner() -> Result<(), Error> {
let cmd = Cmd::from_args();
match cmd {
Cmd::Mp4(opts) => mp4::run(opts).await,
Cmd::Metadata(opts) => metadata::run(opts).await,
Cmd::Metadata(opts) => metadata::run(opts, false).await,
Cmd::Info(opts) => metadata::run(opts, true).await,
}
}

View File

@ -14,16 +14,16 @@ pub struct Opts {
src: super::Source,
}
pub async fn run(opts: Opts) -> Result<(), Error> {
pub async fn run(opts: Opts, is_info: bool) -> Result<(), Error> {
let session_group = Arc::new(SessionGroup::default());
let r = run_inner(opts, session_group.clone()).await;
let r = run_inner(opts, session_group.clone(), is_info).await;
if let Err(e) = session_group.await_teardown().await {
error!("TEARDOWN failed: {}", e);
}
r
}
async fn run_inner(opts: Opts, session_group: Arc<SessionGroup>) -> Result<(), Error> {
async fn run_inner(opts: Opts, session_group: Arc<SessionGroup>, is_info: bool) -> Result<(), Error> {
let stop = tokio::signal::ctrl_c();
let creds = super::creds(opts.src.username, opts.src.password);
@ -35,6 +35,12 @@ async fn run_inner(opts: Opts, session_group: Arc<SessionGroup>) -> Result<(), E
.session_group(session_group),
)
.await?;
if is_info {
for stream in session.streams() {
println!("{}", stream);
}
return Ok(());
}
let onvif_stream_i = session
.streams()
.iter()