Skip to content
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
20 changes: 20 additions & 0 deletions cobalt/renderer/cobalt_content_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "base/task/bind_post_task.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "cobalt/media/service/mojom/platform_window_provider.mojom.h"
#include "cobalt/renderer/cobalt_render_frame_observer.h"
#include "cobalt/shell/common/url_constants.h"
Expand All @@ -33,6 +34,7 @@
#include "media/base/media_switches.h"
#include "media/base/renderer_factory.h"
#include "media/base/starboard/experimental_features.h"
#include "media/media_buildflags.h"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think including this is necessary.

@borongc borongc Jul 28, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments of this PR should be applied to #10698.

#include "media/mojo/clients/starboard/starboard_renderer_client_factory.h"
#include "media/starboard/starboard_media_external_memory_allocator.h"
#include "mojo/public/cpp/bindings/generic_pending_receiver.h"
Expand All @@ -46,6 +48,10 @@
#include "third_party/blink/public/web/web_view.h"
#include "ui/gfx/geometry/size_conversions.h"

#if BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USE_STARBOARD_MEDIA is true for Cobalt build anyway, so this is not necessary.

#include "media/starboard/url_player_demuxer.h"
#endif // BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA)

namespace cobalt {

namespace {
Expand Down Expand Up @@ -368,4 +374,18 @@ void CobaltContentRendererClient::PostSandboxInitialized() {
}
}

std::unique_ptr<::media::Demuxer>
CobaltContentRendererClient::OverrideDemuxerForUrl(
content::RenderFrame* render_frame,
const GURL& url,
scoped_refptr<base::SequencedTaskRunner> task_runner) {
#if BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA)
if (::media::IsHlsUrl(url)) {
return std::make_unique<::media::UrlPlayerDemuxer>(std::move(task_runner),
url);
}
#endif // BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA)
return nullptr;
}

} // namespace cobalt
6 changes: 6 additions & 0 deletions cobalt/renderer/cobalt_content_renderer_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define COBALT_RENDERER_COBALT_CONTENT_RENDERER_CLIENT_H_

#include <atomic>
#include <memory>

