Skip to content

Commit 15d109c

Browse files
committed
feat(iori): add definition for discontinuity
Part of #45
1 parent e3ed7dc commit 15d109c

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

crates/iori/src/hls/segment.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub struct M3u8Segment {
2323
/// Media sequence id from the m3u8 file
2424
pub media_sequence: u64,
2525

26+
pub part_index: u64,
27+
2628
pub duration: f64,
2729
pub format: SegmentFormat,
2830
}
@@ -59,6 +61,10 @@ impl StreamingSegment for M3u8Segment {
5961
fn format(&self) -> SegmentFormat {
6062
self.format.clone()
6163
}
64+
65+
fn part_index(&self) -> u64 {
66+
self.part_index
67+
}
6268
}
6369

6470
impl RemoteStreamingSegment for M3u8Segment {

crates/iori/src/hls/source.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ impl HlsMediaPlaylistSource {
166166
initial_segment: initial_segment.clone(),
167167
sequence: self.sequence.fetch_add(1, Ordering::Relaxed),
168168
media_sequence,
169+
part_index: segment.part_index,
169170
byte_range: segment.byte_range.as_ref().map(|r| crate::ByteRange {
170171
offset: r.offset.unwrap_or(next_range_start),
171172
length: Some(r.length),

crates/iori/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub trait StreamingSource {
5858
) -> impl Future<Output = IoriResult<impl Stream<Item = IoriResult<Vec<Self::Segment>>>>>;
5959
}
6060

61+
/// A segment of a streaming source
6162
pub trait StreamingSegment {
6263
/// Stream id
6364
fn stream_id(&self) -> u64;
@@ -66,8 +67,17 @@ pub trait StreamingSegment {
6667
fn stream_type(&self) -> StreamType;
6768

6869
/// Sequence ID of the segment, starts from 0
70+
///
71+
/// It MUST be contiguous and monotonically increasing for a given stream.
6972
fn sequence(&self) -> u64;
7073

74+
/// Part index of the segment.
75+
///
76+
/// For segments without discontinuities, this defaults to 0.
77+
fn part_index(&self) -> u64 {
78+
0
79+
}
80+
7181
/// File name of the segment
7282
fn file_name(&self) -> &str;
7383

crates/iori/src/merge/pipe.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type SendSegment = (
2222
/// PipeMerger is a merger that pipes the segments directly to the output.
2323
///
2424
/// If there are any missing segments, it will skip them.
25+
/// PipeMerger does not and can not handle discontinuities.
2526
pub struct PipeMerger {
2627
recycle: bool,
2728

crates/iori/src/segment.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub struct SegmentInfo {
7474
pub key: Option<std::sync::Arc<IoriKey>>,
7575
pub duration: Option<f64>,
7676
pub format: SegmentFormat,
77+
pub part_index: u64,
7778
}
7879

7980
impl<T> From<&T> for SegmentInfo
@@ -90,6 +91,7 @@ where
9091
duration: segment.duration(),
9192
stream_type: segment.stream_type(),
9293
format: segment.format(),
94+
part_index: segment.part_index(),
9395
}
9496
}
9597
}
@@ -126,6 +128,10 @@ impl StreamingSegment for Box<dyn StreamingSegment + Send + Sync + '_> {
126128
fn format(&self) -> SegmentFormat {
127129
self.as_ref().format()
128130
}
131+
132+
fn part_index(&self) -> u64 {
133+
self.as_ref().part_index()
134+
}
129135
}
130136

131137
impl StreamingSegment for &Box<dyn StreamingSegment + Send + Sync + '_> {
@@ -160,6 +166,10 @@ impl StreamingSegment for &Box<dyn StreamingSegment + Send + Sync + '_> {
160166
fn format(&self) -> SegmentFormat {
161167
self.as_ref().format()
162168
}
169+
170+
fn part_index(&self) -> u64 {
171+
self.as_ref().part_index()
172+
}
163173
}
164174

165175
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]

0 commit comments

Comments
 (0)