| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | use std::time::Instant; |
| 20 | |
| 21 | #[test] |
| 22 | fn the_session_maps_a_pgs_track_onto_the_timeline_and_draws_it() { |
| 23 | |
| 24 | let Some(film) = engine::real_library::film("hevc_4k_pgs") else { |
| 25 | |
| 26 | |
| 27 | |
| 28 | if std::env::var("EC_REQUIRE_FIXTURES").is_ok_and(|v| v == "1") { |
| 29 | panic!("EC_REQUIRE_FIXTURES=1 but the PGS film `hevc_4k_pgs` is not available"); |
| 30 | } |
| 31 | eprintln!("SKIP pgs_bitmaps: no `hevc_4k_pgs` in real_library.toml; this test did not run"); |
| 32 | return; |
| 33 | }; |
| 34 | let film = film.as_path(); |
| 35 | let opened = Instant::now(); |
| 36 | let mut session = engine::PlaybackSession::open(film).expect("the film opens"); |
| 37 | session.set_gain(0.0); |
| 38 | let rows = session |
| 39 | .import_subtitles(film) |
| 40 | .expect("the film's own subtitle tracks"); |
| 41 | eprintln!("{rows} rows in {:?}", opened.elapsed()); |
| 42 | let pick = session |
| 43 | .subtitles() |
| 44 | .iter() |
| 45 | .position(|t| t.is_bitmap()) |
| 46 | .expect("a bitmap row to pick"); |
| 47 | assert_eq!( |
| 48 | session.subtitles()[pick].refused, None, |
| 49 | "a row a click can pick" |
| 50 | ); |
| 51 | |
| 52 | let mapped = Instant::now(); |
| 53 | let cues = session.timeline_cues(pick); |
| 54 | eprintln!("{} cues mapped in {:?}", cues.len(), mapped.elapsed()); |
| 55 | assert!(!cues.is_empty(), "no cue of this track lands on the timeline"); |
| 56 | |
| 57 | |
| 58 | let warm = Instant::now(); |
| 59 | let again = session.timeline_cues(pick); |
| 60 | let warm = warm.elapsed(); |
| 61 | eprintln!("mapped again in {warm:?}"); |
| 62 | assert_eq!(again, cues, "the same map, twice"); |
| 63 | assert!(warm.as_millis() < 16, "a repaint's worth of map: {warm:?}"); |
| 64 | |
| 65 | |
| 66 | |
| 67 | for pair in cues.windows(2) { |
| 68 | assert!(pair[0].end_us > pair[0].start_us, "{:?}", pair[0]); |
| 69 | assert!(pair[1].start_us >= pair[0].start_us, "{pair:?}"); |
| 70 | } |
| 71 | |
| 72 | |
| 73 | let drawn = Instant::now(); |
| 74 | let image = cues[0].image.as_ref().expect("a picture cue"); |
| 75 | let rgba = image.rgba().expect("the first display set decodes"); |
| 76 | let took = drawn.elapsed(); |
| 77 | eprintln!( |
| 78 | "cue 0 decoded to {}x{} in {took:?}", |
| 79 | image.width, image.height, |
| 80 | ); |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | assert!(took.as_millis() < 16, "a frame's worth of decode: {took:?}"); |
| 87 | assert_eq!(rgba.len(), (image.width * image.height * 4) as usize); |
| 88 | let opaque = rgba.as_chunks::<4>().0.iter().filter(|px| px[3] > 0).count(); |
| 89 | assert!(opaque > 0, "the block decoded to an empty canvas"); |
| 90 | assert!( |
| 91 | opaque < (image.width * image.height) as usize, |
| 92 | "a subtitle that covers the whole frame is not a subtitle" |
| 93 | ); |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | let lane = session.add_lane(engine::project::LaneKind::Subtitle); |
| 102 | session |
| 103 | .place_sub( |
| 104 | lane, |
| 105 | 0, |
| 106 | engine::project::SubClip { |
| 107 | start: 0, |
| 108 | frames: 60, |
| 109 | track: pick, |
| 110 | in_us: cues[0].start_us, |
| 111 | out_us: cues[0].end_us, |
| 112 | link: None, |
| 113 | }, |
| 114 | ) |
| 115 | .expect("the lane is empty, so the placement lands"); |
| 116 | assert_eq!( |
| 117 | session.planned_subtitles(engine::export::Format::Hevc, []), |
| 118 | format!( |
| 119 | "S1 {} — pictures; drawn, not written", |
| 120 | session.subtitles()[pick].label |
| 121 | ), |
| 122 | "a real PGS row on a lane says why it cannot travel" |
| 123 | ); |
| 124 | |
| 125 | |
| 126 | |
| 127 | let text = session |
| 128 | .subtitles() |
| 129 | .iter() |
| 130 | .position(|t| !t.is_bitmap() && t.refused.is_none()) |
| 131 | .expect("the film's text track"); |
| 132 | let words = session.timeline_cues(text); |
| 133 | assert!(!words.is_empty()); |
| 134 | assert!(words.iter().all(|c| c.image.is_none())); |
| 135 | } |