Skip to content

Commit

Permalink
Reland "Onion soup FuchsiaAudioDeviceFactory"
Browse files Browse the repository at this point in the history
This is a reland of e511a14

Change from the original CL:

- `BLINK_MODULES_EXPORT` added to the FuchsiaAudioDeviceFactory
  class declaration (fixes the linking problem locally for
  component builds).

TBR=haraken@chromium.org

Original change's description:
> Onion soup FuchsiaAudioDeviceFactory
>
> This CL executes phases 5 on the design document [1].
>
> [1] https://docs.google.com/document/d/19Zk6Fv1E-6QTQ2c33rpBjDNEkzlsSKvjb3hWkvZAE80/
>
> It also adds triggers the generation of blink bindings by
> //media//fuchsia/mojom.
>
> BUG=787252
> R=guidou@chromium.org, haraken@chromium.org
>
> Change-Id: Ic2a1ffaea1f9647d9c2c18d298fc23c58d5cc5bb
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2436749
> Commit-Queue: Antonio Gomes (GMT-4) <tonikitoo@igalia.com>
> Reviewed-by: Kentaro Hara <haraken@chromium.org>
> Reviewed-by: Guido Urdaneta <guidou@chromium.org>
> Reviewed-by: Sergey Ulanov <sergeyu@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#812057}

Bug: 787252
Change-Id: If5d205e84c2a27842303566e03c568fb8e6c87c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441148
Reviewed-by: Guido Urdaneta <guidou@chromium.org>
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Commit-Queue: Antonio Gomes (GMT-4) <tonikitoo@igalia.com>
Auto-Submit: Antonio Gomes (GMT-4) <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#812329}
  • Loading branch information
