Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[media] Add runtime flag to disable StarboardRenderer #4407

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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<OverlayStrategyUnderlayStarboard>(this));
if (media::IsStarboardRendererEnabled()) {
strategies_.push_back(
std::make_unique<OverlayStrategyUnderlayStarboard>(this));
} else {
strategies_.push_back(std::make_unique<OverlayStrategyUnderlay>(
this, OverlayStrategyUnderlay::OpaqueMode::AllowTransparentCandidates));
}
#else // BUILDFLAG(USE_STARBOARD_MEDIA)
strategies_.push_back(std::make_unique<OverlayStrategyUnderlay>(
this, OverlayStrategyUnderlay::OpaqueMode::AllowTransparentCandidates));
Expand Down
12 changes: 12 additions & 0 deletions content/renderer/media/media_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<media::StarboardRendererFactory>());
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
Expand Down
7 changes: 6 additions & 1 deletion content/renderer/media/media_permission_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions media/base/media_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
8 changes: 8 additions & 0 deletions media/base/media_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
yell0wd0g marked this conversation as resolved.
Show resolved Hide resolved
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

namespace autoplay {

MEDIA_EXPORT extern const char kDocumentUserActivationRequiredPolicy[];
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions media/base/renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
5 changes: 5 additions & 0 deletions media/base/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
borongc marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
8 changes: 8 additions & 0 deletions media/mojo/mojom/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = [
Expand Down
2 changes: 2 additions & 0 deletions media/mojo/mojom/media_types.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
9 changes: 9 additions & 0 deletions media/mojo/mojom/media_types_enum_mojom_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ struct EnumTraits<media::mojom::RendererType, ::media::RendererType> {
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();
Expand Down Expand Up @@ -359,6 +363,11 @@ struct EnumTraits<media::mojom::RendererType, ::media::RendererType> {
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();
Expand Down
2 changes: 2 additions & 0 deletions media/starboard/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down
42 changes: 42 additions & 0 deletions media/starboard/starboard_renderer_factory.cc
Original file line number Diff line number Diff line change
@@ -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 <memory>

#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<Renderer> StarboardRendererFactory::CreateRenderer(
const scoped_refptr<base::SequencedTaskRunner>& media_task_runner,
const scoped_refptr<base::TaskRunner>& 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::StarboardRenderer>(media_task_runner,
video_renderer_sink);
}

} // namespace media
44 changes: 44 additions & 0 deletions media/starboard/starboard_renderer_factory.h
Original file line number Diff line number Diff line change
@@ -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<Renderer> CreateRenderer(
const scoped_refptr<base::SequencedTaskRunner>& media_task_runner,
const scoped_refptr<base::TaskRunner>& 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_
Original file line number Diff line number Diff line change
Expand Up @@ -2807,21 +2807,6 @@ std::unique_ptr<media::Renderer> 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::StarboardRenderer>(media_task_runner_,
compositor_.get());
}
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

if (renderer_type) {
DVLOG(1) << __func__
<< ": renderer_type=" << static_cast<int>(renderer_type.value());
Expand All @@ -2838,6 +2823,14 @@ std::unique_ptr<media::Renderer> WebMediaPlayerImpl::CreateRenderer(
media_metrics_provider_->SetRendererType(renderer_type_);
media_log_->SetProperty<MediaLogProperty::kRendererName>(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),
Expand Down
2 changes: 2 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68501,6 +68501,8 @@ Called by update_use_counter_css.py.-->
<int value="9" label="kCastStreaming"/>
<int value="10" label="kContentEmbedderDefined"/>
<int value="11" label="kTest"/>
<!-- Cobalt: Renderer for Starboard (SbPlayer) -->
<int value="12" label="kStarboard"/>
</enum>

<enum name="MediaResponseCacheType">
Expand Down
Loading