diff --git a/cobalt/android/apk/app/src/main/java/dev/cobalt/coat/CobaltActivity.java b/cobalt/android/apk/app/src/main/java/dev/cobalt/coat/CobaltActivity.java index 15477ec2539e..79b76ebc219e 100644 --- a/cobalt/android/apk/app/src/main/java/dev/cobalt/coat/CobaltActivity.java +++ b/cobalt/android/apk/app/src/main/java/dev/cobalt/coat/CobaltActivity.java @@ -79,6 +79,9 @@ public abstract class CobaltActivity extends Activity { private static final Pattern URL_PARAM_PATTERN = Pattern.compile("^[a-zA-Z0-9_=]*$"); + // Media switch - media_switches::kDisableStarboardRenderer + private static final String DISABLE_STARBOARD_RENDERER_SWITCH = "disable-starboard-renderer"; + public static final int JAVA_BRIDGE_INITIALIZATION_DELAY_MILLI_SECONDS = 100; // Maintain the list of JavaScript-exposed objects as a member variable // to prevent them from being garbage collected prematurely. @@ -345,9 +348,15 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); createContent(savedInstanceState); - videoSurfaceView = new VideoSurfaceView(this); - addContentView( - videoSurfaceView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); + if (CommandLine.getInstance().hasSwitch(DISABLE_STARBOARD_RENDERER_SWITCH)) { + // TODO(b/326827007): Revisit renderer to support secondary videos. + Log.d(TAG, "Disable starboard renderer."); + } else { + Log.d(TAG, "Enable starboard renderer."); + videoSurfaceView = new VideoSurfaceView(this); + addContentView( + videoSurfaceView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); + } initializeJavaBridge(); } diff --git a/components/viz/service/display/overlay_processor_android.cc b/components/viz/service/display/overlay_processor_android.cc index 874dd2e3bad6..122a43ca545a 100644 --- a/components/viz/service/display/overlay_processor_android.cc +++ b/components/viz/service/display/overlay_processor_android.cc @@ -18,6 +18,7 @@ #include "ui/gfx/geometry/rect_conversions.h" #if BUILDFLAG(USE_STARBOARD_MEDIA) +#include "media/base/media_switches.h" #include "components/viz/service/display/starboard/overlay_strategy_underlay_starboard.h" #endif // BUILDFLAG(USE_STARBOARD_MEDIA) @@ -60,7 +61,13 @@ OverlayProcessorAndroid::OverlayProcessorAndroid( // a dummy resource that has no relation to what the overlay contains. // https://crbug.com/842931 . #if BUILDFLAG(USE_STARBOARD_MEDIA) - strategies_.push_back(std::make_unique(this)); + if (media::IsStarboardRendererEnabled()) { + strategies_.push_back( + std::make_unique(this)); + } else { + strategies_.push_back(std::make_unique( + this, OverlayStrategyUnderlay::OpaqueMode::AllowTransparentCandidates)); + } #else // BUILDFLAG(USE_STARBOARD_MEDIA) strategies_.push_back(std::make_unique( this, OverlayStrategyUnderlay::OpaqueMode::AllowTransparentCandidates)); diff --git a/content/renderer/media/media_factory.cc b/content/renderer/media/media_factory.cc index 6e160181d052..8ddbaecf6375 100644 --- a/content/renderer/media/media_factory.cc +++ b/content/renderer/media/media_factory.cc @@ -94,6 +94,7 @@ #include "media/mojo/clients/mojo_fuchsia_cdm_provider.h" #elif BUILDFLAG(USE_STARBOARD_MEDIA) #include "media/starboard/starboard_cdm_factory.h" +#include "media/starboard/starboard_renderer_factory.h" #elif BUILDFLAG(ENABLE_MOJO_CDM) #include "media/mojo/clients/mojo_cdm_factory.h" // nogncheck #else @@ -742,6 +743,17 @@ MediaFactory::CreateRendererFactorySelector( } #endif // BUILDFLAG(IS_CASTOS) || BUILDFLAG(IS_CAST_ANDROID) +#if BUILDFLAG(USE_STARBOARD_MEDIA) + if (!is_base_renderer_factory_set && media::IsStarboardRendererEnabled()) { + // TODO(b/326827007): Revisit renderer to support secondary videos. + is_base_renderer_factory_set = true; + factory_selector->AddFactory( + RendererType::kStarboard, + std::make_unique()); + factory_selector->SetBaseRendererType(RendererType::kStarboard); + } +#endif // BUILDFLAG(USE_STARBOARD_MEDIA) + if (!is_base_renderer_factory_set) { // TODO(crbug.com/1265448): These sorts of checks shouldn't be necessary if // this method were significantly refactored to split things up by diff --git a/content/renderer/media/media_permission_dispatcher.cc b/content/renderer/media/media_permission_dispatcher.cc index e79a4f13b1f3..6bae480fb2f6 100644 --- a/content/renderer/media/media_permission_dispatcher.cc +++ b/content/renderer/media/media_permission_dispatcher.cc @@ -11,6 +11,10 @@ #include "third_party/blink/public/web/web_local_frame.h" #include "url/gurl.h" +#if BUILDFLAG(USE_STARBOARD_MEDIA) +#include "media/base/media_switches.h" +#endif // BUILDFLAG(USE_STARBOARD_MEDIA) + namespace { using Type = media::MediaPermission::Type; @@ -150,7 +154,8 @@ void MediaPermissionDispatcher::OnPermissionStatus( requests_.erase(iter); #if BUILDFLAG(USE_STARBOARD_MEDIA) - std::move(permission_status_cb).Run(true); + // DRM is only supported using StarboardRenderer. + std::move(permission_status_cb).Run(media::IsStarboardRendererEnabled()); #else // BUILDFLAG(USE_STARBOARD_MEDIA) std::move(permission_status_cb) .Run(status == blink::mojom::PermissionStatus::GRANTED); diff --git a/media/base/media_switches.cc b/media/base/media_switches.cc index b8f748b18365..770d4257c758 100644 --- a/media/base/media_switches.cc +++ b/media/base/media_switches.cc @@ -240,6 +240,11 @@ MEDIA_EXPORT extern const char kLacrosUseChromeosProtectedAv1[] = "lacros-use-chromeos-protected-av1"; #endif // BUILDFLAG(IS_CHROMEOS) +#if BUILDFLAG(USE_STARBOARD_MEDIA) +// Force media player using default Renderer instead of StarboardRenderer. +const char kDisableStarboardRenderer[] = "disable-starboard-renderer"; +#endif // BUILDFLAG(USE_STARBOARD_MEDIA) + namespace autoplay { // Autoplay policy that requires a document user activation. @@ -1550,4 +1555,14 @@ uint32_t GetPassthroughAudioFormats() { #endif // BUILDFLAG(ENABLE_PASSTHROUGH_AUDIO_CODECS) } +#if BUILDFLAG(USE_STARBOARD_MEDIA) +bool IsStarboardRendererEnabled() { + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableStarboardRenderer)) { + return false; + } + return true; +} +#endif // BUILDFLAG(USE_STARBOARD_MEDIA) + } // namespace media diff --git a/media/base/media_switches.h b/media/base/media_switches.h index 43265d6c016d..c37b411e05f1 100644 --- a/media/base/media_switches.h +++ b/media/base/media_switches.h @@ -99,6 +99,10 @@ MEDIA_EXPORT extern const char kLacrosUseChromeosProtectedMedia[]; MEDIA_EXPORT extern const char kLacrosUseChromeosProtectedAv1[]; #endif // BUILDFLAG(IS_CHROMEOS) +#if BUILDFLAG(USE_STARBOARD_MEDIA) +MEDIA_EXPORT extern const char kDisableStarboardRenderer[]; +#endif // BUILDFLAG(USE_STARBOARD_MEDIA) + namespace autoplay { MEDIA_EXPORT extern const char kDocumentUserActivationRequiredPolicy[]; @@ -446,6 +450,10 @@ MEDIA_EXPORT bool IsMediaFoundationD3D11VideoCaptureEnabled(); MEDIA_EXPORT bool IsOutOfProcessVideoDecodingEnabled(); #endif // BUILDFLAG(ALLOW_OOP_VIDEO_DECODER) +#if BUILDFLAG(USE_STARBOARD_MEDIA) +MEDIA_EXPORT bool IsStarboardRendererEnabled(); +#endif // BUILDFLAG(USE_STARBOARD_MEDIA) + enum class kCrosGlobalMediaControlsPinOptions { kPin, kNotPin, diff --git a/media/base/renderer.cc b/media/base/renderer.cc index 3c39c5401372..adb75dd6f1b3 100644 --- a/media/base/renderer.cc +++ b/media/base/renderer.cc @@ -33,6 +33,10 @@ std::string GetRendererName(RendererType renderer_type) { return "EmbedderDefined"; case RendererType::kTest: return "Media Renderer Implementation For Testing"; +#if BUILDFLAG(USE_STARBOARD_MEDIA) + case RendererType::kStarboard: + return "StarboardRenderer"; +#endif // BUILDFLAG(USE_STARBOARD_MEDIA) } } diff --git a/media/base/renderer.h b/media/base/renderer.h index 4dcd53329bd2..0ea111a73c5d 100644 --- a/media/base/renderer.h +++ b/media/base/renderer.h @@ -36,7 +36,12 @@ enum class RendererType { kCastStreaming = 9, // PlaybackCommandForwardingRendererFactory kContentEmbedderDefined = 10, // Defined by the content embedder kTest = 11, // Renderer implementations used in tests +#if BUILDFLAG(USE_STARBOARD_MEDIA) + kStarboard = 12, // StarboardRendererFactory + kMaxValue = kStarboard, +#else // BUILDFLAG(USE_STARBOARD_MEDIA) kMaxValue = kTest, +#endif // BUILDFLAG(USE_STARBOARD_MEDIA) }; // Get the name of the Renderer for `renderer_type`. The returned name could be diff --git a/media/mojo/mojom/BUILD.gn b/media/mojo/mojom/BUILD.gn index 1214f486e5c6..1a09573d1801 100644 --- a/media/mojo/mojom/BUILD.gn +++ b/media/mojo/mojom/BUILD.gn @@ -5,6 +5,10 @@ import("//media/media_options.gni") import("//mojo/public/tools/bindings/mojom.gni") +if (is_cobalt) { + import("//starboard/build/buildflags.gni") +} + mojom("mojom") { generate_java = true @@ -123,6 +127,10 @@ mojom("mojom") { enabled_features += [ "enable_cast_renderer" ] } + if (is_cobalt && use_starboard_media) { + enabled_features += [ "use_starboard_media" ] + } + shared_typemaps = [ { types = [ diff --git a/media/mojo/mojom/media_types.mojom b/media/mojo/mojom/media_types.mojom index 71336585acfb..bcce011370e7 100644 --- a/media/mojo/mojom/media_types.mojom +++ b/media/mojo/mojom/media_types.mojom @@ -535,4 +535,6 @@ enum RendererType { kCastStreaming = 9, // CastStreamingRendererFactory kContentEmbedderDefined = 10, // Defined by the content embedder kTest= 11, // Renderer implementations used in tests + [EnableIf=use_starboard_media] + kStarboard = 12, // StarboardRendererFactory }; diff --git a/media/mojo/mojom/media_types_enum_mojom_traits.h b/media/mojo/mojom/media_types_enum_mojom_traits.h index 237b91b97bba..8d3d07461b3a 100644 --- a/media/mojo/mojom/media_types_enum_mojom_traits.h +++ b/media/mojo/mojom/media_types_enum_mojom_traits.h @@ -315,6 +315,10 @@ struct EnumTraits { return media::mojom::RendererType::kContentEmbedderDefined; case ::media::RendererType::kTest: return media::mojom::RendererType::kTest; +#if BUILDFLAG(USE_STARBOARD_MEDIA) + case ::media::RendererType::kStarboard: + return media::mojom::RendererType::kStarboard; +#endif // BUILDFLAG(USE_STARBOARD_MEDIA) } NOTREACHED(); @@ -359,6 +363,11 @@ struct EnumTraits { case media::mojom::RendererType::kTest: *output = ::media::RendererType::kTest; return true; +#if BUILDFLAG(USE_STARBOARD_MEDIA) + case media::mojom::RendererType::kStarboard: + *output = ::media::RendererType::kStarboard; + return true; +#endif // BUILDFLAG(USE_STARBOARD_MEDIA) } NOTREACHED(); diff --git a/media/starboard/BUILD.gn b/media/starboard/BUILD.gn index 9f860dfdb446..f1d176588fd3 100644 --- a/media/starboard/BUILD.gn +++ b/media/starboard/BUILD.gn @@ -76,6 +76,8 @@ source_set("starboard") { "starboard_memory_allocator.h", "starboard_renderer.cc", "starboard_renderer.h", + "starboard_renderer_factory.cc", + "starboard_renderer_factory.h", "starboard_utils.cc", "starboard_utils.h", ] diff --git a/media/starboard/starboard_renderer_factory.cc b/media/starboard/starboard_renderer_factory.cc new file mode 100644 index 000000000000..0a08fbbbe1b6 --- /dev/null +++ b/media/starboard/starboard_renderer_factory.cc @@ -0,0 +1,42 @@ +// Copyright 2024 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "media/starboard/starboard_renderer_factory.h" + +#include + +#include "base/check.h" +#include "base/logging.h" +#include "base/task/sequenced_task_runner.h" +#include "media/starboard/starboard_renderer.h" + +namespace media { + +StarboardRendererFactory::StarboardRendererFactory() {} + +StarboardRendererFactory::~StarboardRendererFactory() = default; + +std::unique_ptr StarboardRendererFactory::CreateRenderer( + const scoped_refptr& media_task_runner, + const scoped_refptr& worker_task_runner, + AudioRendererSink* audio_renderer_sink, + VideoRendererSink* video_renderer_sink, + RequestOverlayInfoCB request_overlay_info_cb, + const gfx::ColorSpace& target_color_space) { + DCHECK(video_renderer_sink); + return std::make_unique(media_task_runner, + video_renderer_sink); +} + +} // namespace media diff --git a/media/starboard/starboard_renderer_factory.h b/media/starboard/starboard_renderer_factory.h new file mode 100644 index 000000000000..ccf82cea0fd6 --- /dev/null +++ b/media/starboard/starboard_renderer_factory.h @@ -0,0 +1,44 @@ +// Copyright 2024 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef MEDIA_STARBOARD_STARBOARD_RENDERER_FACTORY_H_ +#define MEDIA_STARBOARD_STARBOARD_RENDERER_FACTORY_H_ + +#include "base/task/sequenced_task_runner.h" +#include "media/base/renderer_factory.h" + +namespace media { + +// Creates Renderers using Starboard. +class MEDIA_EXPORT StarboardRendererFactory final : public RendererFactory { + public: + StarboardRendererFactory(); + + StarboardRendererFactory(const StarboardRendererFactory&) = delete; + StarboardRendererFactory& operator=(const StarboardRendererFactory&) = delete; + + ~StarboardRendererFactory() final; + + std::unique_ptr CreateRenderer( + const scoped_refptr& media_task_runner, + const scoped_refptr& worker_task_runner, + AudioRendererSink* audio_renderer_sink, + VideoRendererSink* video_renderer_sink, + RequestOverlayInfoCB request_overlay_info_cb, + const gfx::ColorSpace& target_color_space) final; +}; + +} // namespace media + +#endif // MEDIA_STARBOARD_STARBOARD_RENDERER_FACTORY_H_ diff --git a/third_party/blink/renderer/platform/media/web_media_player_impl.cc b/third_party/blink/renderer/platform/media/web_media_player_impl.cc index 2750e4de13d1..7b9e29eaff13 100644 --- a/third_party/blink/renderer/platform/media/web_media_player_impl.cc +++ b/third_party/blink/renderer/platform/media/web_media_player_impl.cc @@ -2807,21 +2807,6 @@ std::unique_ptr WebMediaPlayerImpl::CreateRenderer( &WebMediaPlayerImpl::OnOverlayInfoRequested, weak_this_)); #endif -#if BUILDFLAG(USE_STARBOARD_MEDIA) - // TODO(b/375278384): Select the StarboardRenderer properly instead of - // hard coding. - - // StarboardRenderer always uses full screen with overlay video mode. - overlay_info_.is_fullscreen = true; - - // `media_task_runner_` is always true, use an if statement to avoid - // potential build warning on unreachable code. - if (media_task_runner_) { - return std::make_unique(media_task_runner_, - compositor_.get()); - } -#endif // BUILDFLAG(USE_STARBOARD_MEDIA) - if (renderer_type) { DVLOG(1) << __func__ << ": renderer_type=" << static_cast(renderer_type.value()); @@ -2838,6 +2823,14 @@ std::unique_ptr WebMediaPlayerImpl::CreateRenderer( media_metrics_provider_->SetRendererType(renderer_type_); media_log_->SetProperty(renderer_type_); +#if BUILDFLAG(USE_STARBOARD_MEDIA) + LOG(INFO) << "Renderer Type is " << GetRendererName(renderer_type_) << "."; + if (renderer_type_ == media::RendererType::kStarboard) { + // StarboardRenderer always uses full screen with overlay video mode. + overlay_info_.is_fullscreen = true; + } +#endif // BUILDFLAG(USE_STARBOARD_MEDIA) + return renderer_factory_selector_->GetCurrentFactory()->CreateRenderer( media_task_runner_, worker_task_runner_, audio_source_provider_.get(), compositor_.get(), std::move(request_overlay_info_cb), diff --git a/tools/metrics/histograms/enums.xml b/tools/metrics/histograms/enums.xml index cf788e89061e..f456cc502309 100644 --- a/tools/metrics/histograms/enums.xml +++ b/tools/metrics/histograms/enums.xml @@ -68501,6 +68501,8 @@ Called by update_use_counter_css.py.--> + +