2021-06-04 03:26:45 +04:00
|
|
|
// Copyright (C) 2021 Scott Lamb <slamb@slamb.org>
|
|
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
|
2021-07-08 21:52:39 +04:00
|
|
|
use anyhow::{anyhow, Error};
|
2021-06-04 03:26:45 +04:00
|
|
|
use futures::StreamExt;
|
|
|
|
use log::info;
|
|
|
|
use retina::codec::CodecItem;
|
|
|
|
|
|
|
|
#[derive(structopt::StructOpt)]
|
|
|
|
pub struct Opts {
|
|
|
|
#[structopt(flatten)]
|
|
|
|
src: super::Source,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn run(opts: Opts) -> Result<(), Error> {
|
|
|
|
let stop = tokio::signal::ctrl_c();
|
|
|
|
|
|
|
|
let creds = super::creds(opts.src.username, opts.src.password);
|
|
|
|
let mut session = retina::client::Session::describe(opts.src.url, creds).await?;
|
|
|
|
let onvif_stream_i = session
|
|
|
|
.streams()
|
|
|
|
.iter()
|
|
|
|
.position(|s| matches!(s.parameters(), Some(retina::codec::Parameters::Message(..))))
|
2021-07-08 21:52:39 +04:00
|
|
|
.ok_or_else(|| anyhow!("couldn't find onvif stream"))?;
|
2021-06-04 03:26:45 +04:00
|
|
|
session.setup(onvif_stream_i).await?;
|
|
|
|
let session = session
|
|
|
|
.play(retina::client::PlayPolicy::default().ignore_zero_seq(true))
|
|
|
|
.await?
|
|
|
|
.demuxed()?;
|
|
|
|
|
|
|
|
tokio::pin!(session);
|
|
|
|
tokio::pin!(stop);
|
|
|
|
loop {
|
|
|
|
tokio::select! {
|
|
|
|
item = session.next() => {
|
2021-07-08 21:52:39 +04:00
|
|
|
match item.ok_or_else(|| anyhow!("EOF"))?? {
|
2021-06-04 03:26:45 +04:00
|
|
|
CodecItem::MessageFrame(m) => {
|
|
|
|
info!("{}: {}\n", &m.timestamp, std::str::from_utf8(&m.data[..]).unwrap());
|
|
|
|
},
|
|
|
|
_ => continue,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
_ = &mut stop => {
|
|
|
|
break;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|