hlssink3/hlscmafsink: Add test for validating non-overlapping byte range

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/2439>
This commit is contained in:
Sanchayan Maity 2025-08-13 21:11:22 +05:30
parent a8684853d0
commit 917e1f5885
3 changed files with 29 additions and 1 deletions

View file

@ -12,6 +12,12 @@ pub struct ByteRange {
offset: u64,
}
impl ByteRange {
fn end(&self) -> u64 {
self.offset + self.length
}
}
pub fn get_byte_ranges(s: &gst::StructureRef) -> Vec<ByteRange> {
let mut ranges = Vec::new();
@ -43,3 +49,23 @@ pub fn validate_byterange_sequence(ranges: &[ByteRange]) -> bool {
next.offset == current.offset + current.length
})
}
fn ranges_overlap(a: &ByteRange, b: &ByteRange) -> bool {
a.offset < b.end() && b.offset < a.end()
}
pub fn all_ranges_non_overlapping(ranges: &[ByteRange]) -> bool {
if ranges.len() <= 1 {
return true; // 0 or 1 range cannot overlap
}
for i in 0..ranges.len() {
for j in (i + 1)..ranges.len() {
if ranges_overlap(&ranges[i], &ranges[j]) {
return false;
}
}
}
true
}

View file

@ -205,6 +205,7 @@ fn test_hlscmafsink_video_with_single_media_file() -> Result<(), ()> {
// byte range can differ from each run and hence we do not validate
// the entire playlist.
assert!(validate_byterange_sequence(&byte_ranges));
assert!(all_ranges_non_overlapping(&byte_ranges));
let expected_messages = {
use self::HlsSinkEvent::*;

View file

@ -14,7 +14,7 @@ use std::sync::LazyLock;
use std::sync::{mpsc, Arc, Mutex};
mod common;
use crate::common::{get_byte_ranges, validate_byterange_sequence, ByteRange};
use crate::common::*;
static CAT: LazyLock<gst::DebugCategory> = LazyLock::new(|| {
gst::DebugCategory::new(
@ -657,6 +657,7 @@ fn test_hlssink3_video_with_single_media_file() -> Result<(), ()> {
// range can differ from each run and hence we do not validate
// the entire playlist.
assert!(validate_byterange_sequence(&byte_ranges));
assert!(all_ranges_non_overlapping(&byte_ranges));
let expected_messages = {
use self::HlsSinkEvent::*;