mirror of
https://github.com/sile/hls_m3u8.git
synced 2025-01-08 19:25:24 +00:00
automatically infer start of ByteRange
This commit is contained in:
parent
47eccfdef9
commit
9eccea8a7f
2 changed files with 23 additions and 3 deletions
|
@ -8,8 +8,9 @@ use derive_builder::Builder;
|
|||
use crate::line::{Line, Lines, Tag};
|
||||
use crate::media_segment::MediaSegment;
|
||||
use crate::tags::{
|
||||
ExtM3u, ExtXDiscontinuitySequence, ExtXEndList, ExtXIFramesOnly, ExtXIndependentSegments,
|
||||
ExtXKey, ExtXMediaSequence, ExtXStart, ExtXTargetDuration, ExtXVersion,
|
||||
ExtM3u, ExtXByteRange, ExtXDiscontinuitySequence, ExtXEndList, ExtXIFramesOnly,
|
||||
ExtXIndependentSegments, ExtXKey, ExtXMediaSequence, ExtXStart, ExtXTargetDuration,
|
||||
ExtXVersion,
|
||||
};
|
||||
use crate::types::{
|
||||
DecryptionKey, EncryptionMethod, InitializationVector, KeyFormat, PlaylistType, ProtocolVersion,
|
||||
|
@ -295,6 +296,8 @@ impl MediaPlaylistBuilder {
|
|||
}
|
||||
|
||||
let mut position = sequence_number;
|
||||
let mut previous_range: Option<ExtXByteRange> = None;
|
||||
|
||||
for segment in segments
|
||||
.iter()
|
||||
.filter_map(|(_, s)| if s.explicit_number { None } else { Some(s) })
|
||||
|
@ -322,6 +325,22 @@ impl MediaPlaylistBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
// add the lower bound to the byterange automatically
|
||||
if let Some(range) = &mut segment.byte_range {
|
||||
if range.start().is_none() {
|
||||
if let Some(previous_range) = previous_range {
|
||||
// the end of the previous_range is the start of the next range
|
||||
*range = range.saturating_add(previous_range.end());
|
||||
range.set_start(Some(previous_range.end()));
|
||||
} else {
|
||||
// assume that the byte range starts at zero
|
||||
range.set_start(Some(0));
|
||||
}
|
||||
}
|
||||
|
||||
previous_range = segment.byte_range;
|
||||
}
|
||||
|
||||
result_segments.insert(segment.number, segment);
|
||||
position += 1;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ generate_tests! {
|
|||
.unwrap(),
|
||||
MediaSegment::builder()
|
||||
.duration(ExtInf::new(Duration::from_secs_f64(10.0)))
|
||||
// 834433..904297
|
||||
.byte_range(ExtXByteRange::from(..69864))
|
||||
.uri("video.ts")
|
||||
.build()
|
||||
|
@ -64,7 +65,7 @@ generate_tests! {
|
|||
"#EXTINF:10,\n",
|
||||
"video.ts\n",
|
||||
|
||||
"#EXT-X-BYTERANGE:69864\n",
|
||||
"#EXT-X-BYTERANGE:69864@834433\n",
|
||||
"#EXTINF:10,\n",
|
||||
"video.ts\n"
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue