Jump to live if more than 15s difference

This commit is contained in:
QuantumEntangledAndy committed 2023-05-04 09:10:52 +07:00
1 parent 386fec4220
commit b07aa2ddfe
2 files changed
+44 -44

No files matched your search

+16 -16
View File
@@ -7,7 +7,7 @@ use crate::bc::model::*;
use crate::bc::xml::*;
use crate::{Credentials, Error, Result};
use bytes::BytesMut;
use std::io;
use nom::AsBytes;
use tokio_util::codec::{Decoder, Encoder};
pub(crate) struct BcCodex {
@@ -48,24 +48,24 @@ impl Decoder for BcCodex {
type Error = Error;
fn decode_eof(&mut self, buf: &mut BytesMut) -> Result<Option<Self::Item>> {
// match self.decode(buf)? {
// Some(frame) => Ok(Some(frame)),
// None => {
// if buf.is_empty() {
// Ok(None)
// } else {
// Err(io::Error::new(
// io::ErrorKind::Other,
// format!("bytes remaining on BC stream: {:X?}", buf),
// )
// .into())
// }
// }
// }
match self.decode(buf)? {
Some(frame) => Ok(Some(frame)),
None => Ok(None),
None => {
if buf.is_empty() {
Ok(None)
} else {
log::debug!("bytes remaining on BC stream: {:X?}", buf.as_bytes());
// Right after this we seem to get an issue with the camera dropping us
// Needs probing
// \xf0\xde\xbc\n\x03\0\0\0@\x9c\0\0\0\x01\x04\0\xc8\0\0\0\0\0\0\0\t\x11\xc6\xa0\x12\xdb\xf7:E\x96*
Ok(None)
}
}
}
// match self.decode(buf)? {
// Some(frame) => Ok(Some(frame)),
// None => Ok(None),
// }
}
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>> {
+28 -28
View File
@@ -296,11 +296,11 @@ impl NeoMediaSenders {
occ.remove();
continue;
}
// if let Err(e) = occ.get_mut().process_jump_to_live(&self.buffer).await {
// debug!("Could not handle jump to live: {:?}", e);
// occ.remove();
// continue;
// }
if let Err(e) = occ.get_mut().process_jump_to_live(&self.buffer).await {
debug!("Could not handle jump to live: {:?}", e);
occ.remove();
continue;
}
if let Err(e) = occ.get_mut().process_buffer(&self.buffer).await {
debug!("Could not send client data: {:?}", e);
occ.remove();
@@ -563,26 +563,26 @@ impl NeoMediaSender {
Ok(last_sent_time)
}
// async fn process_jump_to_live(&mut self, buffer: &NeoBuffer) -> AnyResult<()> {
// if self.inited {
// if let (Some(buffer_start), Some(buffer_end)) = (buffer.start_time(), buffer.end_time())
// {
// let runtime = self.get_buftime().unwrap_or(self.last_sent_time);
// if runtime < buffer_start.saturating_sub(LATENCY * 2)
// || runtime > buffer_end.saturating_add(LATENCY * 2)
// {
// debug!(
// "Outside buffer jumping to live: {:?} < {:?} < {:?}",
// Duration::from_micros(buffer_start.try_into().unwrap_or(0)),
// Duration::from_micros(runtime.try_into().unwrap_or(0)),
// Duration::from_micros(buffer_end.try_into().unwrap_or(0))
// );
// self.jump_to_live(buffer).await?;
// }
// }
// }
// Ok(())
// }
async fn process_jump_to_live(&mut self, buffer: &NeoBuffer) -> AnyResult<()> {
if self.inited {
if let (Some(buffer_start), Some(buffer_end)) = (buffer.start_time(), buffer.end_time())
{
let runtime = self.get_buftime().unwrap_or(self.last_sent_time);
if runtime < buffer_start.saturating_sub(15 * SECS)
|| runtime > buffer_end.saturating_add(15 * SECS)
{
debug!(
"Outside buffer jumping to live: {:?} < {:?} < {:?}",
Duration::from_micros(buffer_start.try_into().unwrap_or(0)),
Duration::from_micros(runtime.try_into().unwrap_or(0)),
Duration::from_micros(buffer_end.try_into().unwrap_or(0))
);
self.jump_to_live(buffer).await?;
}
}
}
Ok(())
}
fn get_runtime(&self) -> Option<FrameTime> {
if let Some(appsrc) = self.vid.as_ref() {
@@ -598,9 +598,9 @@ impl NeoMediaSender {
None
}
// fn get_buftime(&self) -> Option<FrameTime> {
// self.get_runtime().map(|time| self.runtime_to_buftime(time))
// }
fn get_buftime(&self) -> Option<FrameTime> {
self.get_runtime().map(|time| self.runtime_to_buftime(time))
}
async fn send_buffer(&mut self, media: &BcMedia) -> AnyResult<bool> {
if self.inited && self.playing {