Skip frames before first iframe
This commit is contained in:
3 files changed
+57
-18
No files matched your search
@@ -407,6 +407,7 @@ pub(crate) struct StreamConfig {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct StampedData {
|
||||
pub(crate) keyframe: bool,
|
||||
pub(crate) data: Arc<Vec<u8>>,
|
||||
pub(crate) ts: Duration,
|
||||
}
|
||||
@@ -552,6 +553,8 @@ impl StreamData {
|
||||
let watchdog_tx = watchdog_tx.clone();
|
||||
log::debug!("Running Stream Instance Task");
|
||||
Box::pin(async move {
|
||||
let mut recieved_iframe = false;
|
||||
let mut aud_keyframe = false;
|
||||
let res = async {
|
||||
let mut prev_ts = Duration::ZERO;
|
||||
let mut stream_data = camera.start_video(name, 0, strict).await?;
|
||||
@@ -636,9 +639,10 @@ impl StreamData {
|
||||
}
|
||||
|
||||
match data {
|
||||
BcMedia::Iframe(BcMediaIframe{data, microseconds, ..}) | BcMedia::Pframe(BcMediaPframe{data, microseconds,..}) => {
|
||||
BcMedia::Iframe(BcMediaIframe{data, microseconds, ..}) => {
|
||||
prev_ts = Duration::from_micros(microseconds as u64);
|
||||
let d = StampedData{
|
||||
keyframe: true,
|
||||
data: Arc::new(data),
|
||||
ts: prev_ts
|
||||
};
|
||||
@@ -649,13 +653,33 @@ impl StreamData {
|
||||
history.pop_front();
|
||||
}
|
||||
});
|
||||
recieved_iframe = true;
|
||||
aud_keyframe = true;
|
||||
log::trace!("Sent Vid Key Frame");
|
||||
},
|
||||
BcMedia::Pframe(BcMediaPframe{data, microseconds,..}) if recieved_iframe => {
|
||||
prev_ts = Duration::from_micros(microseconds as u64);
|
||||
let d = StampedData{
|
||||
keyframe: false,
|
||||
data: Arc::new(data),
|
||||
ts: prev_ts
|
||||
};
|
||||
let _ = vid_tx.send(d.clone());
|
||||
vid_history.send_modify(|history| {
|
||||
history.push_back(d);
|
||||
while history.len() > 100 {
|
||||
history.pop_front();
|
||||
}
|
||||
});
|
||||
log::trace!("Sent Vid Frame");
|
||||
}
|
||||
BcMedia::Aac(BcMediaAac{data, ..}) | BcMedia::Adpcm(BcMediaAdpcm{data,..}) => {
|
||||
BcMedia::Aac(BcMediaAac{data, ..}) | BcMedia::Adpcm(BcMediaAdpcm{data,..}) if recieved_iframe => {
|
||||
let d = StampedData{
|
||||
data: Arc::new(data),
|
||||
ts: prev_ts,
|
||||
keyframe: aud_keyframe,
|
||||
data: Arc::new(data),
|
||||
ts: prev_ts,
|
||||
};
|
||||
aud_keyframe = false;
|
||||
let _ = aud_tx.send(d.clone())?;
|
||||
aud_history.send_modify(|history| {
|
||||
history.push_back(d);
|
||||
|
||||
+9
-2
@@ -52,8 +52,15 @@ pub(crate) async fn main(opt: Opt, reactor: NeoReactor) -> Result<()> {
|
||||
let mut stream = BroadcastStream::new(stream_data.vid.resubscribe())
|
||||
.filter(|f| futures::future::ready(f.is_ok())); // Filter to ignore lagged
|
||||
let buf = loop {
|
||||
if let Some(Ok(StampedData { data, ts: _ })) = stream.next().await {
|
||||
break data;
|
||||
if let Some(Ok(StampedData {
|
||||
data,
|
||||
ts: _,
|
||||
keyframe,
|
||||
})) = stream.next().await
|
||||
{
|
||||
if keyframe {
|
||||
break data;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+20
-12
@@ -678,13 +678,17 @@ async fn stream_run(
|
||||
_ = thread_stream_cancel.cancelled() => AnyResult::Ok(()),
|
||||
v = async {
|
||||
// Send Initial
|
||||
let mut found_key_frame = false;
|
||||
for data in thread_vid_history.borrow().iter() {
|
||||
thread_vid_data_tx.send(
|
||||
StreamData::Media {
|
||||
data: data.data.clone(),
|
||||
ts: Duration::ZERO,
|
||||
}
|
||||
)?;
|
||||
if data.keyframe || found_key_frame {
|
||||
found_key_frame = true;
|
||||
thread_vid_data_tx.send(
|
||||
StreamData::Media {
|
||||
data: data.data.clone(),
|
||||
ts: Duration::ZERO,
|
||||
}
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
// Send new
|
||||
@@ -716,13 +720,17 @@ async fn stream_run(
|
||||
_ = thread_stream_cancel.cancelled() => AnyResult::Ok(()),
|
||||
v = async {
|
||||
// Send Initial
|
||||
let mut found_key_frame = false;
|
||||
for data in thread_aud_history.borrow().iter() {
|
||||
thread_aud_data_tx.send(
|
||||
StreamData::Media {
|
||||
data: data.data.clone(),
|
||||
ts: Duration::ZERO,
|
||||
}
|
||||
)?;
|
||||
if data.keyframe || found_key_frame {
|
||||
thread_aud_data_tx.send(
|
||||
StreamData::Media {
|
||||
data: data.data.clone(),
|
||||
ts: Duration::ZERO,
|
||||
}
|
||||
)?;
|
||||
found_key_frame = true;
|
||||
}
|
||||
}
|
||||
// Send new
|
||||
while let Some(data) = audstream.next().await {
|
||||
|
||||
Reference in new issue
Block a user