Skip to content

Commit

Permalink
[Fuchsia] Stop using mediacodec.CodecFactory in renderer process
Browse files Browse the repository at this point in the history
Added CreateVideoDecoder method to the FuchsiaMediaResourceProvider
interface. The renderer process uses it to connect StreamProcessor
for hardware decoder. This allows to avoid exposing
fuchsia.mediacodec.CodecFactory to the renderer process.

Bug: 1293605
Change-Id: Iefbeb63ecd11d28edca919a151c37a415164841d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3556806
Reviewed-by: Dan Sanders <sandersd@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: David Dorwin <ddorwin@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Peng Huang <penghuang@chromium.org>
Commit-Queue: David Dorwin <ddorwin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1001190}
  • Loading branch information
SergeyUlanov authored and Chromium LUCI CQ committed May 9, 2022
1 parent a2887f1 commit c2956da
Show file tree
Hide file tree
Showing 24 changed files with 367 additions and 169 deletions.
6 changes: 1 addition & 5 deletions chrome/app/chrome.cml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@
"fuchsia.media.Audio",
"fuchsia.media.AudioDeviceEnumerator",
"fuchsia.media.ProfileProvider",

// TODO(crbug.com/1293605): Do not provide this until the
// delegation issue is resolved.
// "fuchsia.mediacodec.CodecFactory",

"fuchsia.mediacodec.CodecFactory",
"fuchsia.memorypressure.Provider",
"fuchsia.net.interfaces.State",
"fuchsia.net.name.Lookup",
Expand Down
1 change: 1 addition & 0 deletions content/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2486,6 +2486,7 @@ source_set("browser") {
"//media/fuchsia/mojom:fuchsia_media_resource_provider",
"//third_party/abseil-cpp:absl",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.accessibility.semantics",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.mediacodec",
"//third_party/fuchsia-sdk/sdk/pkg/inspect",
"//third_party/fuchsia-sdk/sdk/pkg/scenic_cpp",
"//third_party/fuchsia-sdk/sdk/pkg/sys_inspect_cpp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,55 @@

#include "content/browser/renderer_host/media/media_resource_provider_fuchsia.h"

#include <fuchsia/mediacodec/cpp/fidl.h>
#include <lib/sys/cpp/component_context.h>

#include "base/bind.h"
#include "base/command_line.h"
#include "base/fuchsia/process_context.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/provision_fetcher_factory.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h"
#include "media/base/media_switches.h"
#include "media/base/provision_fetcher.h"
#include "media/fuchsia/cdm/service/fuchsia_cdm_manager.h"

namespace content {

namespace {

absl::optional<std::string> GetMimeTypeForVideoCodec(media::VideoCodec codec) {
switch (codec) {
case media::VideoCodec::kH264:
return "video/h264";
case media::VideoCodec::kVP8:
return "video/vp8";
case media::VideoCodec::kVP9:
return "video/vp9";
case media::VideoCodec::kHEVC:
return "video/hevc";
case media::VideoCodec::kAV1:
return "video/av1";

case media::VideoCodec::kVC1:
case media::VideoCodec::kMPEG2:
case media::VideoCodec::kMPEG4:
case media::VideoCodec::kTheora:
case media::VideoCodec::kDolbyVision:
return absl::nullopt;

case media::VideoCodec::kUnknown:
break;
}

NOTREACHED();
return absl::nullopt;
}

} // namespace

// static
void MediaResourceProviderFuchsia::Bind(
content::RenderFrameHost* frame_host,
Expand Down Expand Up @@ -53,4 +90,48 @@ void MediaResourceProviderFuchsia::CreateCdm(
key_system, origin(), std::move(create_fetcher_cb), std::move(request));
}

void MediaResourceProviderFuchsia::CreateVideoDecoder(
media::VideoCodec codec,
bool secure_mode,
fidl::InterfaceRequest<fuchsia::media::StreamProcessor>
stream_processor_request) {
fuchsia::mediacodec::CreateDecoder_Params decoder_params;

// Set format details ordinal to 0. Decoder doesn't change the format, so
// the value doesn't matter.
decoder_params.mutable_input_details()->set_format_details_version_ordinal(0);

auto mime_type = GetMimeTypeForVideoCodec(codec);
if (!mime_type) {
// Drop `stream_processor_request` if the codec is not supported.
return;
}
decoder_params.mutable_input_details()->set_mime_type(mime_type.value());

if (secure_mode) {
decoder_params.set_secure_input_mode(
fuchsia::mediacodec::SecureMemoryMode::ON);
}

if (secure_mode || base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kForceProtectedVideoOutputBuffers)) {
decoder_params.set_secure_output_mode(
fuchsia::mediacodec::SecureMemoryMode::ON);
}

// Video demuxers return each video frame in a separate packet. This field
// must be set to get frame timestamps on the decoder output.
decoder_params.set_promise_separate_access_units_on_input(true);

// We use `fuchsia.mediacodec` only for hardware decoders. Renderer will
// handle software decoding if hardware decoder is not available.
decoder_params.set_require_hw(true);

auto decoder_factory = base::ComponentContextForProcess()
->svc()
->Connect<fuchsia::mediacodec::CodecFactory>();
decoder_factory->CreateDecoder(std::move(decoder_params),
std::move(stream_processor_request));
}

} // namespace content
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class MediaResourceProviderFuchsia final
const std::string& key_system,
fidl::InterfaceRequest<fuchsia::media::drm::ContentDecryptionModule>
request) final;
void CreateVideoDecoder(
media::VideoCodec codec,
bool secure_memory,
fidl::InterfaceRequest<fuchsia::media::StreamProcessor>
stream_processor_request) final;
};

} // namespace content
Expand Down
1 change: 1 addition & 0 deletions content/renderer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ target(link_target_type, "renderer") {

deps += [
"//media/fuchsia/cdm/client",
"//media/fuchsia/video",
"//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
]
}
Expand Down
4 changes: 4 additions & 0 deletions content/renderer/media/media_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@

