Skip to content

Commit

Permalink
fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
Curid committed Mar 6, 2024
1 parent e1c7418 commit 4e3f5da
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
43 changes: 40 additions & 3 deletions examples/client/src/mp4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct TrakTracker {
}

impl TrakTracker {
fn add_sample(
fn add_audio_sample(
&mut self,
sample_description_index: u32,
byte_pos: u32,
Expand Down Expand Up @@ -178,6 +178,43 @@ impl TrakTracker {
Ok(())
}

fn add_video_sample(
&mut self,
sample_description_index: u32,
byte_pos: u32,
size: u32,
timestamp: retina::VideoTimestamp,
loss: u16,
allow_loss: bool,
) -> Result<(), Error> {
if self.samples > 0 && loss > 0 && !allow_loss {
bail!("Lost {} RTP packets mid-stream", loss);
}
self.samples += 1;
if self.next_pos != Some(byte_pos)
|| self.chunks.last().map(|c| c.sample_description_index)
!= Some(sample_description_index)
{
self.chunks.push(Chunk {
first_sample_number: self.samples,
byte_pos,
sample_description_index,
});
}
self.sizes.push(size);
self.next_pos = Some(byte_pos + size);
if let Some(last_pts) = self.last_pts.replace(timestamp.pts()) {
let duration = timestamp.pts().checked_sub(last_pts).unwrap();
self.tot_duration += u64::try_from(duration).unwrap();
let duration = u32::try_from(duration)?;
match self.durations.last_mut() {
Some((s, d)) if *d == duration => *s += 1,
_ => self.durations.push((1, duration)),
}
}
Ok(())
}

fn finish(&mut self) {
if self.last_pts.is_some() {
self.durations.push((1, 0));
Expand Down Expand Up @@ -571,7 +608,7 @@ impl<W: AsyncWrite + AsyncSeek + Send + Unpin> Mp4Writer<W> {
};
self.cur_video_params_sample_description_index = Some(sample_description_index);
let size = u32::try_from(frame.data().remaining())?;
self.video_trak.add_sample(
self.video_trak.add_video_sample(
sample_description_index,
self.mdat_pos,
size,
Expand All @@ -597,7 +634,7 @@ impl<W: AsyncWrite + AsyncSeek + Send + Unpin> Mp4Writer<W> {
frame.data().remaining()
);
let size = u32::try_from(frame.data().remaining())?;
self.audio_trak.add_sample(
self.audio_trak.add_audio_sample(
/* sample_description_index */ 1,
self.mdat_pos,
size,
Expand Down
7 changes: 5 additions & 2 deletions src/codec/h264/dts_extractor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (C) 2021 Scott Lamb <[email protected]>
// SPDX-License-Identifier: MIT OR Apache-2.0

// https://github.com/bluenviron/gortsplib/blob/f0540b4eee760583b2d94f022674b0f3b0f8c8b0/pkg/codecs/h264/dts_extractor.go

use h264_reader::{
Expand Down Expand Up @@ -271,8 +274,8 @@ fn get_picture_order_count(
// return 0, fmt.Errorf("frame_mbs_only_flag = 0 is not supported")
//}
let FrameMbsFlags::Frames = frame_mbs_flags else {
return Err(DtsExtractorError::FrameMbsNotSupported);
};
return Err(DtsExtractorError::FrameMbsNotSupported);
};

let pic_order_cnt_lsb: u32 = r
.read_u32(
Expand Down

0 comments on commit 4e3f5da

Please sign in to comment.