redact URLs within stream.rs; fixes #13

This commit is contained in:
Scott Lamb 2019-02-13 22:34:19 -08:00
parent d7a0cb9a7c
commit 579150c9d5
5 changed files with 21 additions and 8 deletions

2
Cargo.lock generated
View File

@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "MacTypes-sys"
version = "1.3.0"

View File

@ -102,7 +102,10 @@ fn press_edit(siv: &mut Cursive, db: &Arc<db::Database>, id: Option<i32>) {
}
fn press_test_inner(url: &str) -> Result<String, Error> {
let stream = stream::FFMPEG.open(stream::Source::Rtsp(url))?;
let stream = stream::FFMPEG.open(stream::Source::Rtsp {
url,
redacted_url: url,
})?;
let extra_data = stream.get_extra_data()?;
Ok(format!("{}x{} video stream", extra_data.width, extra_data.height))
}

View File

@ -1812,7 +1812,7 @@ mod tests {
pkt.is_key()).unwrap();
end_pts = Some(pts + pkt.duration() as i64);
}
output.close(end_pts);
output.close(end_pts).unwrap();
db.syncer_channel.flush();
}

View File

@ -45,10 +45,15 @@ lazy_static! {
}
pub enum Source<'a> {
/// A filename, for testing.
#[cfg(test)]
File(&'a str), // filename, for testing.
File(&'a str),
Rtsp(&'a str), // url, for production use.
/// An RTSP stream, for production use.
Rtsp {
url: &'a str,
redacted_url: &'a str
},
}
pub trait Opener<S : Stream> : Sync {
@ -98,7 +103,7 @@ impl Opener<FfmpegStream> for Ffmpeg {
}
(i, false)
}
Source::Rtsp(url) => {
Source::Rtsp{url, redacted_url} => {
let mut open_options = ffmpeg::Dictionary::new();
open_options.set(c_str!("rtsp_transport"), c_str!("tcp")).unwrap();
open_options.set(c_str!("user-agent"), c_str!("moonfire-nvr")).unwrap();
@ -112,7 +117,7 @@ impl Opener<FfmpegStream> for Ffmpeg {
let i = InputFormatContext::open(&CString::new(url).unwrap(), &mut open_options)?;
if !open_options.empty() {
warn!("While opening URL {}, some options were not understood: {}",
url, open_options);
redacted_url, open_options);
}
(i, true)
},

View File

@ -103,7 +103,10 @@ impl<'a, C, S> Streamer<'a, C, S> where C: 'a + Clocks + Clone, S: 'a + stream::
let mut stream = {
let _t = TimerGuard::new(&clocks, || format!("opening {}", self.redacted_url));
self.opener.open(stream::Source::Rtsp(&self.url))?
self.opener.open(stream::Source::Rtsp {
url: &self.url,
redacted_url: &self.redacted_url,
})?
};
let realtime_offset = self.db.clocks().realtime() - clocks.monotonic();
// TODO: verify width/height.
@ -275,7 +278,7 @@ mod tests {
impl<'a> stream::Opener<ProxyingStream<'a>> for MockOpener<'a> {
fn open(&self, src: stream::Source) -> Result<ProxyingStream<'a>, Error> {
match src {
stream::Source::Rtsp(url) => assert_eq!(url, &self.expected_url),
stream::Source::Rtsp{url, ..} => assert_eq!(url, &self.expected_url),
stream::Source::File(_) => panic!("expected rtsp url"),
};
let mut l = self.streams.lock();