use ll_hls_runtime::server::{
BlockingQuery, DEFAULT_TRACK_ID, MediaStore, PlaylistOutcome, ResourceOutcome,
master_playlist_m3u8, media_playlist_m3u8,
};
use transmux::ll_hls::{PartInfo, SegmentInfo};
const TARGET_DURATION_SECS: f64 = 1.0;
const PART_TARGET_MS: u32 = 500;
const WINDOW_SEGMENTS: usize = 4;
fn main() {
let store = MediaStore::new(TARGET_DURATION_SECS, PART_TARGET_MS, WINDOW_SEGMENTS);
store.set_init(vec![0xAA; 32]);
store.add_part(PartInfo {
bytes: vec![0x01; 16],
duration: 0.5,
independent: true,
segment_seq: 1,
part_index: 0,
});
store.add_part(PartInfo {
bytes: vec![0x02; 16],
duration: 0.5,
independent: false,
segment_seq: 1,
part_index: 1,
});
store.add_segment(SegmentInfo {
bytes: vec![0x03; 32],
duration: 1.0,
segment_seq: 1,
part_count: 2,
});
store.add_part(PartInfo {
bytes: vec![0x04; 16],
duration: 0.5,
independent: true,
segment_seq: 2,
part_index: 0,
});
println!("--- master.m3u8 ---");
println!("{}", master_playlist_m3u8("media.m3u8"));
println!("--- media.m3u8 ---");
println!("{}", media_playlist_m3u8(&store, DEFAULT_TRACK_ID));
let outcome = store.resolve_playlist(DEFAULT_TRACK_ID, BlockingQuery::default());
assert!(matches!(outcome, PlaylistOutcome::Ready(_)));
println!("resolve_playlist(no query) -> Ready");
let outcome = store.resolve_playlist(
DEFAULT_TRACK_ID,
BlockingQuery {
hls_msn: Some(5),
hls_part: None,
},
);
assert_eq!(outcome, PlaylistOutcome::WouldBlock);
println!("resolve_playlist(_HLS_msn=5) -> WouldBlock");
let outcome = store.resolve_playlist(
DEFAULT_TRACK_ID,
BlockingQuery {
hls_msn: Some(999),
hls_part: None,
},
);
assert_eq!(outcome, PlaylistOutcome::BadRequest);
println!("resolve_playlist(_HLS_msn=999) -> BadRequest (abuse bound)");
match store.resolve_resource("init-1.mp4") {
ResourceOutcome::Ready { .. } => println!("resolve_resource(init-1.mp4) -> Ready"),
other => panic!("expected Ready, got {other:?}"),
}
match store.resolve_resource("seg-1-1.m4s") {
ResourceOutcome::Ready { .. } => println!("resolve_resource(seg-1-1.m4s) -> Ready"),
other => panic!("expected Ready, got {other:?}"),
}
match store.resolve_resource("part-1-2.0.m4s") {
ResourceOutcome::Ready { .. } => println!("resolve_resource(part-1-2.0.m4s) -> Ready"),
other => panic!("expected Ready, got {other:?}"),
}
match store.resolve_resource("part-1-2.1.m4s") {
ResourceOutcome::WouldBlock => println!("resolve_resource(part-1-2.1.m4s) -> WouldBlock"),
other => panic!("expected WouldBlock, got {other:?}"),
}
match store.resolve_resource("nope.txt") {
ResourceOutcome::NotFound => println!("resolve_resource(nope.txt) -> NotFound"),
other => panic!("expected NotFound, got {other:?}"),
}
}