Skip to content

Commit

Permalink
[media] Add StarboardRendererFactory
Browse files Browse the repository at this point in the history
1. Add StarboardRendererFactory for MediaFactory to select StarboardRenderer when `use_starboard_media=true`.
2. Remove hard code StarboardRenderer in WebMediaPlayerImpl.

Note RendererType::kStarboard cannot be gated due to mojom files.

b/375278384
  • Loading branch information
borongc committed Jan 14, 2025
1 parent aba5a7a commit da3acef
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ 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.
private List<CobaltJavaScriptAndroidObject> javaScriptAndroidObjectList = new ArrayList<>();
Expand Down Expand Up @@ -391,9 +395,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));
}
}

/**
Expand Down
9 changes: 8 additions & 1 deletion components/viz/service/display/overlay_processor_android.cc
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
15 changes: 11 additions & 4 deletions content/renderer/media/media_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -761,13 +761,20 @@ MediaFactory::CreateRendererFactorySelector(
is_base_renderer_factory_set = true;
#if BUILDFLAG(USE_STARBOARD_MEDIA)
// TODO(b/326827007): Revisit renderer to support secondary videos.
factory_selector->AddFactory(
RendererType::kStarboard,
std::make_unique<media::StarboardRendererFactory>(
if (media::IsStarboardRendererEnabled()) {
factory_selector->AddFactory(
RendererType::kStarboard,
std::make_unique<media::StarboardRendererFactory>(
media_log,
// TODO: b/383327725 - Cobalt: Inject these values from the web app.
kWriteDurationLocal, kWriteDurationRemote));
factory_selector->SetBaseRendererType(RendererType::kStarboard);
factory_selector->SetBaseRendererType(RendererType::kStarboard);
} else {
auto renderer_impl_factory = CreateRendererImplFactory(
player_id, media_log, decoder_factory, render_thread, render_frame_);
factory_selector->AddBaseFactory(RendererType::kRendererImpl,
std::move(renderer_impl_factory));
}
#else // BUILDFLAG(USE_STARBOARD_MEDIA)
auto renderer_impl_factory = CreateRendererImplFactory(
player_id, media_log, decoder_factory, render_thread, render_frame_);
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 @@ -1557,4 +1562,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[];
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

namespace autoplay {

MEDIA_EXPORT extern const char kDocumentUserActivationRequiredPolicy[];
Expand Down Expand Up @@ -449,6 +453,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

0 comments on commit da3acef

Please sign in to comment.