1#[doc(hidden)]
35pub mod vp9_dec;
36#[doc(hidden)]
37pub mod vp9_simd;
38
39use crate::vp9_dec::Decoder;
40use crate::{
41 CancellationToken, Codec, CodecImplementation, CodecProfile, CodecSupport, DecodedVideoFrame,
42 EncodedVideoSample, Error, ErrorKind, HardwarePreference, Limits, PixelFormat, Result,
43 VideoDecoder, VideoDecoderConfig, VideoDecoderFactory, Vp9CodecConfig,
44};
45#[allow(unused_imports)]
46use zvidlib_color::*;
47#[allow(unused_imports)]
48use zvidlib_core::*;
49pub(crate) use zvidlib_vp9_syntax::picture_to_rgba;
50#[cfg(test)]
52#[allow(unused_imports)]
53use zvidlib_container::*;
54
55pub fn native_vp9_video_decoder_factory() -> impl VideoDecoderFactory {
70 Vp9DecoderFactory
71}
72
73#[derive(Clone, Copy, Debug)]
74struct Vp9DecoderFactory;
75
76impl VideoDecoderFactory for Vp9DecoderFactory {
77 fn capability(&self, configuration: &VideoDecoderConfig) -> CodecSupport {
78 match self.capability_without_parsing(configuration) {
79 CodecSupport::Supported { .. } => {}
80 other => return other,
81 }
82 if let Err(error) = parse_configuration(configuration, &Limits::default()) {
83 return invalid_configuration(error.message());
84 }
85 if configuration.hardware != HardwarePreference::Avoid && hardware_available(configuration)
86 {
87 return CodecSupport::Supported {
88 implementation: CodecImplementation::Hardware,
89 };
90 }
91 if configuration.hardware == HardwarePreference::Require {
92 return CodecSupport::HardwareUnavailable;
93 }
94 CodecSupport::Supported {
95 implementation: CodecImplementation::Software,
96 }
97 }
98
99 fn create(
100 &self,
101 configuration: &VideoDecoderConfig,
102 limits: &Limits,
103 ) -> Result<Box<dyn VideoDecoder>> {
104 match self.capability_without_parsing(configuration) {
105 CodecSupport::Supported { .. } => {}
106 CodecSupport::UnsupportedCodec => {
107 return Err(Error::new(
108 ErrorKind::Unsupported,
109 "native VP9 decoder requires VP9",
110 ));
111 }
112 CodecSupport::UnsupportedProfile => {
113 return Err(Error::new(
114 ErrorKind::Unsupported,
115 "native VP9 decoder supports profiles 0 and 2",
116 ));
117 }
118 CodecSupport::HardwareUnavailable => unreachable!("hardware is not checked here"),
119 CodecSupport::InvalidConfiguration { reason } => {
120 return Err(Error::new(ErrorKind::InvalidInput, reason));
121 }
122 _ => {
123 return Err(Error::new(
124 ErrorKind::Unsupported,
125 "native VP9 decoder does not support this configuration",
126 ));
127 }
128 }
129 parse_configuration(configuration, limits)?;
130 if configuration.hardware != HardwarePreference::Avoid {
131 let hardware_errors = match create_hardware(configuration, limits) {
132 Ok(decoder) => return Ok(decoder),
133 Err(errors) => errors,
134 };
135 if configuration.hardware == HardwarePreference::Require {
136 let detail = if hardware_errors.is_empty() {
137 "no accelerated backend exists for this target".to_owned()
138 } else {
139 hardware_errors.join("; ")
140 };
141 return Err(Error::new(
142 ErrorKind::Unsupported,
143 format!("hardware VP9 decoding is unavailable ({detail})"),
144 ));
145 }
146 }
147 Ok(Box::new(Vp9Decoder {
148 limits: *limits,
149 inner: Decoder::new(*limits),
150 }))
151 }
152}
153
154impl Vp9DecoderFactory {
155 fn capability_without_parsing(&self, configuration: &VideoDecoderConfig) -> CodecSupport {
156 if configuration.codec != Codec::Vp9 {
157 return CodecSupport::UnsupportedCodec;
158 }
159 if !matches!(
160 configuration.profile,
161 CodecProfile::Vp9Profile0 | CodecProfile::Vp9Profile2
162 ) {
163 return CodecSupport::UnsupportedProfile;
164 }
165 if configuration.output_format != PixelFormat::Rgba8 {
166 return invalid_configuration("native VP9 decoding currently outputs RGBA8");
167 }
168 CodecSupport::Supported {
169 implementation: CodecImplementation::Software,
170 }
171 }
172}
173
174fn hardware_available(_configuration: &VideoDecoderConfig) -> bool {
175 let Some(_bit_depth) = zvidlib_vp9_syntax::configured_bit_depth(
177 _configuration.profile,
178 &_configuration.configuration,
179 ) else {
180 return false;
181 };
182 let backends: &[fn(VideoDimensions, u8) -> bool] = &[
184 #[cfg(all(
185 feature = "hardware",
186 any(windows, target_os = "linux"),
187 target_pointer_width = "64"
188 ))]
189 zvidlib_hardware::nvdec::is_vp9_available,
190 #[cfg(all(feature = "hardware", windows))]
191 zvidlib_hardware::windows_mf::is_vp9_available,
192 #[cfg(all(feature = "hardware", target_os = "macos"))]
193 zvidlib_hardware::videotoolbox_vp9::is_vp9_available,
194 ];
195 backends
196 .iter()
197 .any(|is_available| is_available(_configuration.coded_dimensions, _bit_depth))
198}
199
200fn create_hardware(
203 _configuration: &VideoDecoderConfig,
204 _limits: &Limits,
205) -> std::result::Result<Box<dyn VideoDecoder>, Vec<String>> {
206 if zvidlib_vp9_syntax::configured_bit_depth(
207 _configuration.profile,
208 &_configuration.configuration,
209 )
210 .is_none()
211 {
212 return Err(vec![
213 "hardware VP9 profile 2 decoding needs a configuration naming the bit depth".to_owned(),
214 ]);
215 }
216 #[cfg_attr(
217 not(all(
218 feature = "hardware",
219 any(
220 windows,
221 all(target_os = "linux", target_pointer_width = "64"),
222 target_os = "macos"
223 )
224 )),
225 allow(unused_mut)
226 )]
227 let mut errors = Vec::new();
228 #[cfg(all(
229 feature = "hardware",
230 any(windows, target_os = "linux"),
231 target_pointer_width = "64"
232 ))]
233 match zvidlib_hardware::nvdec::create_vp9(_configuration, _limits) {
234 Ok(decoder) => return Ok(decoder),
235 Err(error) => errors.push(format!("NVDEC: {}", error.message())),
236 }
237 #[cfg(all(feature = "hardware", windows))]
238 match zvidlib_hardware::windows_mf::create_vp9(_configuration, _limits) {
239 Ok(decoder) => return Ok(decoder),
240 Err(error) => errors.push(format!("Media Foundation: {}", error.message())),
241 }
242 #[cfg(all(feature = "hardware", target_os = "macos"))]
243 match create_videotoolbox(_configuration, _limits) {
244 Ok(decoder) => return Ok(decoder),
245 Err(error) => errors.push(format!("VideoToolbox: {}", error.message())),
246 }
247 Err(errors)
248}
249
250#[cfg(all(feature = "hardware", target_os = "macos"))]
253fn create_videotoolbox(
254 configuration: &VideoDecoderConfig,
255 limits: &Limits,
256) -> Result<Box<dyn VideoDecoder>> {
257 zvidlib_hardware::videotoolbox_vp9::create_vp9(configuration, limits, replay)
258}
259
260#[cfg(all(feature = "hardware", target_os = "macos"))]
262fn replay(
263 limits: &Limits,
264 history: &[Vec<u8>],
265 chunk: &[u8],
266) -> Result<zvidlib_vp9_syntax::DecodedPicture> {
267 let mut decoder = Decoder::new(*limits);
268 decoder.set_output_wanted(false);
269 for earlier in history {
270 decoder.decode_chunk(earlier)?;
271 }
272 decoder.set_output_wanted(true);
273 decoder.decode_chunk(chunk)?.ok_or_else(|| {
274 Error::new(
275 ErrorKind::Codec,
276 "the VP9 frame shown again was not decoded",
277 )
278 })
279}
280
281fn invalid_configuration(reason: impl Into<String>) -> CodecSupport {
282 CodecSupport::InvalidConfiguration {
283 reason: reason.into(),
284 }
285}
286
287fn parse_configuration(configuration: &VideoDecoderConfig, limits: &Limits) -> Result<()> {
292 if configuration.configuration.len() as u64 > limits.max_allocation_bytes {
293 return Err(limit("VP9 configuration exceeds the allocation limit"));
294 }
295 if configuration.configuration.is_empty() {
296 return Ok(());
297 }
298 let record = Vp9CodecConfig::parse(&configuration.configuration)
299 .map_err(|error| malformed(format!("invalid VP9 configuration: {error}")))?;
300 let supported = match configuration.profile {
301 CodecProfile::Vp9Profile0 => record.profile == 0 && record.bit_depth == 8,
302 _ => record.profile == 2 && matches!(record.bit_depth, 10 | 12),
303 };
304 if !supported || !record.is_420() {
305 return Err(Error::new(
306 ErrorKind::Unsupported,
307 "native VP9 decoder requires a profile 0 8-bit or profile 2 10- or 12-bit 4:2:0 \
308 configuration",
309 ));
310 }
311 Ok(())
312}
313
314struct Vp9Decoder {
315 limits: Limits,
316 inner: Decoder,
317}
318
319impl VideoDecoder for Vp9Decoder {
320 fn submit(
321 &mut self,
322 sample: &EncodedVideoSample,
323 cancellation: &CancellationToken,
324 ) -> Result<Vec<DecodedVideoFrame>> {
325 cancellation.check()?;
326 if sample.data.len() as u64 > self.limits.max_allocation_bytes {
327 return Err(limit("VP9 sample exceeds the allocation limit"));
328 }
329 let shown_before = self.inner.frames_shown();
330 let picture = self.inner.decode_chunk(&sample.data)?;
331 if self.inner.frames_shown() == shown_before {
332 return Err(malformed("VP9 sample does not show a frame"));
333 }
334 let Some(picture) = picture else {
335 return Ok(Vec::new());
337 };
338 Ok(vec![DecodedVideoFrame {
339 presentation_index: sample.presentation_index,
340 frame: picture_to_rgba(&picture, &self.limits)?,
341 }])
342 }
343
344 fn drain(&mut self, cancellation: &CancellationToken) -> Result<Vec<DecodedVideoFrame>> {
345 cancellation.check()?;
346 Ok(Vec::new())
349 }
350
351 fn reset(&mut self) -> Result<()> {
352 self.inner.reset();
353 Ok(())
354 }
355
356 fn set_output_wanted(&mut self, wanted: bool) {
357 self.inner.set_output_wanted(wanted);
361 }
362}
363
364fn malformed(message: impl Into<String>) -> Error {
365 Error::new(ErrorKind::MalformedMedia, message)
366}
367
368fn limit(message: impl Into<String>) -> Error {
369 Error::new(ErrorKind::ResourceLimit, message)
370}
371
372#[doc(hidden)]
376#[must_use]
377pub fn simd_sites() -> Vec<(&'static str, zvidlib_core::SimdIsa)> {
378 vec![("vp9_decode", vp9_simd::active_isa())]
379}
380
381#[cfg(test)]
382mod tests {
383 use super::*;
384 use zvidlib_vp9_syntax::matrix_for;
385
386 fn vpcc(record: &[u8]) -> Vec<u8> {
387 let mut bytes = (12u32 + record.len() as u32).to_be_bytes().to_vec();
388 bytes.extend_from_slice(b"vpcC");
389 bytes.extend_from_slice(&[1, 0, 0, 0]);
390 bytes.extend_from_slice(record);
391 bytes
392 }
393
394 fn config() -> VideoDecoderConfig {
395 VideoDecoderConfig {
396 codec: Codec::Vp9,
397 profile: CodecProfile::Vp9Profile0,
398 coded_dimensions: VideoDimensions::new(16, 16, &Limits::default()).unwrap(),
399 output_format: PixelFormat::Rgba8,
400 color_range: ColorRange::Limited,
401 hardware: HardwarePreference::Avoid,
402 configuration: vpcc(&[0, 10, 0x80, 2, 2, 2, 0, 0]),
403 }
404 }
405
406 #[test]
407 fn capability_distinguishes_codec_profile_configuration_and_hardware() {
408 let factory = native_vp9_video_decoder_factory();
409 assert!(factory.capability(&config()).is_supported());
410
411 let mut candidate = config();
412 candidate.configuration = Vec::new();
413 assert!(factory.capability(&candidate).is_supported());
414
415 candidate = config();
416 candidate.codec = Codec::Av1;
417 assert_eq!(
418 factory.capability(&candidate),
419 CodecSupport::UnsupportedCodec
420 );
421
422 for profile in [CodecProfile::Vp9Profile1, CodecProfile::Vp9Profile3] {
423 candidate = config();
424 candidate.profile = profile;
425 assert_eq!(
426 factory.capability(&candidate),
427 CodecSupport::UnsupportedProfile
428 );
429 }
430
431 let software = CodecSupport::Supported {
436 implementation: CodecImplementation::Software,
437 };
438 let hardware = CodecSupport::Supported {
439 implementation: CodecImplementation::Hardware,
440 };
441 for (configuration, bit_depth) in [
442 (vpcc(&[2, 10, 0xa2, 2, 2, 2, 0, 0]), Some(10)),
443 (vpcc(&[2, 10, 0xc2, 2, 2, 2, 0, 0]), Some(12)),
444 (Vec::new(), None),
445 ] {
446 candidate = config();
447 candidate.profile = CodecProfile::Vp9Profile2;
448 candidate.configuration = configuration;
449 candidate.coded_dimensions = VideoDimensions::new(160, 90, &Limits::default()).unwrap();
451 assert_eq!(
452 zvidlib_vp9_syntax::configured_bit_depth(
453 candidate.profile,
454 &candidate.configuration
455 ),
456 bit_depth
457 );
458 candidate.hardware = HardwarePreference::Avoid;
459 assert_eq!(factory.capability(&candidate), software);
460 assert!(factory.create(&candidate, &Limits::default()).is_ok());
461 let available = hardware_available(&candidate);
462 if bit_depth.is_none() {
463 assert!(!available);
464 }
465 candidate.hardware = HardwarePreference::Prefer;
466 let preferred = factory.capability(&candidate);
467 assert_eq!(
468 preferred,
469 if available { &hardware } else { &software }.clone()
470 );
471 assert!(factory.create(&candidate, &Limits::default()).is_ok());
472 candidate.hardware = HardwarePreference::Require;
473 if available {
474 assert_eq!(factory.capability(&candidate), hardware);
475 assert!(factory.create(&candidate, &Limits::default()).is_ok());
476 } else {
477 assert_eq!(
478 factory.capability(&candidate),
479 CodecSupport::HardwareUnavailable
480 );
481 let error = factory
482 .create(&candidate, &Limits::default())
483 .err()
484 .unwrap();
485 assert_eq!(error.kind(), ErrorKind::Unsupported);
486 if bit_depth.is_none() {
487 assert!(error.message().contains("profile 2"), "{error:?}");
488 }
489 }
490 }
491 for configuration in [
493 vpcc(&[2, 10, 0x82, 2, 2, 2, 0, 0]),
494 vpcc(&[2, 10, 0xa6, 2, 2, 2, 0, 0]),
495 ] {
496 candidate = config();
497 candidate.profile = CodecProfile::Vp9Profile2;
498 candidate.configuration = configuration;
499 assert!(matches!(
500 factory.capability(&candidate),
501 CodecSupport::InvalidConfiguration { .. }
502 ));
503 }
504
505 candidate = config();
507 candidate.hardware = HardwarePreference::Require;
508 let required = factory.capability(&candidate);
509 candidate.hardware = HardwarePreference::Prefer;
510 let preferred = factory.capability(&candidate);
511 if hardware_available(&candidate) {
512 let hardware = CodecSupport::Supported {
513 implementation: CodecImplementation::Hardware,
514 };
515 assert_eq!((required, preferred), (hardware.clone(), hardware));
516 } else {
517 assert_eq!(required, CodecSupport::HardwareUnavailable);
518 assert_eq!(
519 preferred,
520 CodecSupport::Supported {
521 implementation: CodecImplementation::Software
522 }
523 );
524 }
525
526 candidate = config();
527 candidate.output_format = PixelFormat::Yuv420p8;
528 assert!(matches!(
529 factory.capability(&candidate),
530 CodecSupport::InvalidConfiguration { .. }
531 ));
532
533 for configuration in [
535 vpcc(&[0, 10, 0xa0, 2, 2, 2, 0, 0]),
536 vpcc(&[1, 10, 0x86, 2, 2, 2, 0, 0]),
537 vec![1, 2, 3],
538 ] {
539 candidate = config();
540 candidate.configuration = configuration;
541 assert!(matches!(
542 factory.capability(&candidate),
543 CodecSupport::InvalidConfiguration { .. }
544 ));
545 }
546 }
547
548 #[test]
549 fn create_rejects_malformed_configuration_and_samples() {
550 let mut candidate = config();
551 candidate.configuration = vec![1, 2, 3];
552 let error = native_vp9_video_decoder_factory()
553 .create(&candidate, &Limits::default())
554 .err()
555 .unwrap();
556 assert_eq!(error.kind(), ErrorKind::MalformedMedia);
557
558 let mut decoder = native_vp9_video_decoder_factory()
559 .create(&config(), &Limits::default())
560 .unwrap();
561 for data in [vec![], vec![0xff, 0xff], vec![0x82, 0x49, 0x83]] {
562 let sample = EncodedVideoSample {
563 presentation_index: crate::FrameIndex(0),
564 random_access: true,
565 data,
566 };
567 let error = decoder
568 .submit(&sample, &CancellationToken::new())
569 .unwrap_err();
570 assert_eq!(error.kind(), ErrorKind::MalformedMedia);
571 }
572 }
573
574 #[test]
575 fn create_enforces_allocation_limit() {
576 let restrictive = Limits {
577 max_allocation_bytes: 0,
578 ..Limits::default()
579 };
580 let error = native_vp9_video_decoder_factory()
581 .create(&config(), &restrictive)
582 .err()
583 .unwrap();
584 assert_eq!(error.kind(), ErrorKind::ResourceLimit);
585 }
586
587 #[test]
588 fn color_spaces_pick_their_matrix() {
589 assert_eq!(matrix_for(0), MatrixCoefficients::Bt601);
590 assert_eq!(matrix_for(1), MatrixCoefficients::Bt601);
591 assert_eq!(matrix_for(2), MatrixCoefficients::Bt709);
592 assert_eq!(matrix_for(3), MatrixCoefficients::Bt601);
593 assert_eq!(matrix_for(5), MatrixCoefficients::Bt2020Ncl);
594 }
595
596 #[cfg(any(
607 windows,
608 all(target_os = "linux", target_pointer_width = "64"),
609 target_os = "macos"
610 ))]
611 #[test]
612 fn each_hardware_backend_matches_the_software_decoder_and_seeks_exactly() {
613 use crate::{
614 ExpectedVideoFrame, FrameDigest, FrameIndex, VideoDecoderConformanceVector,
615 verify_video_decoder_conformance,
616 };
617
618 type Create = fn(&VideoDecoderConfig, &Limits) -> Result<Box<dyn VideoDecoder>>;
619
620 struct Backend(Create);
621
622 impl VideoDecoderFactory for Backend {
623 fn capability(&self, _configuration: &VideoDecoderConfig) -> CodecSupport {
624 CodecSupport::Supported {
625 implementation: CodecImplementation::Hardware,
626 }
627 }
628
629 fn create(
630 &self,
631 configuration: &VideoDecoderConfig,
632 limits: &Limits,
633 ) -> Result<Box<dyn VideoDecoder>> {
634 (self.0)(configuration, limits)
635 }
636 }
637
638 fn block_on<T>(future: impl std::future::Future<Output = T>) -> T {
639 use std::task::{Context, Poll, Waker};
640 let mut context = Context::from_waker(Waker::noop());
641 let mut future = Box::pin(future);
642 loop {
643 if let Poll::Ready(value) = future.as_mut().poll(&mut context) {
644 return value;
645 }
646 }
647 }
648
649 let backends: [(&str, Create); _] = [
650 #[cfg(all(
651 feature = "hardware",
652 any(windows, target_os = "linux"),
653 target_pointer_width = "64"
654 ))]
655 ("NVDEC", zvidlib_hardware::nvdec::create_vp9),
656 #[cfg(all(feature = "hardware", windows))]
657 ("Media Foundation", zvidlib_hardware::windows_mf::create_vp9),
658 #[cfg(all(feature = "hardware", target_os = "macos"))]
659 ("VideoToolbox", create_videotoolbox),
660 ];
661
662 let limits = Limits::default();
663 let mut streams = Vec::new();
664 for (name, file, profile) in [
665 (
666 "VP9 256x144 with hidden frames",
667 &include_bytes!("../tests/fixtures/vp9_bbb_256x144.mp4")[..],
668 CodecProfile::Vp9Profile0,
669 ),
670 (
671 "VP9 250x142",
672 &include_bytes!("../tests/fixtures/vp9_bbb_250x142.mp4")[..],
673 CodecProfile::Vp9Profile0,
674 ),
675 (
676 "VP9 profile 2 10-bit 160x90 with hidden frames",
677 &include_bytes!("../tests/fixtures/vp9_bbb_160x90_10bit.mp4")[..],
678 CodecProfile::Vp9Profile2,
679 ),
680 ] {
681 let source = crate::io::MemorySource::new(file.to_vec());
682 let movie = block_on(crate::Mp4Demuxer::open(&source, Default::default())).unwrap();
683 let track = movie.track(1).unwrap();
684 let configuration = VideoDecoderConfig {
685 codec: Codec::Vp9,
686 profile,
687 coded_dimensions: track.dimensions.unwrap(),
688 output_format: PixelFormat::Rgba8,
689 color_range: ColorRange::Limited,
690 hardware: HardwarePreference::Avoid,
691 configuration: track.decoder_config.clone(),
692 };
693 let samples = block_on(track.to_encoded_video_samples(&source, &limits)).unwrap();
694 streams.push((name, configuration, samples));
695 }
696 let twelve_bit = crate::vp9_dec::tests::webm_frames(include_bytes!(
699 "../tests/fixtures/vp9_bbb_160x90_12bit.webm"
700 ));
701 streams.push((
702 "VP9 profile 2 12-bit 160x90",
703 VideoDecoderConfig {
704 configuration: vpcc(&[2, 10, 0xc2, 2, 2, 2, 0, 0]),
705 coded_dimensions: VideoDimensions::new(160, 90, &limits).unwrap(),
706 ..streams[2].1.clone()
707 },
708 twelve_bit
709 .iter()
710 .enumerate()
711 .map(|(index, data)| EncodedVideoSample {
712 presentation_index: FrameIndex(index as u64),
713 random_access: index == 0,
714 data: data.to_vec(),
715 })
716 .collect(),
717 ));
718 for (name, stream, marker) in [
723 ("VP9 show_existing_frame", 0, 0x88),
724 ("VP9 profile 2 10-bit show_existing_frame", 2, 0x98),
725 ] {
726 let (_, configuration, samples) = &streams[stream];
727 let mut existing = samples[..4].to_vec();
728 for slot in 0..8u8 {
729 existing.push(EncodedVideoSample {
730 presentation_index: FrameIndex(existing.len() as u64),
731 random_access: false,
732 data: vec![marker | slot],
733 });
734 }
735 streams.push((name, configuration.clone(), existing));
736 }
737
738 let cancellation = CancellationToken::new();
739 let software = native_vp9_video_decoder_factory();
740 for (backend, create) in backends {
741 let factory = Backend(create);
742 if let Err(error) = factory.create(&streams[0].1, &limits) {
743 eprintln!("skipping {backend}: hardware VP9 decoding unavailable: {error}");
744 continue;
745 }
746 for (name, configuration, samples) in &streams {
747 if configuration.profile == CodecProfile::Vp9Profile2
750 && let Err(error) = factory.create(configuration, &limits)
751 {
752 eprintln!("skipping {backend} {name}: {error}");
753 continue;
754 }
755 let decode = |factory: &dyn VideoDecoderFactory| {
756 let mut decoder = factory.create(configuration, &limits).unwrap();
757 let mut digests = Vec::new();
758 for sample in samples {
759 let outputs = decoder
760 .submit(sample, &cancellation)
761 .unwrap_or_else(|error| panic!("{backend} {name}: {error}"));
762 assert_eq!(outputs.len(), 1, "{backend} {name}");
763 assert_eq!(outputs[0].presentation_index, sample.presentation_index);
764 digests.push(FrameDigest::from_frame(&outputs[0].frame).unwrap());
765 }
766 assert!(decoder.drain(&cancellation).unwrap().is_empty());
767 digests
768 };
769 let expected = decode(&software);
770 assert_eq!(decode(&factory), expected, "{backend} {name}");
771 let vector = VideoDecoderConformanceVector {
772 name: (*name).into(),
773 configuration: configuration.clone(),
774 expected_frames: expected
775 .iter()
776 .enumerate()
777 .map(|(index, &digest)| ExpectedVideoFrame {
778 presentation_index: FrameIndex(index as u64),
779 digest,
780 })
781 .collect(),
782 samples: samples.clone(),
783 };
784 verify_video_decoder_conformance(&factory, &vector, limits)
785 .unwrap_or_else(|error| panic!("{backend} {name}: {error}"));
786 }
787 if let Ok(mut decoder) = factory.create(&streams[2].1, &limits) {
790 let error = decoder
791 .submit(&streams[0].2[0], &cancellation)
792 .err()
793 .unwrap_or_else(|| panic!("{backend} decoded 8-bit VP9 as 10-bit"));
794 assert_eq!(error.kind(), ErrorKind::Unsupported, "{backend}: {error}");
795 }
796 eprintln!("{backend}: every VP9 frame matches the software decoder");
797 }
798 }
799}