No smooth and extra debug

This commit is contained in:
QuantumEntangledAndy committed 2023-05-15 19:44:07 +07:00
1 parent 279c1c5bf1
commit 36f70c3222
4 files changed
+64 -19

No files matched your search

+27 -6
View File
@@ -30,7 +30,7 @@ use crate::rtsp::Spring;
type FrameTime = i64;
const BUFFER_SIZE: usize = 100;
const BUFFER_SIZE: usize = 300;
#[derive(Debug, Clone)]
struct Stamped {
@@ -390,6 +390,15 @@ impl NeoMediaSenders {
Some(v) = self.data_source.next() => {
match v {
FactoryCommand::BcMedia(media) => {
let frame_time = match &media {
BcMedia::Iframe(data) => Some(Duration::from_micros(data.microseconds as u64)),
BcMedia::Pframe(data) => Some(Duration::from_micros(data.microseconds as u64)),
_ => None,
};
if let Some(frame_time) = frame_time {
debug!("Got frame at {:?}", frame_time);
}
self.handle_new_data(media).await?;
},
FactoryCommand::ClearBuffer => {
@@ -444,6 +453,7 @@ pub(super) struct NeoMediaSender {
command_sender: Sender<NeoMediaSenderCommand>,
inited: bool,
playing: bool,
refilling: bool,
}
impl NeoMediaSender {
@@ -459,6 +469,7 @@ impl NeoMediaSender {
command_sender: tx,
inited: false,
playing: true,
refilling: false,
}
}
@@ -538,9 +549,9 @@ impl NeoMediaSender {
async fn update_starttime(&mut self) -> AnyResult<()> {
self.start_time.update().await;
if let (Some(runtime), Some(target_time)) = (self.get_runtime(), self.target_live()) {
self.start_time.set_target((target_time - runtime) as f64);
}
// if let (Some(runtime), Some(target_time)) = (self.get_runtime(), self.target_live()) {
// self.start_time.set_target((target_time - runtime) as f64);
// }
Ok(())
}
@@ -666,7 +677,17 @@ impl NeoMediaSender {
}
async fn update(&mut self) -> AnyResult<()> {
if self.inited && self.playing {
if self.refilling && self.buffer.ready() {
self.refilling = false;
self.jump_to_live().await?;
} else if self.refilling {
debug!(
"Refilling: {}/{} ({:.2}%)",
self.buffer.buf.len(),
BUFFER_SIZE * 2 / 3,
self.buffer.buf.len() as f32 / (BUFFER_SIZE * 2 / 3) as f32 * 100.0
);
} else if !self.refilling && self.inited && self.playing {
self.update_starttime().await?;
let mut buffers = vec![];
if !self
@@ -681,7 +702,7 @@ impl NeoMediaSender {
warn!(
"Buffer exhausted. Not enough data from Camera. Pausing RTSP until refilled."
);
self.inited = false;
self.refilling = true;
} else {
debug!("Buffer size: {}", self.buffer.buf.len());
}
+9
View File
@@ -36,4 +36,13 @@ impl Camera<Connected> {
},
})
}
#[allow(unused)]
pub(crate) async fn join(&self) -> Result<()> {
self.state
.camera
.join()
.await
.map_err(|e| anyhow::anyhow!("Camera join error: {:?}", e))
}
}
+9
View File
@@ -96,4 +96,13 @@ impl Camera<LoggedIn> {
pub(crate) fn get_camera(&self) -> &BcCamera {
&self.state.camera
}
#[allow(unused)]
pub(crate) async fn join(&self) -> Result<()> {
self.state
.camera
.join()
.await
.map_err(|e| anyhow::anyhow!("Camera join error: {:?}", e))
}
}
+19 -13
View File
@@ -100,20 +100,26 @@ impl Camera<Streaming> {
}
pub(crate) async fn join(&self) -> Result<()> {
let mut locked_threads = self.state.set.write().await;
while let Some(res) = locked_threads.join_next().await {
match res {
Err(e) => {
locked_threads.abort_all();
return Err(e.into());
tokio::select! {
v = async {
let mut locked_threads = self.state.set.write().await;
while let Some(res) = locked_threads.join_next().await {
match res {
Err(e) => {
locked_threads.abort_all();
return Err(e.into());
}
Ok(Err(e)) => {
locked_threads.abort_all();
return Err(e);
}
Ok(Ok(())) => {}
}
}
Ok(Err(e)) => {
locked_threads.abort_all();
return Err(e);
}
Ok(Ok(())) => {}
}
}
Ok(())
} => v,
v = self.state.camera.join() => v.map_err(|e| anyhow!("Camera join error: {:?}", e)),
}?;
Ok(())
}