Truly independent web browser
Everywhere: Give each Vulkan video codec a platform feature
Zaggy10243e074e7b6f0f
diff --git a/Libraries/LibMediaCodecs/FFmpeg/FFmpegVulkanVideoDecoder.cpp b/Libraries/LibMediaCodecs/FFmpeg/FFmpegVulkanVideoDecoder.cppindex 4e3900eede7..df4764ba141 100644--- a/Libraries/LibMediaCodecs/FFmpeg/FFmpegVulkanVideoDecoder.cpp+++ b/Libraries/LibMediaCodecs/FFmpeg/FFmpegVulkanVideoDecoder.cpp@@ -97,10 +97,24 @@ FFmpegFunctions const* ffmpeg_for(CodecID codec_id)}}-bool may_decode_with(FFmpegFunctions const& functions)+// Each codec's feature depends on the feature of the FFmpeg that decodes it.+bool may_decode(CodecID codec_id){- auto feature = &functions == &FFmpegFunctions::bundled() ? PlatformFeatures::Feature::VulkanVideoBundledFFmpeg : PlatformFeatures::Feature::VulkanVideoSystemFFmpeg;- return PlatformFeatures::ProcessFeatures::the().is_enabled(feature);+ auto feature = [&] -> Optional<PlatformFeatures::Feature> {+ switch (codec_id) {+ case CodecID::VP9:+ return PlatformFeatures::Feature::VulkanVideoBundledFFmpegVP9;+ case CodecID::AV1:+ return PlatformFeatures::Feature::VulkanVideoBundledFFmpegAV1;+ case CodecID::H264:+ return PlatformFeatures::Feature::VulkanVideoSystemFFmpegH264;+ case CodecID::H265:+ return PlatformFeatures::Feature::VulkanVideoSystemFFmpegH265;+ default:+ return {};+ }+ }();+ return feature.has_value() && PlatformFeatures::ProcessFeatures::the().is_enabled(*feature);}// Whether decoded images may be exported directly, rather than copied into images that export.@@ -268,7 +282,7 @@ Optional<DecoderCapabilities> FFmpegVulkanVideoDecoder::capabilities(ParsedCodecauto codec_id = codec.codec_id();auto const* functions = ffmpeg_for(codec_id);- if (functions == nullptr || !may_decode_with(*functions) || !device->has_enabled_extension(decode_extension_for(codec_id)))+ if (functions == nullptr || !may_decode(codec_id) || !device->has_enabled_extension(decode_extension_for(codec_id)))return {};if (vulkan_capable_decoder(*functions, codec_id) == nullptr)return {};@@ -399,7 +413,7 @@ DecoderErrorOr<NonnullOwnPtr<FFmpegVulkanVideoDecoder>> FFmpegVulkanVideoDecoderif (device == nullptr)return DecoderError::with_description(DecoderErrorCategory::NotImplemented, "No Vulkan device can decode video in this process"sv);auto const* ffmpeg = ffmpeg_for(codec_id);- if (ffmpeg == nullptr || !may_decode_with(*ffmpeg) || !device->has_enabled_extension(decode_extension_for(codec_id)))+ if (ffmpeg == nullptr || !may_decode(codec_id) || !device->has_enabled_extension(decode_extension_for(codec_id)))return DecoderError::format(DecoderErrorCategory::NotImplemented, "The Vulkan device cannot decode codec {}", codec_id);auto const& functions = *ffmpeg;diff --git a/Libraries/LibPlatformFeatures/Build.h b/Libraries/LibPlatformFeatures/Build.hindex 3bca866646d..76a5bc87c74 100644--- a/Libraries/LibPlatformFeatures/Build.h+++ b/Libraries/LibPlatformFeatures/Build.h@@ -35,9 +35,13 @@ struct Build {case Feature::VulkanVideo:case Feature::VulkanVideoBundledFFmpeg:case Feature::VulkanVideoBundledFFmpegDirectExport:+ case Feature::VulkanVideoBundledFFmpegVP9:+ case Feature::VulkanVideoBundledFFmpegAV1:return decodes_video_through_vulkan();case Feature::VulkanVideoSystemFFmpeg:case Feature::VulkanVideoSystemFFmpegDirectExport:+ case Feature::VulkanVideoSystemFFmpegH264:+ case Feature::VulkanVideoSystemFFmpegH265:return decodes_video_through_vulkan() && has_system_ffmpeg;}VERIFY_NOT_REACHED();diff --git a/Libraries/LibPlatformFeatures/Feature.cpp b/Libraries/LibPlatformFeatures/Feature.cppindex 40f86abad63..33f40c348b4 100644--- a/Libraries/LibPlatformFeatures/Feature.cpp+++ b/Libraries/LibPlatformFeatures/Feature.cpp@@ -21,10 +21,18 @@ StringView feature_id(Feature feature)return "vulkan_video.bundled_ffmpeg"sv;case Feature::VulkanVideoBundledFFmpegDirectExport:return "vulkan_video.bundled_ffmpeg.direct_export"sv;+ case Feature::VulkanVideoBundledFFmpegVP9:+ return "vulkan_video.bundled_ffmpeg.vp9"sv;+ case Feature::VulkanVideoBundledFFmpegAV1:+ return "vulkan_video.bundled_ffmpeg.av1"sv;case Feature::VulkanVideoSystemFFmpeg:return "vulkan_video.system_ffmpeg"sv;case Feature::VulkanVideoSystemFFmpegDirectExport:return "vulkan_video.system_ffmpeg.direct_export"sv;+ case Feature::VulkanVideoSystemFFmpegH264:+ return "vulkan_video.system_ffmpeg.h264"sv;+ case Feature::VulkanVideoSystemFFmpegH265:+ return "vulkan_video.system_ffmpeg.h265"sv;}VERIFY_NOT_REACHED();}@@ -47,8 +55,12 @@ FeatureProcess process_of(Feature feature)case Feature::VulkanVideo:case Feature::VulkanVideoBundledFFmpeg:case Feature::VulkanVideoBundledFFmpegDirectExport:+ case Feature::VulkanVideoBundledFFmpegVP9:+ case Feature::VulkanVideoBundledFFmpegAV1:case Feature::VulkanVideoSystemFFmpeg:case Feature::VulkanVideoSystemFFmpegDirectExport:+ case Feature::VulkanVideoSystemFFmpegH264:+ case Feature::VulkanVideoSystemFFmpegH265:return FeatureProcess::VideoDecoderServer;}VERIFY_NOT_REACHED();@@ -67,8 +79,12 @@ Optional<Feature> dependency_of(Feature feature)case Feature::VulkanVideoSystemFFmpeg:return Feature::VulkanVideo;case Feature::VulkanVideoBundledFFmpegDirectExport:+ case Feature::VulkanVideoBundledFFmpegVP9:+ case Feature::VulkanVideoBundledFFmpegAV1:return Feature::VulkanVideoBundledFFmpeg;case Feature::VulkanVideoSystemFFmpegDirectExport:+ case Feature::VulkanVideoSystemFFmpegH264:+ case Feature::VulkanVideoSystemFFmpegH265:return Feature::VulkanVideoSystemFFmpeg;}VERIFY_NOT_REACHED();diff --git a/Libraries/LibPlatformFeatures/Feature.h b/Libraries/LibPlatformFeatures/Feature.hindex 5e0f19ecd8e..fbd290ffb92 100644--- a/Libraries/LibPlatformFeatures/Feature.h+++ b/Libraries/LibPlatformFeatures/Feature.h@@ -26,8 +26,12 @@ enum class Feature : u8 {VulkanVideo,VulkanVideoBundledFFmpeg,VulkanVideoBundledFFmpegDirectExport,+ VulkanVideoBundledFFmpegVP9,+ VulkanVideoBundledFFmpegAV1,VulkanVideoSystemFFmpeg,VulkanVideoSystemFFmpegDirectExport,+ VulkanVideoSystemFFmpegH264,+ VulkanVideoSystemFFmpegH265,};constexpr Array all_features {@@ -36,8 +40,12 @@ constexpr Array all_features {Feature::VulkanVideo,Feature::VulkanVideoBundledFFmpeg,Feature::VulkanVideoBundledFFmpegDirectExport,+ Feature::VulkanVideoBundledFFmpegVP9,+ Feature::VulkanVideoBundledFFmpegAV1,Feature::VulkanVideoSystemFFmpeg,Feature::VulkanVideoSystemFFmpegDirectExport,+ Feature::VulkanVideoSystemFFmpegH264,+ Feature::VulkanVideoSystemFFmpegH265,};StringView feature_id(Feature);diff --git a/Libraries/LibWebView/PlatformFeatureDecisions.cpp b/Libraries/LibWebView/PlatformFeatureDecisions.cppindex 25f236ae094..151f351391d 100644--- a/Libraries/LibWebView/PlatformFeatureDecisions.cpp+++ b/Libraries/LibWebView/PlatformFeatureDecisions.cpp@@ -39,6 +39,13 @@ ReadonlySpan<BlocklistRule> blocklist_rules()return s_blocklist_rules;}+static Optional<String> missing_codec(SystemFacts const& facts, VideoDecodeFacts PlatformFeatures::GpuFacts::* codec, StringView name)+{+ if (!facts.gpu.has_value() || !((*facts.gpu).*codec).supported)+ return MUST(String::formatted("The GPU does not decode {} through Vulkan", name));+ return {};+}+static Optional<String> missing_capability(Feature feature, SystemFacts const& facts, PlatformFeatures::Build const& build){switch (feature) {@@ -76,6 +83,14 @@ static Optional<String> missing_capability(Feature feature, SystemFacts const& fif (!facts.gpu.has_value() || !(facts.gpu->h264.supported || facts.gpu->h265.supported))return "The GPU decodes neither H.264 nor HEVC through Vulkan"_string;return {};+ case Feature::VulkanVideoBundledFFmpegVP9:+ return missing_codec(facts, &PlatformFeatures::GpuFacts::vp9, "VP9"sv);+ case Feature::VulkanVideoBundledFFmpegAV1:+ return missing_codec(facts, &PlatformFeatures::GpuFacts::av1, "AV1"sv);+ case Feature::VulkanVideoSystemFFmpegH264:+ return missing_codec(facts, &PlatformFeatures::GpuFacts::h264, "H.264"sv);+ case Feature::VulkanVideoSystemFFmpegH265:+ return missing_codec(facts, &PlatformFeatures::GpuFacts::h265, "HEVC"sv);case Feature::VulkanVideoBundledFFmpegDirectExport:case Feature::VulkanVideoSystemFFmpegDirectExport:return {};diff --git a/Tests/LibWebView/TestPlatformFeatures.cpp b/Tests/LibWebView/TestPlatformFeatures.cppindex 05a50c24553..ccf393d5c45 100644--- a/Tests/LibWebView/TestPlatformFeatures.cpp+++ b/Tests/LibWebView/TestPlatformFeatures.cpp@@ -249,7 +249,16 @@ TEST_CASE(each_process_is_given_only_its_own_features)auto decisions = evaluate(facts_with_a_separate_dpb());EXPECT_EQ(decisions.features_for(FeatureProcess::Compositor).to_byte_string(), "gpu_painting,ycbcr_import"sv);EXPECT_EQ(decisions.features_for(FeatureProcess::VideoDecoderServer).to_byte_string(),- "vulkan_video,vulkan_video.bundled_ffmpeg,vulkan_video.bundled_ffmpeg.direct_export,vulkan_video.system_ffmpeg"sv);+ "vulkan_video,vulkan_video.bundled_ffmpeg,vulkan_video.bundled_ffmpeg.direct_export,vulkan_video.bundled_ffmpeg.vp9,vulkan_video.bundled_ffmpeg.av1,vulkan_video.system_ffmpeg,vulkan_video.system_ffmpeg.h264,vulkan_video.system_ffmpeg.h265"sv);+}++TEST_CASE(a_codec_the_gpu_does_not_decode_is_unsupported)+{+ auto facts = facts_with_a_coinciding_dpb();+ facts.gpu->av1.supported = false;+ auto decisions = evaluate(facts);+ EXPECT_EQ(decisions.status_of(Feature::VulkanVideoBundledFFmpegAV1).state, FeatureStatus::State::Unsupported);+ EXPECT(decisions.is_enabled(Feature::VulkanVideoBundledFFmpegVP9));}TEST_CASE(disabling_a_feature_turns_off_its_dependents_with_the_root_cause)