#if BUILDFLAG(IS_FUCHSIA)
#include "media/fuchsia/cdm/client/fuchsia_cdm_util.h"
#include "media/fuchsia/video/fuchsia_decoder_factory.h"
#elif BUILDFLAG(ENABLE_MOJO_CDM)
#include "media/mojo/clients/mojo_cdm_factory.h" // nogncheck
#else
Expand Down Expand Up @@ -788,6 +789,9 @@ base::WeakPtr<media::DecoderFactory> MediaFactory::GetDecoderFactory() {
GetMediaInterfaceFactory();
external_decoder_factory =
std::make_unique<media::MojoDecoderFactory>(interface_factory);
#elif BUILDFLAG(IS_FUCHSIA)
external_decoder_factory =
std::make_unique<media::FuchsiaDecoderFactory>(interface_broker_);
#endif
decoder_factory_ = std::make_unique<media::DefaultDecoderFactory>(
std::move(external_decoder_factory));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ void WebEngineContentBrowserClient::AppendExtraCommandLineSwitches(
switches::kEnableContentDirectories,
switches::kEnableProtectedVideoBuffers,
switches::kEnableWidevine,
switches::kForceProtectedVideoOutputBuffers,
switches::kMaxDecodedImageSizeMb,
switches::kPlayreadyKeySystem,
network::switches::kUnsafelyTreatInsecureOriginAsSecure,
Expand Down
1 change: 1 addition & 0 deletions media/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ test("media_unittests") {
deps += [
"//media/fuchsia/audio:unittests",
"//media/fuchsia/cdm/service:unittests",
"//media/fuchsia/video:unittests",
]

use_cfv2 = false
Expand Down
32 changes: 0 additions & 32 deletions media/filters/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -237,26 +237,6 @@ source_set("filters") {
"h264_bitstream_buffer.h",
]
}

if (is_fuchsia) {
sources += [
"fuchsia/fuchsia_video_decoder.cc",
"fuchsia/fuchsia_video_decoder.h",
]
public_deps = [ "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.media" ]
deps += [
"//components/viz/common",
"//gpu/command_buffer/client",
"//gpu/command_buffer/common",
"//gpu/ipc/common",
"//media/fuchsia/cdm",
"//media/fuchsia/common",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.mediacodec",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.sysmem",
"//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
"//ui/ozone",
]
}
}

source_set("perftests") {
Expand Down Expand Up @@ -345,18 +325,6 @@ source_set("unit_tests") {
deps += [ "//ui/gl" ]
}

if (is_fuchsia) {
sources += [ "fuchsia/fuchsia_video_decoder_unittest.cc" ]
deps += [
"//components/viz/common",
"//components/viz/test:test_support",
"//gpu/command_buffer/client",
"//gpu/config",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.sysmem",
"//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
]
}

# libvpx for running vpx test on chromecast doesn't support high bit depth.
# This may cause some unit tests failure.
if (is_chromecast) {
Expand Down
9 changes: 0 additions & 9 deletions media/filters/fuchsia/DIR_METADATA

This file was deleted.

7 changes: 7 additions & 0 deletions media/fuchsia/mojom/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import("//mojo/public/tools/bindings/mojom.gni")

mojom("fuchsia_media_resource_provider") {
sources = [ "fuchsia_media_resource_provider.mojom" ]
deps = [ "//media/mojo/mojom" ]

export_class_attribute_blink = "BLINK_PLATFORM_EXPORT"
export_define_blink = "BLINK_PLATFORM_IMPLEMENTATION=1"
Expand All @@ -18,10 +19,16 @@ mojom("fuchsia_media_resource_provider") {
cpp = "::fidl::InterfaceRequest<::fuchsia::media::drm::ContentDecryptionModule>"
move_only = true
},
{
mojom = "media.mojom.StreamProcessorRequest"
cpp = "::fidl::InterfaceRequest<::fuchsia::media::StreamProcessor>"
move_only = true
},
]
traits_headers = [ "fuchsia_media_resource_provider_mojom_traits.h" ]
traits_public_deps = [
"//mojo/public/cpp/base/fuchsia:traits",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.media",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.media.drm",
]
}
Expand Down
16 changes: 14 additions & 2 deletions media/fuchsia/mojom/fuchsia_media_resource_provider.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,29 @@

module media.mojom;

import "media/mojo/mojom/media_types.mojom";

// Mojo struct for
// fidl::InterfaceRequest<fuchsia::media::drm::ContentDecryptionModule>.
// `fidl::InterfaceRequest<fuchsia::media::drm::ContentDecryptionModule>`.
struct CdmRequest {
handle<platform> request;
};

// Mojo struct for `fidl::InterfaceRequest<fuchsia::media::StreamProcessor>`.
struct StreamProcessorRequest {
handle<platform> request;
};

// Interface used by the renderer to connect to CDM and mediacodec resources.
// Instances are document-scoped.
interface FuchsiaMediaResourceProvider {
// Create connection to fuchsia::media::drm::ContentDecryptionModule for
// |key_system|. Implementation should make sure the persistent storage is
// `key_system`. Implementation should make sure the persistent storage is
// isolated per web origin.
CreateCdm(string key_system, CdmRequest cdm_request);

// Create connection to fuchsia::media::StreamProcessor for the specified
// `codec`.
CreateVideoDecoder(VideoCodec codec, bool secure_memory,
StreamProcessorRequest stream_processor_request);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef MEDIA_FUCHSIA_MOJOM_FUCHSIA_MEDIA_RESOURCE_PROVIDER_MOJOM_TRAITS_H_
#define MEDIA_FUCHSIA_MOJOM_FUCHSIA_MEDIA_RESOURCE_PROVIDER_MOJOM_TRAITS_H_

#include <fuchsia/media/cpp/fidl.h>
#include <fuchsia/media/drm/cpp/fidl.h>

#include "mojo/public/cpp/base/fuchsia/fidl_interface_request_mojom_traits.h"
Expand All @@ -19,6 +20,13 @@ struct StructTraits<
media::mojom::CdmRequestDataView,
fuchsia::media::drm::ContentDecryptionModule> {};

template <>
struct StructTraits<media::mojom::StreamProcessorRequestDataView,
fidl::InterfaceRequest<fuchsia::media::StreamProcessor>>
: public FidlInterfaceRequestStructTraits<
media::mojom::StreamProcessorRequestDataView,
fuchsia::media::StreamProcessor> {};

} // namespace mojo

#endif // MEDIA_FUCHSIA_MOJOM_FUCHSIA_MEDIA_RESOURCE_PROVIDER_MOJOM_TRAITS_H_
52 changes: 52 additions & 0 deletions media/fuchsia/video/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2022 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

source_set("video") {
visibility = [
":unittests",
"//content/renderer/*",
]
sources = [
"fuchsia_decoder_factory.cc",
"fuchsia_decoder_factory.h",
"fuchsia_video_decoder.cc",
"fuchsia_video_decoder.h",
]
public_deps = [ "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.media" ]
deps = [
"//components/viz/common",
"//gpu/command_buffer/client",
"//gpu/command_buffer/common",
"//gpu/ipc/common",
"//media/fuchsia/cdm",
"//media/fuchsia/common",
"//media/fuchsia/mojom:fuchsia_media_resource_provider",
"//third_party/blink/public/common",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.mediacodec",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.sysmem",
"//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
"//ui/ozone",
]
}

source_set("unittests") {
testonly = true
sources = [ "fuchsia_video_decoder_unittest.cc" ]
deps = [
":video",
"//base/test:test_support",
"//components/viz/common",
"//components/viz/test:test_support",
"//gpu/command_buffer/client",
"//gpu/config",
"//media:test_support",
"//media/fuchsia/mojom:fuchsia_media_resource_provider",
"//testing/gmock",
"//testing/gtest",
"//third_party/blink/public/common",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.mediacodec",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.sysmem",
"//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
]
}
2 changes: 2 additions & 0 deletions media/filters/fuchsia/DEPS → media/fuchsia/video/DEPS
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include_rules = [
"+components/viz/common/gpu/raster_context_provider.h",
"+mojo/public",
"+third_party/blink/public",
]
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
sergeyu@chromium.org
file://build/fuchsia/OWNERS
Loading

0 comments on commit c2956da

Please sign in to comment.