use ll_hls_runtime::client::{Action, LlHlsClient};
use ll_hls_runtime::server::{DEFAULT_TRACK_ID, MediaStore, media_playlist_m3u8};
use transmux::ll_hls::{PartInfo, SegmentInfo};
const PLAYLIST_URL: &str = "http://origin/live/media.m3u8";
fn canned_playlist() -> String {
let store = MediaStore::new(1.0, 500, 4);
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_segment(SegmentInfo {
bytes: vec![0x02; 32],
duration: 1.0,
segment_seq: 1,
part_count: 1,
});
store.add_part(PartInfo {
bytes: vec![0x03; 16],
duration: 0.5,
independent: true,
segment_seq: 2,
part_index: 0,
});
media_playlist_m3u8(&store, DEFAULT_TRACK_ID)
}
fn main() {
let playlist = canned_playlist();
println!("--- canned media.m3u8 ---\n{playlist}");
let mut client = LlHlsClient::new(PLAYLIST_URL);
match client.poll() {
Some(Action::FetchPlaylist {
url,
blocking,
skip,
}) => {
assert_eq!(url, PLAYLIST_URL);
assert!(blocking.is_none());
assert!(!skip);
println!("action: FetchPlaylist {{ url: {url:?}, blocking: None }}");
}
other => panic!("expected the seeded FetchPlaylist, got {other:?}"),
}
client
.on_playlist(playlist.as_bytes())
.expect("the canned playlist parses");
let mut saw_blocking_reload = false;
while let Some(action) = client.poll() {
match &action {
Action::FetchResource { id, url, .. } => {
println!("action: FetchResource {{ id: {id:?}, url: {url:?} }}");
}
Action::FetchPlaylist {
url,
blocking: Some(b),
..
} => {
println!(
"action: FetchPlaylist {{ url: {url:?}, blocking: {b:?} }} <- blocking reload"
);
saw_blocking_reload = true;
}
Action::FetchPlaylist {
url,
blocking: None,
..
} => {
println!("action: FetchPlaylist {{ url: {url:?}, blocking: None }}");
}
Action::WaitMs(ms) => println!("action: WaitMs({ms})"),
_ => {}
}
}
assert!(
saw_blocking_reload,
"this crate's own origin renderer defaults CAN-BLOCK-RELOAD=YES, so the \
next reload the client schedules must be a blocking one"
);
}