Skip to content
Closed
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
6 changes: 6 additions & 0 deletions build/build_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@
#define BUILDFLAG_INTERNAL_USE_STARBOARD_MEDIA() (0)
#endif

#if defined(ENABLE_BUILDFLAG_USE_STARBOARD_URL_PLAYER)

@borongc borongc Jun 26, 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.

Same as #10979 (comment), I think introducing one more flag for a single Starboard platform is not ideal.

#define BUILDFLAG_INTERNAL_USE_STARBOARD_URL_PLAYER() (1)
#else
#define BUILDFLAG_INTERNAL_USE_STARBOARD_URL_PLAYER() (0)
#endif

#if defined(ENABLE_BUILDFLAG_USE_EVERGREEN)
#define BUILDFLAG_INTERNAL_USE_EVERGREEN() (1)
#else
Expand Down
8 changes: 8 additions & 0 deletions cobalt/build/configs/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ config("buildflag_defines") {
defines += [ "ENABLE_BUILDFLAG_USE_STARBOARD_MEDIA" ]
}

# use_starboard_url_player and BUILDFLAG(USE_STARBOARD_URL_PLAYER) should be
# used to wrap URL-based player functionality (e.g., HLS via AVPlayer on
# tvOS). This is a derived capability that is true only for tvOS builds with
# Starboard media enabled.
if (use_starboard_url_player) {
defines += [ "ENABLE_BUILDFLAG_USE_STARBOARD_URL_PLAYER" ]
}

# use_evergreen and BUILDFLAG(USE_EVERGREEN) should be used for
# Evergreen-specific functionality, i.e. the Evergreen loader_app. Do not use
# this flag for hermetic build functionality, instead use
Expand Down
6 changes: 6 additions & 0 deletions media/base/media_resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ DemuxerStream* MediaResource::GetFirstStream(DemuxerStream::Type type) {
return nullptr;
}

#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
GURL MediaResource::GetMediaUrl() const {
return GURL();
}
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)

} // namespace media
9 changes: 9 additions & 0 deletions media/base/media_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "media/base/demuxer_stream.h"
#include "media/base/media_export.h"
#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
#include "url/gurl.h"
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)

namespace media {

Expand Down Expand Up @@ -41,6 +45,11 @@ 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(USE_STARBOARD_URL_PLAYER)
// Returns the media URL for URL based players (e.g., HLS via AVPlayer).
virtual GURL GetMediaUrl() const;
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)
};

} // namespace media
Expand Down
8 changes: 7 additions & 1 deletion media/base/renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// found in the LICENSE file.

#include "media/base/renderer.h"

#include "base/logging.h"
#include "build/build_config.h"

namespace media {

Expand Down Expand Up @@ -34,7 +36,11 @@ std::string GetRendererName(RendererType renderer_type) {
#if BUILDFLAG(USE_STARBOARD_MEDIA)
case RendererType::kStarboard:
return "StarboardRenderer";
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
case RendererType::kUrlPlayer:
return "UrlPlayerRenderer";
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)
}
}

Expand Down
10 changes: 8 additions & 2 deletions media/base/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "base/functional/callback.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "media/base/buffering_state.h"
#include "media/base/demuxer_stream.h"
#include "media/base/media_export.h"
Expand Down Expand Up @@ -39,10 +40,15 @@ enum class RendererType {
kTest = 11, // Renderer implementations used in tests
#if BUILDFLAG(USE_STARBOARD_MEDIA)
kStarboard = 12, // StarboardRendererFactory
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
kUrlPlayer = 13, // UrlPlayerRendererClientFactory
kMaxValue = kUrlPlayer,
#elif BUILDFLAG(USE_STARBOARD_MEDIA)
kMaxValue = kStarboard,
#else // BUILDFLAG(USE_STARBOARD_MEDIA)
#else
kMaxValue = kTest,
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)
};

// Get the name of the Renderer for `renderer_type`. The returned name could be
Expand Down
7 changes: 7 additions & 0 deletions media/mojo/clients/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ source_set("clients") {
"//cobalt/renderer",
]
}

if (is_cobalt && use_starboard_url_player) {
sources += [
"starboard/url_player_renderer_client.cc",
"starboard/url_player_renderer_client.h",
]
}
}

static_library("test_support") {
Expand Down
25 changes: 25 additions & 0 deletions media/mojo/clients/mojo_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,31 @@ void MojoRenderer::Initialize(MediaResource* media_resource,
base::Unretained(this), client));
}