tonikitoo authored and Commit Bot committed Sep 30, 2020
1 parent 8b291c5 commit c0e2864
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 67 deletions.
2 changes: 0 additions & 2 deletions content/renderer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,6 @@ target(link_target_type, "renderer") {

if (is_fuchsia) {
sources += [
"media/audio/fuchsia_audio_device_factory.cc",
"media/audio/fuchsia_audio_device_factory.h",
"media/fuchsia_renderer_factory.cc",
"media/fuchsia_renderer_factory.h",
"render_view_fuchsia.cc",
Expand Down
5 changes: 3 additions & 2 deletions content/renderer/renderer_main_platform_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "content/public/common/main_function_params.h"

#if defined(OS_FUCHSIA)
#include "content/renderer/media/audio/fuchsia_audio_device_factory.h"
#include "third_party/blink/public/web/modules/media/audio/fuchsia_audio_device_factory.h"
#endif // defined(OS_FUCHSIA)

namespace content {
Expand All @@ -41,7 +41,8 @@ class CONTENT_EXPORT RendererMainPlatformDelegate {
#endif

#if defined(OS_FUCHSIA)
std::unique_ptr<FuchsiaAudioDeviceFactory> fuchsia_audio_device_factory_;
std::unique_ptr<blink::FuchsiaAudioDeviceFactory>
fuchsia_audio_device_factory_;
#endif // defined(OS_FUCHSIA)

DISALLOW_COPY_AND_ASSIGN(RendererMainPlatformDelegate);
Expand Down
3 changes: 2 additions & 1 deletion content/renderer/renderer_main_platform_delegate_fuchsia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ RendererMainPlatformDelegate::RendererMainPlatformDelegate(
RendererMainPlatformDelegate::~RendererMainPlatformDelegate() {}

void RendererMainPlatformDelegate::PlatformInitialize() {
fuchsia_audio_device_factory_ = std::make_unique<FuchsiaAudioDeviceFactory>();
fuchsia_audio_device_factory_ =
std::make_unique<blink::FuchsiaAudioDeviceFactory>();
}

void RendererMainPlatformDelegate::PlatformUninitialize() {
Expand Down
59 changes: 32 additions & 27 deletions media/fuchsia/mojom/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,36 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("mojom") {
sources = [ "fuchsia_media_resource_provider.mojom" ]

cpp_typemaps = [
{
types = [
{
mojom = "media.mojom.CdmRequest"
cpp = "::fidl::InterfaceRequest<::fuchsia::media::drm::ContentDecryptionModule>"
move_only = true
},
{
mojom = "media.mojom.AudioConsumerRequest"
cpp = "::fidl::InterfaceRequest<::fuchsia::media::AudioConsumer>"
move_only = true
},
{
mojom = "media.mojom.AudioCapturerRequest"
cpp = "::fidl::InterfaceRequest<::fuchsia::media::AudioCapturer>"
move_only = true
},
]
traits_headers = [ "fuchsia_media_resource_provider_mojom_traits.h" ]
traits_public_deps = [
"//fuchsia/mojom:traits",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.media",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.media.drm",
]
},
]
export_class_attribute_blink = "BLINK_PLATFORM_EXPORT"
export_define_blink = "BLINK_PLATFORM_IMPLEMENTATION=1"
export_header_blink = "third_party/blink/public/platform/web_common.h"

shared_cpp_typemaps = {
types = [
{
mojom = "media.mojom.CdmRequest"
cpp = "::fidl::InterfaceRequest<::fuchsia::media::drm::ContentDecryptionModule>"
move_only = true
},
{
mojom = "media.mojom.AudioConsumerRequest"
cpp = "::fidl::InterfaceRequest<::fuchsia::media::AudioConsumer>"
move_only = true
},
{
mojom = "media.mojom.AudioCapturerRequest"
cpp = "::fidl::InterfaceRequest<::fuchsia::media::AudioCapturer>"
move_only = true
},
]
traits_headers = [ "fuchsia_media_resource_provider_mojom_traits.h" ]
traits_public_deps = [
"//fuchsia/mojom:traits",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.media",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.media.drm",
]
}

cpp_typemaps = [ shared_cpp_typemaps ]
blink_cpp_typemaps = [ shared_cpp_typemaps ]
}
1 change: 1 addition & 0 deletions third_party/blink/public/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ source_set("blink_headers") {
"platform/websocket_handshake_throttle.h",
"web/blink.h",
"web/modules/autofill/web_form_element_observer.h",
"web/modules/media/audio/fuchsia_audio_device_factory.h",
"web/modules/media/audio/web_audio_device_factory.h",
"web/modules/media/audio/web_audio_input_ipc_factory.h",
"web/modules/media/audio/web_audio_output_ipc_factory.h",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,44 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_RENDERER_MEDIA_AUDIO_FUCHSIA_AUDIO_DEVICE_FACTORY_H_
#define CONTENT_RENDERER_MEDIA_AUDIO_FUCHSIA_AUDIO_DEVICE_FACTORY_H_
#ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_MODULES_MEDIA_AUDIO_FUCHSIA_AUDIO_DEVICE_FACTORY_H_
#define THIRD_PARTY_BLINK_PUBLIC_WEB_MODULES_MEDIA_AUDIO_FUCHSIA_AUDIO_DEVICE_FACTORY_H_

#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/platform/web_common.h"
#include "third_party/blink/public/web/modules/media/audio/web_audio_device_factory.h"

namespace content {
namespace blink {

class FuchsiaAudioDeviceFactory : public blink::WebAudioDeviceFactory {
// TODO(https://crbug.com/787252): Move this class out of the Blink API layer.
class BLINK_MODULES_EXPORT FuchsiaAudioDeviceFactory
: public WebAudioDeviceFactory {
public:
FuchsiaAudioDeviceFactory();
~FuchsiaAudioDeviceFactory() final;

protected:
scoped_refptr<media::AudioRendererSink> CreateFinalAudioRendererSink(
const blink::LocalFrameToken& frame_token,
const LocalFrameToken& frame_token,
const media::AudioSinkParameters& params,
base::TimeDelta auth_timeout) final;

scoped_refptr<media::AudioRendererSink> CreateAudioRendererSink(
blink::WebAudioDeviceSourceType source_type,
const blink::LocalFrameToken& frame_token,
WebAudioDeviceSourceType source_type,
const LocalFrameToken& frame_token,
const media::AudioSinkParameters& params) final;

scoped_refptr<media::SwitchableAudioRendererSink>
CreateSwitchableAudioRendererSink(
blink::WebAudioDeviceSourceType source_type,
const blink::LocalFrameToken& frame_token,
WebAudioDeviceSourceType source_type,
const LocalFrameToken& frame_token,
const media::AudioSinkParameters& params) final;

scoped_refptr<media::AudioCapturerSource> CreateAudioCapturerSource(
const blink::LocalFrameToken& frame_token,
const LocalFrameToken& frame_token,
const media::AudioSourceParameters& params) final;
};

} // namespace content
} // namespace blink

#endif // CONTENT_RENDERER_MEDIA_AUDIO_FUCHSIA_AUDIO_DEVICE_FACTORY_H_
#endif // THIRD_PARTY_BLINK_PUBLIC_WEB_MODULES_MEDIA_AUDIO_FUCHSIA_AUDIO_DEVICE_FACTORY_H_
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ namespace blink {
// to provide specialized implementations.
// TODO(olka): rename it, probably split it into AudioRendererSinkFactory and
// AudioCapturerSourceFactory.
//
// TODO(https://crrev.com/787252): Add a 'Web' prefix to the class name.
class BLINK_MODULES_EXPORT WebAudioDeviceFactory {
public:
// Maps the source type to the audio latency it requires.
Expand Down
9 changes: 9 additions & 0 deletions third_party/blink/renderer/modules/media/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ blink_modules_sources("media") {
"audio/web_audio_output_ipc_factory.cc",
"webmediaplayer_util.cc",
]

if (is_fuchsia) {
sources += [ "audio/fuchsia_audio_device_factory.cc" ]

deps = [
"//media/fuchsia/audio",
"//media/fuchsia/mojom:mojom_blink",
]
}
}
4 changes: 4 additions & 0 deletions third_party/blink/renderer/modules/media/audio/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ specific_include_rules = {
"+base/test/test_mock_time_task_runner.h",
"+base/threading/thread.h",
],
"fuchsia_audio_device_factory\.cc" : [
"+media/fuchsia/audio/fuchsia_audio_capturer_source.h",
"+media/fuchsia/mojom",
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/renderer/media/audio/fuchsia_audio_device_factory.h"
#include "third_party/blink/public/web/modules/media/audio/fuchsia_audio_device_factory.h"

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

#include "content/public/renderer/render_frame.h"
#include "media/base/audio_renderer_sink.h"
#include "media/fuchsia/audio/fuchsia_audio_capturer_source.h"
#include "media/fuchsia/mojom/fuchsia_media_resource_provider.mojom.h"
#include "media/fuchsia/mojom/fuchsia_media_resource_provider.mojom-blink.h"
#include "media/fuchsia/mojom/fuchsia_media_resource_provider_mojom_traits.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/public/web/web_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"

namespace content {
namespace blink {

FuchsiaAudioDeviceFactory::FuchsiaAudioDeviceFactory() = default;
FuchsiaAudioDeviceFactory::~FuchsiaAudioDeviceFactory() = default;

scoped_refptr<media::AudioRendererSink>
FuchsiaAudioDeviceFactory::CreateFinalAudioRendererSink(
const blink::LocalFrameToken& frame_token,
const LocalFrameToken& frame_token,
const media::AudioSinkParameters& params,
base::TimeDelta auth_timeout) {
// Return nullptr to fallback to the default renderer implementation.
Expand All @@ -32,39 +31,34 @@ FuchsiaAudioDeviceFactory::CreateFinalAudioRendererSink(

scoped_refptr<media::AudioRendererSink>
FuchsiaAudioDeviceFactory::CreateAudioRendererSink(
blink::WebAudioDeviceSourceType source_type,
const blink::LocalFrameToken& frame_token,
WebAudioDeviceSourceType source_type,
const LocalFrameToken& frame_token,
const media::AudioSinkParameters& params) {
// Return nullptr to fallback to the default renderer implementation.
return nullptr;
}

scoped_refptr<media::SwitchableAudioRendererSink>
FuchsiaAudioDeviceFactory::CreateSwitchableAudioRendererSink(
blink::WebAudioDeviceSourceType source_type,
const blink::LocalFrameToken& frame_token,
WebAudioDeviceSourceType source_type,
const LocalFrameToken& frame_token,
const media::AudioSinkParameters& params) {
// Return nullptr to fallback to the default renderer implementation.
return nullptr;
}

scoped_refptr<media::AudioCapturerSource>
FuchsiaAudioDeviceFactory::CreateAudioCapturerSource(
const blink::LocalFrameToken& frame_token,
const LocalFrameToken& frame_token,
const media::AudioSourceParameters& params) {
blink::WebFrame* web_frame = blink::WebFrame::FromFrameToken(frame_token);
if (!web_frame)
return nullptr;

int render_frame_id = RenderFrame::GetRoutingIdForWebFrame(web_frame);
auto* render_frame = RenderFrame::FromRoutingID(render_frame_id);
if (!render_frame)
auto* local_frame = LocalFrame::FromFrameToken(frame_token);
if (!local_frame)
return nullptr;

// Connect FuchsiaMediaResourceProvider.
mojo::Remote<media::mojom::FuchsiaMediaResourceProvider>
mojo::Remote<media::mojom::blink::FuchsiaMediaResourceProvider>
media_resource_provider;
render_frame->GetBrowserInterfaceBroker()->GetInterface(
local_frame->GetBrowserInterfaceBroker().GetInterface(
media_resource_provider.BindNewPipeAndPassReceiver());

// Connect AudioCapturer.
Expand All @@ -75,4 +69,4 @@ FuchsiaAudioDeviceFactory::CreateAudioCapturerSource(
std::move(capturer));
}

} // namespace content
} // namespace blink
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,10 @@
'base::EraseIf',
'base::ScopedPlatformFile',
'mojo::WrapCallbackWithDefaultInvokeIfNotRun',

# TODO(https://crrev.com/787252): Consider allowlisting fidl::*
# usage more broadly in Blink.
'fidl::InterfaceHandle',
]
},
{
Expand Down

0 comments on commit c0e2864

Please sign in to comment.