add camera name to rtp packet loss messages

This commit is contained in:
Scott Lamb 2021-06-28 17:49:29 -07:00
parent 5be69baaa6
commit a50625e769
4 changed files with 52 additions and 22 deletions

View File

@ -125,11 +125,14 @@ fn press_test_inner(
username: Option<String>,
password: Option<String>,
) -> Result<String, Error> {
let (extra_data, _stream) = stream::FFMPEG.open(stream::Source::Rtsp {
url,
username,
password,
})?;
let (extra_data, _stream) = stream::FFMPEG.open(
"test stream".to_owned(),
stream::Source::Rtsp {
url,
username,
password,
},
)?;
Ok(format!(
"{}x{} video stream",
extra_data.entry.width, extra_data.entry.height

View File

@ -2256,7 +2256,10 @@ mod tests {
fn copy_mp4_to_db(db: &TestDb<RealClocks>) {
let (extra_data, mut input) = stream::FFMPEG
.open(stream::Source::File("src/testdata/clip.mp4"))
.open(
"test".to_owned(),
stream::Source::File("src/testdata/clip.mp4"),
)
.unwrap();
// 2015-04-26 00:00:00 UTC.
@ -2367,10 +2370,13 @@ mod tests {
fn compare_mp4s(new_filename: &str, pts_offset: i64, shorten: i64) {
let (orig_extra_data, mut orig) = stream::FFMPEG
.open(stream::Source::File("src/testdata/clip.mp4"))
.open(
"test".to_owned(),
stream::Source::File("src/testdata/clip.mp4"),
)
.unwrap();
let (new_extra_data, mut new) = stream::FFMPEG
.open(stream::Source::File(new_filename))
.open("test".to_owned(), stream::Source::File(new_filename))
.unwrap();
assert_eq!(orig_extra_data, new_extra_data);
let mut final_durations = None;

View File

@ -75,7 +75,8 @@ pub enum Source {
}
pub trait Opener: Send + Sync {
fn open(&self, src: Source) -> Result<(h264::ExtraData, Box<dyn Stream>), Error>;
fn open(&self, label: String, src: Source)
-> Result<(h264::ExtraData, Box<dyn Stream>), Error>;
}
pub struct VideoFrame<'a> {
@ -105,7 +106,11 @@ impl Ffmpeg {
}
impl Opener for Ffmpeg {
fn open(&self, src: Source) -> Result<(h264::ExtraData, Box<dyn Stream>), Error> {
fn open(
&self,
label: String,
src: Source,
) -> Result<(h264::ExtraData, Box<dyn Stream>), Error> {
use ffmpeg::avformat::InputFormatContext;
let mut input = match src {
#[cfg(test)]
@ -123,8 +128,8 @@ impl Opener for Ffmpeg {
)?;
if !open_options.empty() {
warn!(
"While opening URL {}, some options were not understood: {}",
url, open_options
"{}: While opening URL {}, some options were not understood: {}",
&label, url, open_options
);
}
i
@ -174,8 +179,8 @@ impl Opener for Ffmpeg {
)?;
if !open_options.empty() {
warn!(
"While opening URL {}, some options were not understood: {}",
url, open_options
"{}: While opening URL {}, some options were not understood: {}",
&label, url, open_options
);
}
i
@ -271,7 +276,11 @@ pub struct RetinaOpener {}
pub const RETINA: RetinaOpener = RetinaOpener {};
impl Opener for RetinaOpener {
fn open(&self, src: Source) -> Result<(h264::ExtraData, Box<dyn Stream>), Error> {
fn open(
&self,
label: String,
src: Source,
) -> Result<(h264::ExtraData, Box<dyn Stream>), Error> {
let (startup_tx, startup_rx) = tokio::sync::oneshot::channel();
let (frame_tx, frame_rx) = tokio::sync::mpsc::channel(1);
let handle = tokio::runtime::Handle::current();
@ -323,7 +332,12 @@ impl Opener for RetinaOpener {
Some(Ok(CodecItem::VideoFrame(v))) => {
deadline = tokio::time::Instant::now() + RETINA_TIMEOUT;
if v.loss > 0 {
log::warn!("lost {} RTP packets @ {:?}", v.loss, v.start_ctx());
log::warn!(
"{}: lost {} RTP packets @ {:?}",
&label,
v.loss,
v.start_ctx()
);
}
if frame_tx.send(Ok(v)).await.is_err() {
return; // other end died.

View File

@ -109,11 +109,14 @@ where
let (extra_data, mut stream) = {
let _t = TimerGuard::new(&clocks, || format!("opening {}", self.url.as_str()));
self.opener.open(stream::Source::Rtsp {
url: self.url.clone(),
username: self.username.clone(),
password: self.password.clone(),
})?
self.opener.open(
self.short_name.clone(),
stream::Source::Rtsp {
url: self.url.clone(),
username: self.username.clone(),
password: self.password.clone(),
},
)?
};
let realtime_offset = self.db.clocks().realtime() - clocks.monotonic();
let video_sample_entry_id = {
@ -285,6 +288,7 @@ mod tests {
impl stream::Opener for MockOpener {
fn open(
&self,
_label: String,
src: stream::Source,
) -> Result<(h264::ExtraData, Box<dyn stream::Stream>), Error> {
match src {
@ -337,7 +341,10 @@ mod tests {
clocks.sleep(time::Duration::seconds(86400)); // to 2015-04-26 00:00:00 UTC
let (extra_data, stream) = stream::FFMPEG
.open(stream::Source::File("src/testdata/clip.mp4"))
.open(
"test".to_owned(),
stream::Source::File("src/testdata/clip.mp4"),
)
.unwrap();
let mut stream = ProxyingStream::new(clocks.clone(), time::Duration::seconds(2), stream);
stream.ts_offset = 123456; // starting pts of the input should be irrelevant