Skip to content

Commit

Permalink
parent f891342
Browse files Browse the repository at this point in the history
author irving ou <[email protected]> 1736528540 -0500
committer irving ou <[email protected]> 1736530356 -0500

fix(dgw): fix streamer failure for RDM
  • Loading branch information
irvingoujAtDevolution committed Jan 10, 2025
1 parent f891342 commit 41b81a7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
8 changes: 5 additions & 3 deletions crates/video-streamer/src/streamer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ pub fn webm_stream(
header_writer.write(header)?;
}

let mut encode_writer = header_writer.into_encoded_writer(encode_writer_config)?;

let (mut encode_writer, cut_block_hit_marker) = header_writer.into_encoded_writer(encode_writer_config)?;
let mut cut_block_hit_marker = Some(cut_block_hit_marker);
// Start muxing from the last key frame.
// The WebM project requires the muxer to ensure the first Block/SimpleBlock is a keyframe.
// However, the WebM file emitted by the CaptureStream API in Chrome does not adhere to this requirement.
Expand Down Expand Up @@ -119,7 +119,9 @@ pub fn webm_stream(
}
Some(Ok(tag)) => {
if webm_itr.last_tag_position() == cut_block_position {
encode_writer.mark_cut_block_hit();
if let Some(cut_block_hit_marker) = cut_block_hit_marker.take() {
encode_writer.mark_cut_block_hit(cut_block_hit_marker);
}
}

match encode_writer.write(tag) {
Expand Down
34 changes: 23 additions & 11 deletions crates/video-streamer/src/streamer/tag_writers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ where
Ok(())
}

pub(crate) fn into_encoded_writer(self, config: EncodeWriterConfig) -> anyhow::Result<CutCusterWriter<T>> {
pub(crate) fn into_encoded_writer(
self,
config: EncodeWriterConfig,
) -> anyhow::Result<(CutCusterWriter<T>, CutBlockHitMarker)> {
let encoded_writer = CutCusterWriter::new(config, self)?;
Ok(encoded_writer)
}
Expand Down Expand Up @@ -94,11 +97,13 @@ where
cut_block_state: CutBlockState,
}

pub(crate) struct CutBlockHitMarker;

impl<T> CutCusterWriter<T>
where
T: std::io::Write,
{
fn new(config: EncodeWriterConfig, writer: HeaderWriter<T>) -> anyhow::Result<Self> {
fn new(config: EncodeWriterConfig, writer: HeaderWriter<T>) -> anyhow::Result<(Self, CutBlockHitMarker)> {
let decoder = VpxDecoder::builder()
.threads(config.threads)
.width(config.width)
Expand All @@ -117,13 +122,16 @@ where
.build()?;

let HeaderWriter { writer } = writer;
Ok(Self {
writer,
cluster_timestamp: None,
encoder,
decoder,
cut_block_state: CutBlockState::HaventMet,
})
Ok((
Self {
writer,
cluster_timestamp: None,
encoder,
decoder,
cut_block_state: CutBlockState::HaventMet,
},
CutBlockHitMarker,
))
}
}

Expand All @@ -137,6 +145,7 @@ where
{
#[instrument(skip(self, tag))]
pub fn write(&mut self, tag: MatroskaSpec) -> anyhow::Result<WriterResult> {
warn!("attempted to write tag: {}", mastroka_spec_name(&tag));
match tag {
MatroskaSpec::Timestamp(timestamp) => {
self.cluster_timestamp = Some(timestamp);
Expand Down Expand Up @@ -203,7 +212,9 @@ where
let current_block_absolute_time = current_video_block.absolute_timestamp()?;
let cluster_relative_timestamp = current_block_absolute_time - cut_block_absolute_time;
if self.should_write_new_cluster(current_block_absolute_time) {
self.start_new_cluster(cluster_relative_timestamp)?;
self.start_new_cluster(cluster_relative_timestamp).inspect_err(|e| {
error!("failed to start new cluster: {}", e);
})?;

self.cut_block_state = CutBlockState::Met {
cut_block_absolute_time,
Expand Down Expand Up @@ -296,7 +307,8 @@ where
false
}

pub(crate) fn mark_cut_block_hit(&mut self) {
pub(crate) fn mark_cut_block_hit(&mut self, _marker: CutBlockHitMarker) {
debug!("marking cut block hit");
self.cut_block_state = CutBlockState::AtCutBlock;
}
}
Expand Down

0 comments on commit 41b81a7

Please sign in to comment.