Commit dab8c1ff authored by Sharon Yang's avatar Sharon Yang Committed by Commit Bot

[fuchsia] Add HARDWARE_VIDEO_DECODER flag enforcement

Make sure video decoding is only enabled when the feature flag
HARDWARE_VIDEO_DECODER is set.

Bug: 1004461
Change-Id: I1fca519539a508c6b59e8997db11d1efe112940e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2363174
Commit-Queue: Sharon Yang <yangsharon@chromium.org>
Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Reviewed-by: default avatarDavid Dorwin <ddorwin@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811023}
parent 34f8794c
......@@ -361,6 +361,7 @@ test("web_engine_integration_tests") {
"//media",
"//media/fuchsia/audio:test_support",
"//media/fuchsia/camera:test_support",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.mediacodec",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.sys",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.web",
]
......
......@@ -476,13 +476,22 @@ void ContextProviderImpl::Create(
base::FilePath(kCdmDataPath), cdm_data_directory_channel.get()});
}
bool enable_hardware_video_decoder =
(features & fuchsia::web::ContextFeatureFlags::HARDWARE_VIDEO_DECODER) ==
fuchsia::web::ContextFeatureFlags::HARDWARE_VIDEO_DECODER;
if (!enable_hardware_video_decoder)
launch_command.AppendSwitch(switches::kDisableAcceleratedVideoDecode);
if (enable_hardware_video_decoder && !enable_vulkan) {
DLOG(ERROR) << "HARDWARE_VIDEO_DECODER requires VULKAN.";
context_request.Close(ZX_ERR_NOT_SUPPORTED);
return;
}
bool disable_software_video_decoder =
(features &
fuchsia::web::ContextFeatureFlags::HARDWARE_VIDEO_DECODER_ONLY) ==
fuchsia::web::ContextFeatureFlags::HARDWARE_VIDEO_DECODER_ONLY;
bool enable_hardware_video_decoder =
(features & fuchsia::web::ContextFeatureFlags::HARDWARE_VIDEO_DECODER) ==
fuchsia::web::ContextFeatureFlags::HARDWARE_VIDEO_DECODER;
if (disable_software_video_decoder) {
if (!enable_hardware_video_decoder) {
LOG(ERROR) << "Software video decoding may only be disabled if hardware "
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <fuchsia/mediacodec/cpp/fidl.h>
#include <fuchsia/sys/cpp/fidl.h>
#include <fuchsia/web/cpp/fidl.h>
#include <lib/fdio/directory.h>
......@@ -570,8 +571,6 @@ TEST_F(WebEngineIntegrationTest, PlayAudio_NoFlag) {
TEST_F(WebEngineIntegrationTest, PlayVideo) {
CreateContextAndFrame(ContextParamsWithAudioAndTestData());
frame_->SetBlockMediaLoading(false);
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html?autoplay");
navigation_listener_->RunUntilTitleEquals("ended");
......@@ -745,3 +744,55 @@ TEST_F(WebEngineIntegrationTestBase, CameraNoVideoCaptureProcess) {
StartWebEngine(std::move(command_line));
RunCameraTest(/*grant_permission=*/true);
}
// Check that when the ContextFeatureFlag HARDWARE_VIDEO_DECODER is
// provided that the CodecFactory service is connected to.
TEST_F(MAYBE_VulkanWebEngineIntegrationTest,
HardwareVideoDecoderFlag_Provided) {
fuchsia::web::CreateContextParams create_params =
ContextParamsWithAudioAndTestData();
// The VULKAN flag is required for hardware video decoders to be available.
create_params.set_features(
fuchsia::web::ContextFeatureFlags::VULKAN |
fuchsia::web::ContextFeatureFlags::HARDWARE_VIDEO_DECODER |
fuchsia::web::ContextFeatureFlags::AUDIO);
CreateContextAndFrame(std::move(create_params));
// Check that the CodecFactory service is requested.
bool is_requested = false;
filtered_service_directory_->outgoing_directory()->AddPublicService(
std::make_unique<vfs::Service>(
[&is_requested](zx::channel channel, async_dispatcher_t* dispatcher) {
is_requested = true;
}),
fuchsia::mediacodec::CodecFactory::Name_);
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html?autoplay");
navigation_listener_->RunUntilTitleEquals("ended");
EXPECT_TRUE(is_requested);
}
// Check that the CodecFactory service is not requested when
// HARDWARE_VIDEO_DECODER is not provided.
// The video should use software decoders and still play.
TEST_F(WebEngineIntegrationTest, HardwareVideoDecoderFlag_NotProvided) {
fuchsia::web::CreateContextParams create_params =
ContextParamsWithAudioAndTestData();
CreateContextAndFrame(std::move(create_params));
bool is_requested = false;
filtered_service_directory_->outgoing_directory()->AddPublicService(
std::make_unique<vfs::Service>(
[&is_requested](zx::channel channel, async_dispatcher_t* dispatcher) {
is_requested = true;
}),
fuchsia::mediacodec::CodecFactory::Name_);
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_video.html?autoplay");
navigation_listener_->RunUntilTitleEquals("ended");
EXPECT_FALSE(is_requested);
}
......@@ -237,7 +237,9 @@ fuchsia::web::CreateContextParams CastRunner::GetCommonContextParams() {
if (disable_vulkan_for_test_) {
*params.mutable_features() &=
~(fuchsia::web::ContextFeatureFlags::WIDEVINE_CDM |
fuchsia::web::ContextFeatureFlags::VULKAN);
fuchsia::web::ContextFeatureFlags::VULKAN |
fuchsia::web::ContextFeatureFlags::HARDWARE_VIDEO_DECODER |
fuchsia::web::ContextFeatureFlags::HARDWARE_VIDEO_DECODER_ONLY);
params.clear_playready_key_system();
}
......
......@@ -24,6 +24,8 @@
#endif
#if defined(OS_FUCHSIA)
// TODO(crbug.com/1117629): Remove this dependency and update include_rules
// that allow it.
#include "fuchsia/engine/switches.h"
#include "media/filters/fuchsia/fuchsia_video_decoder.h"
#endif
......@@ -119,7 +121,8 @@ void DefaultDecoderFactory::CreateVideoDecoders(
}
#if defined(OS_FUCHSIA)
if (gpu_factories) {
// TODO(crbug.com/1122116): Minimize Fuchsia-specific code paths.
if (gpu_factories && gpu_factories->IsGpuVideoAcceleratorEnabled()) {
auto* context_provider = gpu_factories->GetMediaContextProvider();
// GetMediaContextProvider() may return nullptr when the context was lost
......@@ -135,7 +138,7 @@ void DefaultDecoderFactory::CreateVideoDecoders(
context_provider->ContextSupport()));
} else {
DLOG(ERROR)
<< "Can't created FuchsiaVideoDecoder due to GPU context loss.";
<< "Can't create FuchsiaVideoDecoder due to GPU context loss.";
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment