Address pausing of buffers
This commit is contained in:
4 files changed
+79
-32
No files matched your search
@@ -120,6 +120,8 @@ pub(crate) enum FactoryCommand {
|
||||
BcMedia(BcMedia),
|
||||
ClearBuffer,
|
||||
JumpToLive,
|
||||
Pause,
|
||||
Resume,
|
||||
}
|
||||
|
||||
pub(crate) struct NeoMediaFactoryImpl {
|
||||
|
||||
+45
-32
@@ -402,6 +402,17 @@ impl NeoMediaSenders {
|
||||
client.inited = false;
|
||||
}
|
||||
},
|
||||
FactoryCommand::Pause => {
|
||||
for client in self.client_data.values_mut() {
|
||||
client.playing = false;
|
||||
}
|
||||
},
|
||||
FactoryCommand::Resume => {
|
||||
for client in self.client_data.values_mut() {
|
||||
client.playing = true;
|
||||
let _ = client.jump_to_live().await;
|
||||
}
|
||||
},
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
@@ -638,44 +649,46 @@ impl NeoMediaSender {
|
||||
}
|
||||
|
||||
async fn update(&mut self) -> AnyResult<()> {
|
||||
self.update_starttime().await?;
|
||||
let mut buffers = vec![];
|
||||
if !self
|
||||
.vid
|
||||
.as_ref()
|
||||
.map(|x| x.pads().iter().all(|pad| pad.is_linked()))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return Err(anyhow!("Vid src is closed"));
|
||||
}
|
||||
if self.buffer.buf.len() < 4 {
|
||||
error!("Buffer exhausted. Not enough data from Camera.");
|
||||
} else {
|
||||
trace!("Buffer size: {}", self.buffer.buf.len());
|
||||
}
|
||||
const LATENCY: FrameTime = Duration::from_millis(250).as_micros() as FrameTime;
|
||||
if let Some(buftime) = self.get_buftime().map(|i| i.saturating_add(LATENCY)) {
|
||||
// debug!("Update: buftime: {}", buftime);
|
||||
while self
|
||||
.buffer
|
||||
.buf
|
||||
.front()
|
||||
.map(|data| data.time <= buftime)
|
||||
if self.playing {
|
||||
self.update_starttime().await?;
|
||||
let mut buffers = vec![];
|
||||
if !self
|
||||
.vid
|
||||
.as_ref()
|
||||
.map(|x| x.pads().iter().all(|pad| pad.is_linked()))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
tokio::task::yield_now().await;
|
||||
match self.buffer.buf.pop_front() {
|
||||
Some(frame) => {
|
||||
buffers.push(frame);
|
||||
return Err(anyhow!("Vid src is closed"));
|
||||
}
|
||||
if self.buffer.buf.len() < 4 {
|
||||
error!("Buffer exhausted. Not enough data from Camera.");
|
||||
} else {
|
||||
trace!("Buffer size: {}", self.buffer.buf.len());
|
||||
}
|
||||
const LATENCY: FrameTime = Duration::from_millis(250).as_micros() as FrameTime;
|
||||
if let Some(buftime) = self.get_buftime().map(|i| i.saturating_add(LATENCY)) {
|
||||
// debug!("Update: buftime: {}", buftime);
|
||||
while self
|
||||
.buffer
|
||||
.buf
|
||||
.front()
|
||||
.map(|data| data.time <= buftime)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
tokio::task::yield_now().await;
|
||||
match self.buffer.buf.pop_front() {
|
||||
Some(frame) => {
|
||||
buffers.push(frame);
|
||||
}
|
||||
None => break,
|
||||
}
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tokio::task::yield_now().await;
|
||||
// collect certain frames
|
||||
self.send_buffers(&buffers).await?;
|
||||
tokio::task::yield_now().await;
|
||||
// collect certain frames
|
||||
self.send_buffers(&buffers).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -302,6 +302,26 @@ impl NeoRtspServer {
|
||||
Err(anyhow!("No such tag"))
|
||||
}
|
||||
}
|
||||
|
||||
// Pause on all senders of a tag
|
||||
pub(crate) async fn pause<T: Into<String>>(&self, tag: T) -> AnyResult<()> {
|
||||
if let Some(sender) = self.imp().get_sender(tag).await {
|
||||
sender.send(FactoryCommand::Pause).await?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("No such tag"))
|
||||
}
|
||||
}
|
||||
|
||||
// Resume on all senders of a tag
|
||||
pub(crate) async fn resume<T: Into<String>>(&self, tag: T) -> AnyResult<()> {
|
||||
if let Some(sender) = self.imp().get_sender(tag).await {
|
||||
sender.send(FactoryCommand::Resume).await?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("No such tag"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for NeoRtspServer {}
|
||||
|
||||
@@ -279,6 +279,12 @@ async fn camera_main(camera: Camera<Disconnected>) -> Result<(), CameraFailureKi
|
||||
}.with_context(|| format!("{}: Error while streaming", name))
|
||||
.map_err(CameraFailureKind::Retry)?;
|
||||
|
||||
tags.iter()
|
||||
.map(|tag| rtsp_thread.pause(tag))
|
||||
.collect::<FuturesUnordered<_>>()
|
||||
.collect::<Vec<_>>()
|
||||
.await;
|
||||
|
||||
let paused = streaming
|
||||
.stop()
|
||||
.await
|
||||
@@ -346,5 +352,11 @@ async fn camera_main(camera: Camera<Disconnected>) -> Result<(), CameraFailureKi
|
||||
.await
|
||||
.with_context(|| format!("{}: Could not start stream", name))
|
||||
.map_err(CameraFailureKind::Retry)?;
|
||||
|
||||
tags.iter()
|
||||
.map(|tag| rtsp_thread.resume(tag))
|
||||
.collect::<FuturesUnordered<_>>()
|
||||
.collect::<Vec<_>>()
|
||||
.await;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user