#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
void MojoRenderer::InitializeWithUrl(media::RendererClient* client,
const GURL& source_url,
PipelineStatusCallback init_cb) {
DVLOG(1) << __func__;
DCHECK(task_runner_->RunsTasksInCurrentSequence());

if (!source_url.is_valid() || encountered_error_) {
task_runner_->PostTask(
FROM_HERE, base::BindOnce(std::move(init_cb),
PIPELINE_ERROR_INITIALIZATION_FAILED));
return;
}

init_cb_ = std::move(init_cb);

BindRemoteRendererIfNeeded();

remote_renderer_->InitializeWithUrl(
client_receiver_.BindNewEndpointAndPassRemote(), source_url,
base::BindOnce(&MojoRenderer::OnInitialized, base::Unretained(this),
client));
}
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)

void MojoRenderer::SetCdm(CdmContext* cdm_context,
CdmAttachedCB cdm_attached_cb) {
DVLOG(1) << __func__;
Expand Down
7 changes: 7 additions & 0 deletions media/mojo/clients/mojo_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
#include "base/task/sequenced_task_runner.h"
#include "base/time/default_tick_clock.h"
#include "base/unguessable_token.h"
#include "build/build_config.h"
#include "media/base/demuxer_stream.h"
#include "media/base/renderer.h"
#include "media/base/time_delta_interpolator.h"
#include "media/mojo/mojom/renderer.mojom.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "url/gurl.h"

#if BUILDFLAG(USE_STARBOARD_MEDIA)
#include "media/mojo/common/starboard/mojo_renderer_bypass_bridge.h"
Expand Down Expand Up @@ -65,6 +67,11 @@ class MojoRenderer : public Renderer, public mojom::RendererClient {
void Initialize(MediaResource* media_resource,
media::RendererClient* client,
PipelineStatusCallback init_cb) override;
#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
void InitializeWithUrl(media::RendererClient* client,
const GURL& source_url,
PipelineStatusCallback init_cb);
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)
void SetCdm(CdmContext* cdm_context, CdmAttachedCB cdm_attached_cb) override;
void SetLatencyHint(std::optional<base::TimeDelta> latency_hint) override;
void Flush(base::OnceClosure flush_cb) override;
Expand Down
11 changes: 11 additions & 0 deletions media/mojo/clients/mojo_renderer_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <utility>

#include "base/logging.h"

namespace media {

MojoRendererWrapper::MojoRendererWrapper(
Expand All @@ -20,6 +22,15 @@ void MojoRendererWrapper::Initialize(MediaResource* media_resource,
mojo_renderer_->Initialize(media_resource, client, std::move(init_cb));
}

#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
void MojoRendererWrapper::InitializeWithUrl(RendererClient* client,
const GURL& source_url,
PipelineStatusCallback init_cb) {
DVLOG(1) << __func__;
mojo_renderer_->InitializeWithUrl(client, source_url, std::move(init_cb));
}
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)

void MojoRendererWrapper::Flush(base::OnceClosure flush_cb) {
mojo_renderer_->Flush(std::move(flush_cb));
}
Expand Down
7 changes: 7 additions & 0 deletions media/mojo/clients/mojo_renderer_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

#include <memory>

#include "build/build_config.h"
#include "media/base/renderer.h"
#include "media/mojo/clients/mojo_renderer.h"
#include "url/gurl.h"

namespace media {

Expand All @@ -30,6 +32,11 @@ class MojoRendererWrapper : public Renderer {
void Initialize(MediaResource* media_resource,
RendererClient* client,
PipelineStatusCallback init_cb) override;
#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
void InitializeWithUrl(RendererClient* client,
const GURL& source_url,
PipelineStatusCallback init_cb);
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)
void SetCdm(CdmContext* cdm_context, CdmAttachedCB cdm_attached_cb) override;
void SetLatencyHint(std::optional<base::TimeDelta> latency_hint) override;
void Flush(base::OnceClosure flush_cb) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "media/base/mock_media_log.h"
#include "media/base/test_helpers.h"
#include "media/base/video_renderer_sink.h"
#include "media/media_buildflags.h"
#include "media/mojo/mojom/renderer.mojom.h"
#include "media/mojo/mojom/renderer_extensions.mojom.h"
#include "media/renderers/video_overlay_factory.h"
Expand Down Expand Up @@ -61,6 +62,13 @@ class FakeMojomRenderer : public mojom::Renderer {
InitializeWithBypassBridgeCallback cb) override {
std::move(cb).Run(true);
}
#if BUILDFLAG(USE_STARBOARD_URL_PLAYER)
void InitializeWithUrl(mojo::PendingAssociatedRemote<mojom::RendererClient>,
const GURL& source_url,
InitializeWithUrlCallback cb) override {
std::move(cb).Run(true);
}
#endif // BUILDFLAG(USE_STARBOARD_URL_PLAYER)
MOCK_METHOD1(Flush, void(FlushCallback));
void StartPlayingFrom(base::TimeDelta time) override {}
MOCK_METHOD1(SetPlaybackRate, void(double));
Expand Down
Loading
Loading