1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-06-18 04:40:33 +00:00

automatically infer start of ByteRange

This commit is contained in:
Luro02 2020-03-29 12:58:32 +02:00
parent 47eccfdef9
commit 9eccea8a7f
No known key found for this signature in database
GPG key ID: B66FD4F74501A9CF
2 changed files with 23 additions and 3 deletions

View file

@ -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;
}

View file

@ -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"
)