Truly independent web browser
LibGfx+Compositor+Tests: Allow VideoToolbox to output 4:2:2 video
Zaggy10248a8109f13a5d
diff --git a/Libraries/LibGfx/VideoSurfaceImage.mm b/Libraries/LibGfx/VideoSurfaceImage.mmindex 7631d7485e4..07eec78edd8 100644--- a/Libraries/LibGfx/VideoSurfaceImage.mm+++ b/Libraries/LibGfx/VideoSurfaceImage.mm@@ -21,6 +21,10 @@ static constexpr Array biplanar_pixel_formats = {BiplanarPixelFormat { kCVPixelFormatType_420YpCbCr8BiPlanarFullRange, 8, Media::Subsampling::yuv420(), Media::VideoFullRangeFlag::Full },BiplanarPixelFormat { kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange, 10, Media::Subsampling::yuv420(), Media::VideoFullRangeFlag::Studio },BiplanarPixelFormat { kCVPixelFormatType_420YpCbCr10BiPlanarFullRange, 10, Media::Subsampling::yuv420(), Media::VideoFullRangeFlag::Full },+ BiplanarPixelFormat { kCVPixelFormatType_422YpCbCr8BiPlanarVideoRange, 8, Media::Subsampling::yuv422(), Media::VideoFullRangeFlag::Studio },+ BiplanarPixelFormat { kCVPixelFormatType_422YpCbCr8BiPlanarFullRange, 8, Media::Subsampling::yuv422(), Media::VideoFullRangeFlag::Full },+ BiplanarPixelFormat { kCVPixelFormatType_422YpCbCr10BiPlanarVideoRange, 10, Media::Subsampling::yuv422(), Media::VideoFullRangeFlag::Studio },+ BiplanarPixelFormat { kCVPixelFormatType_422YpCbCr10BiPlanarFullRange, 10, Media::Subsampling::yuv422(), Media::VideoFullRangeFlag::Full },BiplanarPixelFormat { kCVPixelFormatType_444YpCbCr8BiPlanarVideoRange, 8, Media::Subsampling::yuv444(), Media::VideoFullRangeFlag::Studio },BiplanarPixelFormat { kCVPixelFormatType_444YpCbCr8BiPlanarFullRange, 8, Media::Subsampling::yuv444(), Media::VideoFullRangeFlag::Full },BiplanarPixelFormat { kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange, 10, Media::Subsampling::yuv444(), Media::VideoFullRangeFlag::Studio },diff --git a/Services/Compositor/VideoFrameSkia.mm b/Services/Compositor/VideoFrameSkia.mmindex 1dcd09b1c87..b574ca2d0bf 100644--- a/Services/Compositor/VideoFrameSkia.mm+++ b/Services/Compositor/VideoFrameSkia.mm@@ -45,6 +45,8 @@ sk_sp<SkImage> sk_image_from_video_surface(Media::VideoSurface const& surface, Mauto subsampling = SkYUVAInfo::Subsampling::k420;if (format->subsampling == Media::Subsampling::yuv444())subsampling = SkYUVAInfo::Subsampling::k444;+ else if (format->subsampling == Media::Subsampling::yuv422())+ subsampling = SkYUVAInfo::Subsampling::k422;else if (format->subsampling != Media::Subsampling::yuv420())return nullptr;if (cicp.matrix_coefficients() == Media::MatrixCoefficients::Identity && subsampling != SkYUVAInfo::Subsampling::k444)diff --git a/Tests/Compositor/TestVideoSurfaceImage.mm b/Tests/Compositor/TestVideoSurfaceImage.mmindex 185d7c95c8a..33ffb2f46a0 100644--- a/Tests/Compositor/TestVideoSurfaceImage.mm+++ b/Tests/Compositor/TestVideoSurfaceImage.mm@@ -604,6 +604,21 @@ TEST_CASE(a_four_four_four_surface_and_separate_planes_of_the_same_samples_rendeexpect_surface_renders_as_its_pattern(kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange, *context);}+TEST_CASE(a_four_two_two_surface_and_separate_planes_of_the_same_samples_render_alike)+{+ EXPECT(!Gfx::validate_biplanar_video_surface(create_decoder_shaped_surface(TEST_WIDTH, TEST_HEIGHT, kCVPixelFormatType_422YpCbCr8BiPlanarVideoRange).release_value()).is_error());+ expect_surface_reads_back_as_its_pattern(kCVPixelFormatType_422YpCbCr8BiPlanarVideoRange);+ expect_surface_reads_back_as_its_pattern(kCVPixelFormatType_422YpCbCr10BiPlanarVideoRange);++ auto context = gpu_context();+ if (!context) {+ warnln("No GPU context available, skipping");+ return;+ }+ expect_surface_renders_as_its_pattern(kCVPixelFormatType_422YpCbCr8BiPlanarVideoRange, *context);+ expect_surface_renders_as_its_pattern(kCVPixelFormatType_422YpCbCr10BiPlanarVideoRange, *context);+}+TEST_CASE(an_rgb_surface_renders_as_its_green_blue_and_red_planes){auto context = gpu_context();diff --git a/Tests/LibMedia/TestVideoToolboxDecode.cpp b/Tests/LibMedia/TestVideoToolboxDecode.cppindex 4b15d74ea3f..f36b44b66ce 100644--- a/Tests/LibMedia/TestVideoToolboxDecode.cpp+++ b/Tests/LibMedia/TestVideoToolboxDecode.cpp@@ -591,3 +591,18 @@ TEST_CASE(h265_frames_carry_their_own_dolby_vision_scene_peaks)EXPECT_EQ(frame_count, 6u);scene_peaks.expect_every_frame_checked();}++TEST_CASE(a_four_two_two_stream_keeps_its_chroma_rows)+{+ auto decoding = open_decoding("./h264_422.mp4"sv, Media::CodecID::H264);++ auto frame_result = decoding.next_frame();+ if (frame_result.is_error()) {+ EXPECT(decoding_is_unavailable(frame_result.error()));+ return;+ }+ auto frame = frame_result.release_value();+ EXPECT_NE(frame->surface(), nullptr);+ EXPECT_EQ(frame->subsampling(), Media::Subsampling::yuv422());+ EXPECT_EQ(frame->size(), Gfx::Size<u32>(64, 64));+}diff --git a/Tests/LibMedia/h264_422.mp4 b/Tests/LibMedia/h264_422.mp4new file mode 100644index 00000000000..17d7659a3daBinary files /dev/null and b/Tests/LibMedia/h264_422.mp4 differ