Merge branch 'worktree-agent-a60c9f67098825772'
Browse files at this commit7 changed files +183 -57
- crates/engine-hw/src/lib.rs +41 -3
- crates/engine/src/caps.rs +2 -1
- crates/engine/src/export.rs +29 -3
- crates/engine/src/hw.rs +31 -3
- crates/engine/tests/backends.rs +50 -44
- vendor/cros-codecs/src/encoder/h265.rs +15 -0
- vendor/cros-codecs/src/encoder/stateless/h265/predictor.rs +15 -3
crates/engine-hw/src/lib.rsmodified+41 -3
| @@ -30,6 +30,7 @@ use cros_codecs::decoder::stateless::{DecodeError, StatelessDecoder, StatelessVi | |||
| 30 | use cros_codecs::decoder::{BlockingMode, DecodedHandle, DecoderEvent, StreamInfo}; | 30 | use cros_codecs::decoder::{BlockingMode, DecodedHandle, DecoderEvent, StreamInfo}; |
| 31 | use cros_codecs::encoder::av1::EncoderConfig as Av1Config; | 31 | use cros_codecs::encoder::av1::EncoderConfig as Av1Config; |
| 32 | use cros_codecs::encoder::h264::EncoderConfig as H264Config; | 32 | use cros_codecs::encoder::h264::EncoderConfig as H264Config; |
| 33 | +use cros_codecs::encoder::h265::ColourDescription as H265Colour; | ||
| 33 | use cros_codecs::encoder::h265::EncoderConfig as H265Config; | 34 | use cros_codecs::encoder::h265::EncoderConfig as H265Config; |
| 34 | use cros_codecs::encoder::stateless::av1::StatelessEncoder as Av1StatelessEncoder; | 35 | use cros_codecs::encoder::stateless::av1::StatelessEncoder as Av1StatelessEncoder; |
| 35 | use cros_codecs::encoder::stateless::h264::StatelessEncoder; | 36 | use cros_codecs::encoder::stateless::h264::StatelessEncoder; |
| @@ -1154,7 +1155,7 @@ impl EncSession { | |||
| 1154 | bitrate: u64, | 1155 | bitrate: u64, |
| 1155 | codec: EncCodec, | 1156 | codec: EncCodec, |
| 1156 | ) -> Option<Self> { | 1157 | ) -> Option<Self> { |
| 1157 | - Self::open_seat(width, height, fps_num, fps_den, bitrate, codec, false) | 1158 | + Self::open_seat(width, height, fps_num, fps_den, bitrate, codec, false, None) |
| 1158 | } | 1159 | } |
| 1159 | 1160 | ||
| 1160 | #[allow(clippy::too_many_arguments)] | 1161 | #[allow(clippy::too_many_arguments)] |
| @@ -1166,6 +1167,7 @@ impl EncSession { | |||
| 1166 | bitrate: u64, | 1167 | bitrate: u64, |
| 1167 | codec: EncCodec, | 1168 | codec: EncCodec, |
| 1168 | intra_only: bool, | 1169 | intra_only: bool, |
| 1170 | + colour: Option<H265Colour>, | ||
| 1169 | ) -> Option<Self> { | 1171 | ) -> Option<Self> { |
| 1170 | // NV12 chroma is half resolution, so odd dimensions have no packing; | 1172 | // NV12 chroma is half resolution, so odd dimensions have no packing; |
| 1171 | // and radeonsi refuses encode contexts below 64x64 (measured). | 1173 | // and radeonsi refuses encode contexts below 64x64 (measured). |
| @@ -1295,6 +1297,14 @@ impl EncSession { | |||
| 1295 | framerate, | 1297 | framerate, |
| 1296 | ..Default::default() | 1298 | ..Default::default() |
| 1297 | }, | 1299 | }, |
| 1300 | + // What the SPS tells a decoder the samples mean. Without it | ||
| 1301 | + // libavcodec reads this stream's colour as "unspecified" and | ||
| 1302 | + // renders it BT.601 whatever the container says -- the HEVC | ||
| 1303 | + // decoder takes the bitstream's answer and overwrites the | ||
| 1304 | + // container's with it, so an untagged 709 export is a | ||
| 1305 | + // visible shift (`engine::export::video_signal_type` writes | ||
| 1306 | + // the same three code points on the software seat). | ||
| 1307 | + colour, | ||
| 1298 | }; | 1308 | }; |
| 1299 | Box::new( | 1309 | Box::new( |
| 1300 | HevcEncoder::new_vaapi( | 1310 | HevcEncoder::new_vaapi( |
| @@ -1625,6 +1635,7 @@ pub extern "C" fn vh_enc_open_intra( | |||
| 1625 | bitrate, | 1635 | bitrate, |
| 1626 | EncCodec::H264, | 1636 | EncCodec::H264, |
| 1627 | true, | 1637 | true, |
| 1638 | + None, | ||
| 1628 | ) { | 1639 | ) { |
| 1629 | Some(session) => Box::into_raw(Box::new(session)) as *mut c_void, | 1640 | Some(session) => Box::into_raw(Box::new(session)) as *mut c_void, |
| 1630 | None => std::ptr::null_mut(), | 1641 | None => std::ptr::null_mut(), |
| @@ -1672,16 +1683,43 @@ pub extern "C" fn vh_enc_av1_open( | |||
| 1672 | /// The session it returns is fed, drained and closed through `vh_enc_frame`, | 1683 | /// The session it returns is fed, drained and closed through `vh_enc_frame`, |
| 1673 | /// `vh_enc_drain` and `vh_enc_close` exactly as an H.264 one is; what comes back | 1684 | /// `vh_enc_drain` and `vh_enc_close` exactly as an H.264 one is; what comes back |
| 1674 | /// out of them is Annex-B HEVC access units. | 1685 | /// out of them is Annex-B HEVC access units. |
| 1686 | +/// | ||
| 1687 | +/// The last four arguments are what the SPS says the samples mean -- the three | ||
| 1688 | +/// H.273 code points and the range flag -- and they are part of the *symbol* | ||
| 1689 | +/// rather than a later setter because the parameter sets are built when the | ||
| 1690 | +/// sequence starts. A seat that signalled nothing is read back as "unspecified" | ||
| 1691 | +/// and rendered BT.601, the container's own tag notwithstanding, which is why | ||
| 1692 | +/// this replaced the colourless `vh_enc_hevc_open`: an engine older than this | ||
| 1693 | +/// symbol finds none and takes the software intra seat, which has always | ||
| 1694 | +/// written the VUI. | ||
| 1675 | #[unsafe(no_mangle)] | 1695 | #[unsafe(no_mangle)] |
| 1676 | -pub extern "C" fn vh_enc_hevc_open( | 1696 | +pub extern "C" fn vh_enc_hevc_open_colour( |
| 1677 | width: u32, | 1697 | width: u32, |
| 1678 | height: u32, | 1698 | height: u32, |
| 1679 | fps_num: u32, | 1699 | fps_num: u32, |
| 1680 | fps_den: u32, | 1700 | fps_den: u32, |
| 1681 | bitrate: u64, | 1701 | bitrate: u64, |
| 1702 | + colour_primaries: u32, | ||
| 1703 | + transfer_characteristics: u32, | ||
| 1704 | + matrix_coeffs: u32, | ||
| 1705 | + full_range: i32, | ||
| 1682 | ) -> *mut c_void { | 1706 | ) -> *mut c_void { |
| 1683 | catch_unwind(AssertUnwindSafe(|| { | 1707 | catch_unwind(AssertUnwindSafe(|| { |
| 1684 | - match EncSession::open_codec(width, height, fps_num, fps_den, bitrate, EncCodec::Hevc) { | 1708 | + match EncSession::open_seat( |
| 1709 | + width, | ||
| 1710 | + height, | ||
| 1711 | + fps_num, | ||
| 1712 | + fps_den, | ||
| 1713 | + bitrate, | ||
| 1714 | + EncCodec::Hevc, | ||
| 1715 | + false, | ||
| 1716 | + Some(H265Colour { | ||
| 1717 | + colour_primaries, | ||
| 1718 | + transfer_characteristics, | ||
| 1719 | + matrix_coeffs, | ||
| 1720 | + full_range: full_range != 0, | ||
| 1721 | + }), | ||
| 1722 | + ) { | ||
| 1685 | Some(session) => Box::into_raw(Box::new(session)) as *mut c_void, | 1723 | Some(session) => Box::into_raw(Box::new(session)) as *mut c_void, |
| 1686 | None => std::ptr::null_mut(), | 1724 | None => std::ptr::null_mut(), |
| 1687 | } | 1725 | } |
crates/engine/src/caps.rsmodified+2 -1
| @@ -106,7 +106,8 @@ mod tests { | |||
| 106 | assert!(hw_line(Some(VhCaps::default())).starts_with("none —")); | 106 | assert!(hw_line(Some(VhCaps::default())).starts_with("none —")); |
| 107 | // This project's own GPU as `vainfo` lists it: H.264, HEVC and AV1 both | 107 | // This project's own GPU as `vainfo` lists it: H.264, HEVC and AV1 both |
| 108 | // ways, VP9 decode only, and the 10-bit profiles on three of the four. | 108 | // ways, VP9 decode only, and the 10-bit profiles on three of the four. |
| 109 | - // HEVC is an encode seat here as of the plugin's `vh_enc_hevc_open` -- | 109 | + // HEVC is an encode seat here as of the plugin's |
| 110 | + // `vh_enc_hevc_open_colour` -- | ||
| 110 | // the 10-bit note beside it stays a *decode* claim, that seat coding | 111 | // the 10-bit note beside it stays a *decode* claim, that seat coding |
| 111 | // 8-bit Main whatever the source was. | 112 | // 8-bit Main whatever the source was. |
| 112 | let radeonsi = VhCaps { | 113 | let radeonsi = VhCaps { |
crates/engine/src/export.rsmodified+29 -3
| @@ -549,9 +549,18 @@ fn hw_seat(meta: &VideoMeta, settings: &ExportSettings) -> Option<HwEncoder> { | |||
| 549 | // (`hevc_export::a_1080p_hardware_export_leaves_a_decoder_with_nothing_to_say`). | 549 | // (`hevc_export::a_1080p_hardware_export_leaves_a_decoder_with_nothing_to_say`). |
| 550 | // `None` here is the plugin's own "no" -- no entrypoint, or a picture | 550 | // `None` here is the plugin's own "no" -- no entrypoint, or a picture |
| 551 | // under the driver's 384x384 floor -- and the software seat takes it. | 551 | // under the driver's 384x384 floor -- and the software seat takes it. |
| 552 | - format if format.is_hevc() => { | 552 | + // The colour goes in at the open, from the same [`ColorDescription::output`] |
| 553 | - HwEncoder::open_hevc(meta.width, meta.height, fps_num, fps_den, bitrate) | 553 | + // rule the software seat's VUI and both containers' tags come from, so |
| 554 | - } | 554 | + // the file cannot say one thing in its bitstream and another in its |
| 555 | + // header. | ||
| 556 | + format if format.is_hevc() => HwEncoder::open_hevc( | ||
| 557 | + meta.width, | ||
| 558 | + meta.height, | ||
| 559 | + fps_num, | ||
| 560 | + fps_den, | ||
| 561 | + bitrate, | ||
| 562 | + ColorDescription::output(meta.height), | ||
| 563 | + ), | ||
| 555 | // Opt-in only, for the reason [`Enc::open_av1`] states in full. Both | 564 | // Opt-in only, for the reason [`Enc::open_av1`] states in full. Both |
| 556 | // AV1 formats sit on it: the container is not the encoder's business. | 565 | // AV1 formats sit on it: the container is not the encoder's business. |
| 557 | format if format.is_av1() && !forced("VE_HW_AV1") => None, | 566 | format if format.is_av1() && !forced("VE_HW_AV1") => None, |
| @@ -2212,6 +2221,23 @@ fn run( | |||
| 2212 | "export audio: waited for after {:.1} s of picture", | 2221 | "export audio: waited for after {:.1} s of picture", |
| 2213 | picture_started.elapsed().as_secs_f64() | 2222 | picture_started.elapsed().as_secs_f64() |
| 2214 | ); | 2223 | ); |
| 2224 | + // ...and the line on screen finished with it. The loop above | ||
| 2225 | + // publishes the measured codec the moment the pass lands | ||
| 2226 | + // under the picture, but a picture that outran the mix never | ||
| 2227 | + // reaches that branch -- and "working out the sound…" would | ||
| 2228 | + // then be the last thing the card ever said about a track it | ||
| 2229 | + // had long since written. | ||
| 2230 | + publish_seats( | ||
| 2231 | + shared, | ||
| 2232 | + seat, | ||
| 2233 | + project, | ||
| 2234 | + settings, | ||
| 2235 | + track.as_ref().map(|track| track.copied), | ||
| 2236 | + track | ||
| 2237 | + .as_ref() | ||
| 2238 | + .is_some_and(|track| track.opus_pre_skip.is_some()), | ||
| 2239 | + false, | ||
| 2240 | + ); | ||
| 2215 | track | 2241 | track |
| 2216 | } | 2242 | } |
| 2217 | None => late, | 2243 | None => late, |
crates/engine/src/hw.rsmodified+31 -3
| @@ -22,6 +22,8 @@ use std::sync::OnceLock; | |||
| 22 | 22 | ||
| 23 | use libloading::Library; | 23 | use libloading::Library; |
| 24 | 24 | ||
| 25 | +use crate::colorspace::ColorDescription; | ||
| 26 | + | ||
| 25 | const LIB_NAME: &str = "libengine_hw.so"; | 27 | const LIB_NAME: &str = "libengine_hw.so"; |
| 26 | 28 | ||
| 27 | /// Stream metadata, C layout. Mirrors [`crate::VideoMeta`]. | 29 | /// Stream metadata, C layout. Mirrors [`crate::VideoMeta`]. |
| @@ -443,7 +445,11 @@ struct EncPlugin { | |||
| 443 | open_av1: Option<extern "C" fn(u32, u32, u32, u32, u64) -> *mut c_void>, | 445 | open_av1: Option<extern "C" fn(u32, u32, u32, u32, u64) -> *mut c_void>, |
| 444 | /// The HEVC seat, missing from an older plugin for the same reason and at | 446 | /// The HEVC seat, missing from an older plugin for the same reason and at |
| 445 | /// the same cost: an HEVC export then runs on the software intra encoder. | 447 | /// the same cost: an HEVC export then runs on the software intra encoder. |
| 446 | - open_hevc: Option<extern "C" fn(u32, u32, u32, u32, u64) -> *mut c_void>, | 448 | + /// Four arguments more than the others: what the SPS says the samples mean |
| 449 | + /// ([`HwEncoder::open_hevc`]), which is why the symbol is named apart from | ||
| 450 | + /// the colourless `vh_enc_hevc_open` it replaced rather than sharing its | ||
| 451 | + /// name with another signature. | ||
| 452 | + open_hevc: Option<extern "C" fn(u32, u32, u32, u32, u64, u32, u32, u32, i32) -> *mut c_void>, | ||
| 447 | /// The **intra-only** H.264 seat, missing from an older plugin for the same | 453 | /// The **intra-only** H.264 seat, missing from an older plugin for the same |
| 448 | /// reason and at the same cost: a proxy then runs on the software encoder, | 454 | /// reason and at the same cost: a proxy then runs on the software encoder, |
| 449 | /// which codes one frame a GOP and so writes the same kind of file. | 455 | /// which codes one frame a GOP and so writes the same kind of file. |
| @@ -480,7 +486,7 @@ fn load_enc() -> Option<EncPlugin> { | |||
| 480 | Some(EncPlugin { | 486 | Some(EncPlugin { |
| 481 | open: *lib.get(b"vh_enc_open\0").ok()?, | 487 | open: *lib.get(b"vh_enc_open\0").ok()?, |
| 482 | open_av1: lib.get(b"vh_enc_av1_open\0").ok().map(|s| *s), | 488 | open_av1: lib.get(b"vh_enc_av1_open\0").ok().map(|s| *s), |
| 483 | - open_hevc: lib.get(b"vh_enc_hevc_open\0").ok().map(|s| *s), | 489 | + open_hevc: lib.get(b"vh_enc_hevc_open_colour\0").ok().map(|s| *s), |
| 484 | open_intra: lib.get(b"vh_enc_open_intra\0").ok().map(|s| *s), | 490 | open_intra: lib.get(b"vh_enc_open_intra\0").ok().map(|s| *s), |
| 485 | frame: *lib.get(b"vh_enc_frame\0").ok()?, | 491 | frame: *lib.get(b"vh_enc_frame\0").ok()?, |
| 486 | dma_geometry: lib.get(b"vh_enc_dma_geometry\0").ok().map(|s| *s), | 492 | dma_geometry: lib.get(b"vh_enc_dma_geometry\0").ok().map(|s| *s), |
| @@ -575,16 +581,38 @@ impl HwEncoder { | |||
| 575 | /// too old to export the symbol, on a GPU with no HEVC encode entrypoint, | 581 | /// too old to export the symbol, on a GPU with no HEVC encode entrypoint, |
| 576 | /// and below 384x384 -- the driver's own floor, stated in the plugin. The | 582 | /// and below 384x384 -- the driver's own floor, stated in the plugin. The |
| 577 | /// caller then takes the software intra encoder without a word about it. | 583 | /// caller then takes the software intra encoder without a word about it. |
| 584 | + /// | ||
| 585 | + /// `colour` is what the SPS will say the samples mean, and it is taken at | ||
| 586 | + /// the open because the parameter sets are written when the sequence starts. | ||
| 587 | + /// libavcodec's HEVC decoder overwrites a container's colour with the | ||
| 588 | + /// bitstream's, so a seat that signalled nothing hands a player | ||
| 589 | + /// "unspecified" -- BT.601 -- however the file is tagged. | ||
| 578 | pub fn open_hevc( | 590 | pub fn open_hevc( |
| 579 | width: u32, | 591 | width: u32, |
| 580 | height: u32, | 592 | height: u32, |
| 581 | fps_num: u32, | 593 | fps_num: u32, |
| 582 | fps_den: u32, | 594 | fps_den: u32, |
| 583 | bitrate: u64, | 595 | bitrate: u64, |
| 596 | + colour: ColorDescription, | ||
| 584 | ) -> Option<Self> { | 597 | ) -> Option<Self> { |
| 585 | let plugin = enc_plugin()?; | 598 | let plugin = enc_plugin()?; |
| 586 | let open = plugin.open_hevc?; | 599 | let open = plugin.open_hevc?; |
| 587 | - Self::opened(plugin, open, width, height, fps_num, fps_den, bitrate) | 600 | + let (primaries, transfer, matrix) = colour.codes(); |
| 601 | + let handle = open( | ||
| 602 | + width, | ||
| 603 | + height, | ||
| 604 | + fps_num, | ||
| 605 | + fps_den, | ||
| 606 | + bitrate, | ||
| 607 | + u32::from(primaries), | ||
| 608 | + u32::from(transfer), | ||
| 609 | + u32::from(matrix), | ||
| 610 | + i32::from(colour.full_range), | ||
| 611 | + ); | ||
| 612 | + if handle.is_null() { | ||
| 613 | + return None; | ||
| 614 | + } | ||
| 615 | + Some(Self { plugin, handle }) | ||
| 588 | } | 616 | } |
| 589 | 617 | ||
| 590 | /// The null check both opens share, which is the plugin's whole way of | 618 | /// The null check both opens share, which is the plugin's whole way of |
crates/engine/tests/backends.rsmodified+50 -44
| @@ -123,22 +123,7 @@ fn the_planned_encoders_are_the_ones_the_job_opens() { | |||
| 123 | ); | 123 | ); |
| 124 | let out = out_path("planned", ext); | 124 | let out = out_path("planned", ext); |
| 125 | let handle = session.export_to_with(&out, &settings); | 125 | let handle = session.export_to_with(&out, &settings); |
| 126 | - let started = Instant::now(); | 126 | + let opened = published_encoders(&handle, ext); |
| 127 | - let opened = loop { | ||
| 128 | - if let Some(line) = handle.encoders() { | ||
| 129 | - break line; | ||
| 130 | - } | ||
| 131 | - assert!( | ||
| 132 | - !handle.is_finished(), | ||
| 133 | - "the export settled before it opened an encoder: {:?}", | ||
| 134 | - handle.result().map(|r| r.err()) | ||
| 135 | - ); | ||
| 136 | - assert!( | ||
| 137 | - started.elapsed() < Duration::from_secs(60), | ||
| 138 | - "no encoder was published" | ||
| 139 | - ); | ||
| 140 | - std::thread::sleep(Duration::from_millis(10)); | ||
| 141 | - }; | ||
| 142 | // Nothing here wants the file, only the seat it was going to be written | 127 | // Nothing here wants the file, only the seat it was going to be written |
| 143 | // with: cancelling deletes the `.part` the worker had started. | 128 | // with: cancelling deletes the `.part` the worker had started. |
| 144 | handle.cancel(); | 129 | handle.cancel(); |
| @@ -201,22 +186,7 @@ fn the_planned_seat_follows_the_size_and_the_pin() { | |||
| 201 | } | 186 | } |
| 202 | let out = out_path("seat", ext); | 187 | let out = out_path("seat", ext); |
| 203 | let handle = session.export_to_with(&out, &settings); | 188 | let handle = session.export_to_with(&out, &settings); |
| 204 | - let started = Instant::now(); | 189 | + let opened = published_encoders(&handle, &format!("{ext} {width}x{height}")); |
| 205 | - let opened = loop { | ||
| 206 | - if let Some(line) = handle.encoders() { | ||
| 207 | - break line; | ||
| 208 | - } | ||
| 209 | - assert!( | ||
| 210 | - !handle.is_finished(), | ||
| 211 | - "{ext} {width}x{height}: settled before an encoder opened: {:?}", | ||
| 212 | - handle.result().map(|r| r.err()) | ||
| 213 | - ); | ||
| 214 | - assert!( | ||
| 215 | - started.elapsed() < Duration::from_secs(60), | ||
| 216 | - "no encoder was published" | ||
| 217 | - ); | ||
| 218 | - std::thread::sleep(Duration::from_millis(10)); | ||
| 219 | - }; | ||
| 220 | handle.cancel(); | 190 | handle.cancel(); |
| 221 | wind_down(&handle); | 191 | wind_down(&handle); |
| 222 | assert!( | 192 | assert!( |
| @@ -313,28 +283,64 @@ fn a_mixed_timeline_says_it_re_encodes_and_then_does() { | |||
| 313 | ..ExportSettings::default() | 283 | ..ExportSettings::default() |
| 314 | }, | 284 | }, |
| 315 | ); | 285 | ); |
| 286 | + let opened = published_encoders(&handle, "a mixed timeline"); | ||
| 287 | + assert!( | ||
| 288 | + opened.ends_with(&planned), | ||
| 289 | + "{opened} does not end in {planned}" | ||
| 290 | + ); | ||
| 291 | + // ...and it is the line the job *settles* on, which is why this one runs to | ||
| 292 | + // the end instead of cancelling: an mp4 mixes its sound beside the picture, | ||
| 293 | + // and a hardware picture is through first, so the measured codec reaches the | ||
| 294 | + // line where the pass is collected under the muxer rather than in the frame | ||
| 295 | + // loop. A card left saying "working out the sound…" over a written file is | ||
| 296 | + // the same lie as one naming a codec that never ran. | ||
| 316 | let started = Instant::now(); | 297 | let started = Instant::now(); |
| 317 | - let opened = loop { | 298 | + while !handle.is_finished() { |
| 318 | - if let Some(line) = handle.encoders() { | 299 | + assert!( |
| 319 | - break line; | 300 | + started.elapsed() < Duration::from_secs(300), |
| 301 | + "the export did not finish in 300 s" | ||
| 302 | + ); | ||
| 303 | + std::thread::sleep(Duration::from_millis(10)); | ||
| 304 | + } | ||
| 305 | + handle.result().expect("an outcome").expect("the export"); | ||
| 306 | + let settled = handle.encoders().expect("a finished job still names its seats"); | ||
| 307 | + assert!( | ||
| 308 | + settled.ends_with(&planned), | ||
| 309 | + "the export settled on {settled}, which does not end in {planned}" | ||
| 310 | + ); | ||
| 311 | +} | ||
| 312 | + | ||
| 313 | +/// The half-line an export shows while its sound is still being mixed on the | ||
| 314 | +/// thread beside the picture (`engine::export::publish_seats`). An mp4 job | ||
| 315 | +/// overlaps the two passes, so this is what the *first* line out of one says | ||
| 316 | +/// about a codec that has not run yet. | ||
| 317 | +const MIXING: &str = "working out the sound…"; | ||
| 318 | + | ||
| 319 | +/// The encoders line a running job settles on: published as soon as the picture | ||
| 320 | +/// seat is open, and completed once the sound has been measured. Waiting for the | ||
| 321 | +/// second half is what makes this the line a card shows rather than a snapshot | ||
| 322 | +/// of an export mid-decision -- and, because a job that ends without ever | ||
| 323 | +/// completing it fails here, it is also the pin on that completion happening at | ||
| 324 | +/// all, whichever of the two passes finishes first. | ||
| 325 | +fn published_encoders(handle: &ExportHandle, what: &str) -> String { | ||
| 326 | + let started = Instant::now(); | ||
| 327 | + loop { | ||
| 328 | + match handle.encoders() { | ||
| 329 | + Some(line) if !line.ends_with(MIXING) => return line, | ||
| 330 | + _ => {} | ||
| 320 | } | 331 | } |
| 321 | assert!( | 332 | assert!( |
| 322 | !handle.is_finished(), | 333 | !handle.is_finished(), |
| 323 | - "the export settled before it opened an encoder: {:?}", | 334 | + "{what}: the export settled without naming its encoders ({:?}): {:?}", |
| 335 | + handle.encoders(), | ||
| 324 | handle.result().map(|r| r.err()) | 336 | handle.result().map(|r| r.err()) |
| 325 | ); | 337 | ); |
| 326 | assert!( | 338 | assert!( |
| 327 | started.elapsed() < Duration::from_secs(60), | 339 | started.elapsed() < Duration::from_secs(60), |
| 328 | - "no encoder was published" | 340 | + "{what}: no encoder was published" |
| 329 | ); | 341 | ); |
| 330 | std::thread::sleep(Duration::from_millis(10)); | 342 | std::thread::sleep(Duration::from_millis(10)); |
| 331 | - }; | 343 | + } |
| 332 | - handle.cancel(); | ||
| 333 | - wind_down(&handle); | ||
| 334 | - assert!( | ||
| 335 | - opened.ends_with(&planned), | ||
| 336 | - "{opened} does not end in {planned}" | ||
| 337 | - ); | ||
| 338 | } | 344 | } |
| 339 | 345 | ||
| 340 | /// Waits for a cancelled job to settle, so its `.part` is gone before the test | 346 | /// Waits for a cancelled job to settle, so its `.part` is gone before the test |
vendor/cros-codecs/src/encoder/h265.rsmodified+15 -0
| @@ -10,6 +10,17 @@ use crate::Resolution; | |||
| 10 | 10 | ||
| 11 | pub struct H265; | 11 | pub struct H265; |
| 12 | 12 | ||
| 13 | +/// What the SPS says the coded samples mean, as H.273 code points, and whether | ||
| 14 | +/// the luma codes cover the full range. Written into the VUI, which is the | ||
| 15 | +/// answer a decoder takes before it looks at any container tag. | ||
| 16 | +#[derive(Clone, Copy)] | ||
| 17 | +pub struct ColourDescription { | ||
| 18 | + pub colour_primaries: u32, | ||
| 19 | + pub transfer_characteristics: u32, | ||
| 20 | + pub matrix_coeffs: u32, | ||
| 21 | + pub full_range: bool, | ||
| 22 | +} | ||
| 23 | + | ||
| 13 | #[derive(Clone)] | 24 | #[derive(Clone)] |
| 14 | pub struct EncoderConfig { | 25 | pub struct EncoderConfig { |
| 15 | pub resolution: Resolution, | 26 | pub resolution: Resolution, |
| @@ -18,6 +29,9 @@ pub struct EncoderConfig { | |||
| 18 | pub pred_structure: PredictionStructure, | 29 | pub pred_structure: PredictionStructure, |
| 19 | /// Initial tunings values | 30 | /// Initial tunings values |
| 20 | pub initial_tunings: Tunings, | 31 | pub initial_tunings: Tunings, |
| 32 | + /// What the VUI declares about the samples. `None` writes no video signal | ||
| 33 | + /// type at all, and a stream that says nothing is read as "unspecified". | ||
| 34 | + pub colour: Option<ColourDescription>, | ||
| 21 | } | 35 | } |
| 22 | 36 | ||
| 23 | impl Default for EncoderConfig { | 37 | impl Default for EncoderConfig { |
| @@ -29,6 +43,7 @@ impl Default for EncoderConfig { | |||
| 29 | level: Level::L4, | 43 | level: Level::L4, |
| 30 | pred_structure: PredictionStructure::LowDelay { limit: 2048 }, | 44 | pred_structure: PredictionStructure::LowDelay { limit: 2048 }, |
| 31 | initial_tunings: Default::default(), | 45 | initial_tunings: Default::default(), |
| 46 | + colour: None, | ||
| 32 | } | 47 | } |
| 33 | } | 48 | } |
| 34 | } | 49 | } |
vendor/cros-codecs/src/encoder/stateless/h265/predictor.rsmodified+15 -3
| @@ -131,7 +131,7 @@ impl<Picture, Reference> LowDelayH265<Picture, Reference> { | |||
| 131 | 131 | ||
| 132 | // H.265 Table 6-1, the encoder only supports 4:2:0 subsampling. Must be set before | 132 | // H.265 Table 6-1, the encoder only supports 4:2:0 subsampling. Must be set before |
| 133 | // `resolution()`, which derives the conformance window from it. | 133 | // `resolution()`, which derives the conformance window from it. |
| 134 | - let sps = SpsBuilder::new(Rc::clone(&vps)) | 134 | + let mut sps = SpsBuilder::new(Rc::clone(&vps)) |
| 135 | .seq_parameter_set_id(0) | 135 | .seq_parameter_set_id(0) |
| 136 | .chroma_format_idc(1) | 136 | .chroma_format_idc(1) |
| 137 | .resolution(coded_width, coded_height) | 137 | .resolution(coded_width, coded_height) |
| @@ -150,8 +150,20 @@ impl<Picture, Reference> LowDelayH265<Picture, Reference> { | |||
| 150 | .max_latency_increase_plus1(0) | 150 | .max_latency_increase_plus1(0) |
| 151 | .short_term_ref_pic_set(short_term_ref_pic_set) | 151 | .short_term_ref_pic_set(short_term_ref_pic_set) |
| 152 | .long_term_ref_pics_present_flag(false) | 152 | .long_term_ref_pics_present_flag(false) |
| 153 | - .timing_info(1, self.tunings.framerate, false) | 153 | + .timing_info(1, self.tunings.framerate, false); |
| 154 | - .build(); | 154 | + |
| 155 | + // What the samples mean, where the caller declared it. `video_format` is | ||
| 156 | + // 5, "unspecified": the field is the analogue system a picture came off | ||
| 157 | + // and an encoded timeline came off none. | ||
| 158 | + if let Some(colour) = config.colour { | ||
| 159 | + sps = sps.video_signal_type(5, colour.full_range).colour_description( | ||
| 160 | + colour.colour_primaries, | ||
| 161 | + colour.transfer_characteristics, | ||
| 162 | + colour.matrix_coeffs, | ||
| 163 | + ); | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + let sps = sps.build(); | ||
| 155 | 167 | ||
| 156 | let min_qp = self.tunings.min_quality.max(MIN_QP as u32); | 168 | let min_qp = self.tunings.min_quality.max(MIN_QP as u32); |
| 157 | let max_qp = self.tunings.max_quality.min(MAX_QP as u32); | 169 | let max_qp = self.tunings.max_quality.min(MAX_QP as u32); |