mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-09-02 01:33:47 +00:00
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:
parent
a8684853d0
commit
917e1f5885
3 changed files with 29 additions and 1 deletions
|
@ -12,6 +12,12 @@ pub struct ByteRange {
|
||||||
offset: u64,
|
offset: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ByteRange {
|
||||||
|
fn end(&self) -> u64 {
|
||||||
|
self.offset + self.length
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_byte_ranges(s: &gst::StructureRef) -> Vec<ByteRange> {
|
pub fn get_byte_ranges(s: &gst::StructureRef) -> Vec<ByteRange> {
|
||||||
let mut ranges = Vec::new();
|
let mut ranges = Vec::new();
|
||||||
|
|
||||||
|
@ -43,3 +49,23 @@ pub fn validate_byterange_sequence(ranges: &[ByteRange]) -> bool {
|
||||||
next.offset == current.offset + current.length
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
// byte range can differ from each run and hence we do not validate
|
||||||
// the entire playlist.
|
// the entire playlist.
|
||||||
assert!(validate_byterange_sequence(&byte_ranges));
|
assert!(validate_byterange_sequence(&byte_ranges));
|
||||||
|
assert!(all_ranges_non_overlapping(&byte_ranges));
|
||||||
|
|
||||||
let expected_messages = {
|
let expected_messages = {
|
||||||
use self::HlsSinkEvent::*;
|
use self::HlsSinkEvent::*;
|
||||||
|
|
|
@ -14,7 +14,7 @@ use std::sync::LazyLock;
|
||||||
use std::sync::{mpsc, Arc, Mutex};
|
use std::sync::{mpsc, Arc, Mutex};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
use crate::common::{get_byte_ranges, validate_byterange_sequence, ByteRange};
|
use crate::common::*;
|
||||||
|
|
||||||
static CAT: LazyLock<gst::DebugCategory> = LazyLock::new(|| {
|
static CAT: LazyLock<gst::DebugCategory> = LazyLock::new(|| {
|
||||||
gst::DebugCategory::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
|
// range can differ from each run and hence we do not validate
|
||||||
// the entire playlist.
|
// the entire playlist.
|
||||||
assert!(validate_byterange_sequence(&byte_ranges));
|
assert!(validate_byterange_sequence(&byte_ranges));
|
||||||
|
assert!(all_ranges_non_overlapping(&byte_ranges));
|
||||||
|
|
||||||
let expected_messages = {
|
let expected_messages = {
|
||||||
use self::HlsSinkEvent::*;
|
use self::HlsSinkEvent::*;
|
||||||
|
|
Loading…
Reference in a new issue