diff --git a/crates/media/src/craft_source.rs b/crates/media/src/craft_source.rs index 1bf733128..7518b13b4 100644 --- a/crates/media/src/craft_source.rs +++ b/crates/media/src/craft_source.rs @@ -2870,6 +2870,15 @@ mod raw_avi_tests; mod tests { use super::*; + /// A decoder's "unsupported" stays unsupported; anything else is a decode failure. + #[test] + fn video_decode_errors_keep_unsupported_apart() { + assert!(matches!(video_decode_error(VideoError::Unsupported("H.264: 4:2:2".into())), MediaError::Unsupported(s) if s == "H.264: 4:2:2")); + assert!( + matches!(video_decode_error(VideoError::Malformed("VP9: bad header".into())), MediaError::Decode(s) if s == "malformed video: VP9: bad header") + ); + } + // One 20 ms mono packet from craft-audio's generated tone.opus test fixture. // Re-mux it into ordinary small audio-only files without an external encoder. const OPUS_TONE: &[u8] = b"\x78\x82\x01\xB7\x6C\x7E\x40\xE6\x00\x00\x0A\xBE\x9A\xA7\xBE\xFF\xB6\x85\xD7\x0A\x71\xE0\xDD\ diff --git a/crates/media/src/pool.rs b/crates/media/src/pool.rs index 92c7031f5..14bca26bf 100644 --- a/crates/media/src/pool.rs +++ b/crates/media/src/pool.rs @@ -2343,6 +2343,34 @@ mod tests { assert_eq!(c.bytes, (16 * 16 * 16 + 64) + (16 * 16 * 4 + 64)); } + /// The shared decoder's real messages read without their wrappers or the H.264 syntax-field + /// number, and stay "unsupported" or "can't be decoded" as the decoder said. + #[test] + fn describe_problem_unwraps_shared_decoder_errors() { + let unsupported = |s: &str| MediaError::Unsupported(s.into()); + assert_eq!( + describe_problem("H.264", &unsupported("H.264: unsupported: chroma_format_idc 2 (only 4:2:0 is implemented)")), + "H.264 isn't supported by the built-in decoder: 4:2:2 chroma (only 4:2:0 is implemented)" + ); + assert_eq!( + describe_problem("H.264", &unsupported("H.264: chroma_format_idc 0 stream")), + "H.264 isn't supported by the built-in decoder: monochrome stream" + ); + assert_eq!(describe_problem("H.264", &unsupported("chroma_format_idc 3 stream")), "H.264 isn't supported by the built-in decoder: 4:4:4 chroma stream"); + // The relabel is H.264's own field: another codec keeps the text. + assert_eq!( + describe_problem("HEVC", &unsupported("chroma_format_idc 2 stream")), + "HEVC isn't supported by the built-in decoder: chroma_format_idc 2 stream" + ); + // A wrapped "unsupported" inside a decode error still counts as unsupported. + assert_eq!( + describe_problem("VP9", &MediaError::Decode("decode error: unsupported video: VP9: profile 3".into())), + "VP9 isn't supported by the built-in decoder: profile 3" + ); + assert_eq!(describe_problem("VP9", &MediaError::Decode("malformed video: VP9: bad frame header".into())), "VP9 can't be decoded: bad frame header"); + assert_eq!(describe_problem("", &MediaError::Decode("malformed video: truncated".into())), "This video can't be decoded: truncated"); + } + /// #482: an OpenEXR file with HTJ2K compression (which the decoder lacks) says so on import /// and when its frame is read, instead of "no non-deep rgb channels" or a transparent frame. #[test]