#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
Expand All @@ -27,6 +28,7 @@
#include "cobalt/media/audio/cobalt_audio_device_factory.h"
#include "cobalt/media/service/mojom/platform_window_provider.mojom.h"
#include "content/public/renderer/content_renderer_client.h"
#include "media/base/demuxer.h"
#include "media/base/key_systems_support_registration.h"
#include "media/base/starboard/renderer_factory_traits.h"
#include "mojo/public/cpp/bindings/remote.h"
Expand Down Expand Up @@ -74,6 +76,10 @@ class CobaltContentRendererClient : public content::ContentRendererClient {
void GetStarboardRendererFactoryTraits(
::media::RendererFactoryTraits* traits) override;
void PostSandboxInitialized() override;
std::unique_ptr<::media::Demuxer> OverrideDemuxerForUrl(
content::RenderFrame* render_frame,
const GURL& url,
scoped_refptr<base::SequencedTaskRunner> task_runner) override;

uint64_t GetSbWindowHandle() const { return sb_window_handle_; }

Expand Down
3 changes: 2 additions & 1 deletion cobalt/shell/browser/shell_platform_delegate_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ - (void)viewDidLoad {
// Note that the actual size and and position of this view are irrelevant at
// this point: it will be changed in starboard's
// AVSBVideoRenderer::SetBounds() when necessary.
UIView* playerContainerView = [[UIView alloc] init];
UIView* playerContainerView =
[[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
playerContainerView.accessibilityIdentifier = @"Player Container";
[_contentView addSubview:playerContainerView];
[SBDGetApplication() setPlayerContainerView:playerContainerView];
Expand Down
1 change: 1 addition & 0 deletions media/base/demuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum class DemuxerType {
kFrameInjectingDemuxer = 5,
kStreamProviderDemuxer = 6,
kManifestDemuxer = 7,
kUrlPlayerDemuxer = 8, // URL player placeholder demuxer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: gate it by BUILDFLAG(USE_STARBOARD_MEDIA).

};

class MEDIA_EXPORT DemuxerHost {
Expand Down
14 changes: 14 additions & 0 deletions media/base/media_resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "media/base/media_resource.h"

#include "base/no_destructor.h"
#include "media/media_buildflags.h"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary, please check it.

#include "net/cookies/site_for_cookies.h"
#include "net/storage_access_api/status.h"
#include "url/gurl.h"
Expand All @@ -25,4 +26,17 @@ DemuxerStream* MediaResource::GetFirstStream(DemuxerStream::Type type) {
return nullptr;
}

#if BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA)
GURL MediaResource::GetMediaUrl() const {
return GURL();
}

void MediaResource::ForwardDurationChangeToDemuxerHost(
base::TimeDelta duration) {}

void MediaResource::ForwardBufferedTimeRangesToDemuxerHost(
base::TimeDelta start,
base::TimeDelta length) {}
#endif // BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA)

} // namespace media
17 changes: 17 additions & 0 deletions media/base/media_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
#include "base/time/time.h"
#include "media/base/demuxer_stream.h"
#include "media/base/media_export.h"
#include "build/build_config.h"
#include "media/media_buildflags.h"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for all #include "media/media_buildflags.h"

#if BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA)
#include "url/gurl.h"
#endif // BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA)

namespace media {

Expand Down Expand Up @@ -41,6 +46,18 @@ class MEDIA_EXPORT MediaResource {
// A helper function that return the first stream of the given `type` if one
// exists or a null pointer if there is no streams of that type.
DemuxerStream* GetFirstStream(DemuxerStream::Type type);

#if BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA)
// Returns the media URL for URL player.
virtual GURL GetMediaUrl() const;

// Forwards duration change to DemuxerHost.
virtual void ForwardDurationChangeToDemuxerHost(base::TimeDelta duration);

// Forwards buffered ranges to DemuxerHost.
virtual void ForwardBufferedTimeRangesToDemuxerHost(base::TimeDelta start,
base::TimeDelta length);
#endif // BUILDFLAG(IS_IOS_TVOS) && BUILDFLAG(USE_STARBOARD_MEDIA)
};

} // namespace media
Expand Down
46 changes: 44 additions & 2 deletions media/mojo/clients/starboard/starboard_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "base/functional/bind.h"
#include "base/time/time.h"
#include "base/unguessable_token.h"
#include "build/build_config.h"
#include "media/base/media_log.h"
#include "media/base/media_resource.h"
#include "media/base/media_switches.h"
Expand All @@ -30,6 +31,10 @@
#include "mojo/public/cpp/bindings/callback_helpers.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"

#if BUILDFLAG(IS_IOS_TVOS)
#include "url/gurl.h"
#endif // BUILDFLAG(IS_IOS_TVOS)
Comment thread
abhijeetk marked this conversation as resolved.

#if BUILDFLAG(IS_ANDROID)
#include "base/task/bind_post_task.h"
#endif // BUILDFLAG(IS_ANDROID)
Expand Down Expand Up @@ -102,6 +107,7 @@ void StarboardRendererClient::Initialize(MediaResource* media_resource,
DCHECK(!init_cb_);

client_ = client;
media_resource_ = media_resource;
init_cb_ = std::move(init_cb);

DCHECK(!AreMojoPipesConnected());
Expand Down Expand Up @@ -280,6 +286,26 @@ void StarboardRendererClient::GetSbWindowHandle() {
renderer_extension_->OnSbWindowHandleReady(sb_window_handle);
}

void StarboardRendererClient::OnDurationChange(base::TimeDelta duration) {
DCHECK(media_task_runner_->RunsTasksInCurrentSequence());
#if BUILDFLAG(IS_IOS_TVOS)
if (media_resource_) {
media_resource_->ForwardDurationChangeToDemuxerHost(duration);
}
#endif // BUILDFLAG(IS_IOS_TVOS)
Comment thread
abhijeetk marked this conversation as resolved.
}

void StarboardRendererClient::OnBufferedTimeRangesChange(
base::TimeDelta start,
base::TimeDelta length) {
DCHECK(media_task_runner_->RunsTasksInCurrentSequence());
#if BUILDFLAG(IS_IOS_TVOS)
if (media_resource_) {
media_resource_->ForwardBufferedTimeRangesToDemuxerHost(start, length);
}
#endif // BUILDFLAG(IS_IOS_TVOS)
Comment thread
abhijeetk marked this conversation as resolved.
}

#if BUILDFLAG(IS_ANDROID)
void StarboardRendererClient::RequestOverlayInfo(bool restart_for_transitions) {
DCHECK(media_task_runner_->RunsTasksInCurrentSequence());
Expand Down Expand Up @@ -351,8 +377,18 @@ void StarboardRendererClient::InitializeMojoRenderer(
DCHECK(media_task_runner_->RunsTasksInCurrentSequence());
DCHECK(AreMojoPipesConnected());

if (base::FeatureList::IsEnabled(kCobaltBypassMojoForMedia) ||
bypass_mojo_for_media_) {
// URL player is incompatible with the bypass bridge because the bypass

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just gate the code by !BUILDFLAG(IS_IOS_TVOS)

@abhijeetk abhijeetk Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion!

Gating the bypass bridge block with !BUILDFLAG(IS_IOS_TVOS) would also require gating the related members (bypass_mojo_for_media_, bypass_bridge_, bypass_id_), the static g_next_bypass_id, and the three helper methogs (OnTimeUpdateFromBridge, OnStatisticsUpdateFromBridge OnExtensionBypassInitialized), since they become unused on tvOS and trigger -Werror compile errors.

Let me know if you'd prefer a different approach here.

// bridge proxies demuxer streams, while the URL player delegates playback
// entirely to the native platform player.
bool is_url_player = false;
#if BUILDFLAG(IS_IOS_TVOS)
GURL url = media_resource->GetMediaUrl();
is_url_player = url.is_valid();
#endif // BUILDFLAG(IS_IOS_TVOS)
Comment thread
abhijeetk marked this conversation as resolved.

if (!is_url_player &&
(base::FeatureList::IsEnabled(kCobaltBypassMojoForMedia) ||
bypass_mojo_for_media_)) {
bypass_bridge_ = base::MakeRefCounted<MojoRendererBypassBridge>(
media_task_runner_,
base::BindRepeating(&StarboardRendererClient::OnTimeUpdateFromBridge,
Expand All @@ -378,6 +414,12 @@ void StarboardRendererClient::InitializeMojoRenderer(
return;
}

#if BUILDFLAG(IS_IOS_TVOS)
if (is_url_player) {
renderer_extension_->SetSourceUrl(url.spec());
}
#endif // BUILDFLAG(IS_IOS_TVOS)
Comment thread
abhijeetk marked this conversation as resolved.

MojoRendererWrapper::Initialize(media_resource, client, std::move(init_cb));
}

Expand Down
5 changes: 5 additions & 0 deletions media/mojo/clients/starboard/starboard_renderer_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "base/memory/weak_ptr.h"
#include "base/synchronization/lock.h"
#include "base/task/sequenced_task_runner.h"
#include "build/build_config.h"
#include "media/base/pipeline_status.h"
#include "media/base/renderer_client.h"
#include "media/base/starboard/starboard_rendering_mode.h"
Expand Down Expand Up @@ -110,6 +111,9 @@ class MEDIA_EXPORT StarboardRendererClient
void PaintVideoHoleFrame(const gfx::Size& size) override;
void UpdateStarboardRenderingMode(const StarboardRenderingMode mode) override;
void GetSbWindowHandle() override;
void OnDurationChange(base::TimeDelta duration) override;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is only used on tvOS, consider to gate them by BUILDFLAG(IS_IOS_TVOS), so it would override on other platforms. Same for OnBufferedTimeRangesChange.

void OnBufferedTimeRangesChange(base::TimeDelta start,
base::TimeDelta length) override;
#if BUILDFLAG(IS_ANDROID)
void RequestOverlayInfo(bool restart_for_transitions) override;
#endif // BUILDFLAG(IS_ANDROID)
Expand Down Expand Up @@ -169,6 +173,7 @@ class MEDIA_EXPORT StarboardRendererClient
mojo::Remote<RendererExtension> renderer_extension_;

raw_ptr<RendererClient> client_ = nullptr;
raw_ptr<MediaResource> media_resource_ = nullptr;
PipelineStatusCallback init_cb_;

// Rendering mode the Starboard Renderer will use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class FakeStarboardRendererExtension
#endif // BUILDFLAG(IS_ANDROID)
void OnGpuChannelTokenReady(
mojom::CommandBufferIdPtr command_buffer_id) override {}
void SetSourceUrl(const std::string& source_url) override {}

private:
FakeMojomRendererCallRecord* record_ = nullptr;
Expand Down
1 change: 1 addition & 0 deletions media/mojo/mojom/media_types.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ enum DemuxerType {
kFrameInjectingDemuxer = 5,
kStreamProviderDemuxer = 6,
kManifestDemuxer = 7,
kUrlPlayerDemuxer = 8, // URL player placeholder demuxer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please gate it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_ios_tvos / is_tvos isn't available as a mojom enabled feature (only is_ios is registered in mojom.gni). Would [EnableIf=is_ios] work as a substitute since it's the closest available flag?

Currently at GN level, we identify tvos code using is_ios && target_platform == "tvos" but we can not use compound conditions with [EnableIf=...]

Please see our previous notes here regarding this constraint.

Aslo, media_types.mojom must stay in sync with demuxer.h and media_types_enum_mojom_traits.h.
The traits file has a switch that maps between ::media::DemuxerType::kUrlPlayerDemuxer (from
demuxer.h) and media::mojom::DemuxerType::kUrlPlayerDemuxer (from generated mojom). If one exists but the other doesn't, compilation fails.

As per your suggestion on demuxer.h to use BUILDFLAG(USE_STARBOARD_MEDIA), it means we need to use [EnableIf=use_starboard_media] here ?

};

// See media::CreateCdmStatus
Expand Down
9 changes: 7 additions & 2 deletions media/mojo/mojom/media_types_enum_mojom_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ struct EnumTraits<media::mojom::RendererType, ::media::RendererType> {
#if BUILDFLAG(USE_STARBOARD_MEDIA)
case ::media::RendererType::kStarboard:
return media::mojom::RendererType::kStarboard;
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
}

NOTREACHED();
Expand Down Expand Up @@ -436,7 +436,7 @@ struct EnumTraits<media::mojom::RendererType, ::media::RendererType> {
case media::mojom::RendererType::kStarboard:
*output = ::media::RendererType::kStarboard;
return true;
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
}

NOTREACHED();
Expand All @@ -461,6 +461,8 @@ struct EnumTraits<media::mojom::DemuxerType, ::media::DemuxerType> {
return media::mojom::DemuxerType::kStreamProviderDemuxer;
case ::media::DemuxerType::kManifestDemuxer:
return media::mojom::DemuxerType::kManifestDemuxer;
case ::media::DemuxerType::kUrlPlayerDemuxer:
return media::mojom::DemuxerType::kUrlPlayerDemuxer;
}

NOTREACHED();
Expand Down Expand Up @@ -492,6 +494,9 @@ struct EnumTraits<media::mojom::DemuxerType, ::media::DemuxerType> {
case media::mojom::DemuxerType::kManifestDemuxer:
*output = ::media::DemuxerType::kManifestDemuxer;
return true;
case media::mojom::DemuxerType::kUrlPlayerDemuxer:
*output = ::media::DemuxerType::kUrlPlayerDemuxer;
return true;
}

NOTREACHED();
Expand Down
8 changes: 8 additions & 0 deletions media/mojo/mojom/renderer_extensions.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ interface StarboardRendererClientExtension {
// Get SbWindow from StarboardRendererClient.
GetSbWindowHandle();

// URL player duration and buffered ranges forwarding.
OnDurationChange(mojo_base.mojom.TimeDelta duration);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please gate it both by use_starboard_media and is_ios_tvos

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed above on media_types.mojom, is_ios_tvos isn't available as a mojom enabled feature.
The interface StarboardRendererClientExtension is already guarded by use_starboard_media, should we use [EnableIf=is_ios] here ?

OnBufferedTimeRangesChange(mojo_base.mojom.TimeDelta start,
mojo_base.mojom.TimeDelta length);

[EnableIf=is_android]
// Request OverlayInfo from StarboardRendererClient.
RequestOverlayInfo(bool restart_for_transitions);
Expand Down Expand Up @@ -151,6 +156,9 @@ interface StarboardRendererExtension {
// Initialize media bypass bridge in single-process mode.
InitializeWithBypassBridge(uint32 bypass_bridge_id) => (bool success);

// Pass source URL for URL player.
SetSourceUrl(string source_url);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed above on media_types.mojom, is_ios_tvos isn't available as a mojom enabled feature.
The interface StarboardRendererExtension is already guarded by use_starboard_media, should we use [EnableIf=is_ios] here ?


[EnableIf=is_android]
// Notify StarboardRendererWrapper when the current OverlayInfo changes.
OnOverlayInfoChanged(OverlayInfo overlay_info);
Expand Down
30 changes: 30 additions & 0 deletions media/mojo/services/starboard/starboard_renderer_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ void StarboardRendererWrapper::Initialize(MediaResource* media_resource,
#endif // BUILDFLAG(IS_ANDROID)
);

#if SB_HAS(PLAYER_WITH_URL)
// Wire duration and buffered ranges callbacks.
GetRenderer()->SetDurationChangeCB(base::BindRepeating(
&StarboardRendererWrapper::OnDurationChange, weak_factory_.GetWeakPtr()));
GetRenderer()->SetBufferedRangesCB(
base::BindRepeating(&StarboardRendererWrapper::OnBufferedTimeRangesChange,
weak_factory_.GetWeakPtr()));
#endif // SB_HAS(PLAYER_WITH_URL)

base::ScopedClosureRunner scoped_init_cb(
base::BindOnce(&StarboardRendererWrapper::ContinueInitialization,
weak_factory_.GetWeakPtr(), std::move(media_resource),
Expand Down Expand Up @@ -515,6 +524,13 @@ void StarboardRendererWrapper::InitializeWithBypassBridge(
std::move(callback).Run(true);
}

void StarboardRendererWrapper::SetSourceUrl(const std::string& source_url) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
#if SB_HAS(PLAYER_WITH_URL)
GetRenderer()->SetSourceUrl(source_url);
#endif // SB_HAS(PLAYER_WITH_URL)
}

#if BUILDFLAG(IS_ANDROID)
void StarboardRendererWrapper::OnOverlayInfoChanged(
const OverlayInfo& overlay_info) {
Expand Down Expand Up @@ -619,6 +635,20 @@ void StarboardRendererWrapper::OnGetSbWindowHandle() {
client_extension_remote_->GetSbWindowHandle();
}

#if SB_HAS(PLAYER_WITH_URL)
void StarboardRendererWrapper::OnDurationChange(base::TimeDelta duration) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
client_extension_remote_->OnDurationChange(duration);
}

void StarboardRendererWrapper::OnBufferedTimeRangesChange(
base::TimeDelta start,
base::TimeDelta length) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
client_extension_remote_->OnBufferedTimeRangesChange(start, length);
}
#endif // SB_HAS(PLAYER_WITH_URL)

void StarboardRendererWrapper::OnSubscribeToVideoGeometryChange(
MediaResource* /* media_resource */,
RendererClient* /* client */) {
Expand Down
Loading
Loading